001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:48:48 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33634 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.ROADnet; 031 032import com.brtt.antelope.OrbWaveformPacket; 033 034import ptolemy.actor.TypedAtomicActor; 035import ptolemy.actor.TypedIOPort; 036import ptolemy.data.ObjectToken; 037import ptolemy.data.Token; 038import ptolemy.data.expr.Parameter; 039import ptolemy.data.type.BaseType; 040import ptolemy.kernel.CompositeEntity; 041import ptolemy.kernel.util.IllegalActionException; 042import ptolemy.kernel.util.NameDuplicationException; 043 044/** 045 * This actor receives OrbPacket objects ensconced in ObjectTokens and extracts 046 * any OrbPacketChannels from the OrbPackets and outputs them as 047 * OrbPacketChannel objects ensconced in ObjectTokens. 048 * 049 * @author Tobin Fricke, University of California 050 * @version $Id: OrbPacketChannelExtractor.java 11161 2005-11-01 20:39:16Z 051 * ruland $ 052 */ 053 054public class OrbPacketChannelExtractor extends TypedAtomicActor { 055 056 public OrbPacketChannelExtractor(CompositeEntity container, String name) 057 throws NameDuplicationException, IllegalActionException { 058 super(container, name); 059 060 output = new TypedIOPort(this, "output", false, true); 061 output.setMultiport(true); 062 output.setTypeEquals(BaseType.OBJECT); 063 064 input = new TypedIOPort(this, "input", true, false); 065 input.setMultiport(true); 066 input.setTypeEquals(BaseType.OBJECT); 067 } 068 069 /** Connect to the ORB */ 070 071 public void initialize() throws IllegalActionException { 072 super.initialize(); 073 } 074 075 /** Process a token */ 076 077 public void fire() throws IllegalActionException { 078 super.fire(); 079 try { 080 081 // first take care of any inputs 082 083 for (int c = 0; c < input.getWidth(); c++) { 084 while (input.hasToken(c)) { 085 ObjectToken token = (ObjectToken) (input.get(c)); 086 087 // fixme: we should actually check the following 088 089 OrbWaveformPacket packet = (OrbWaveformPacket) (token 090 .getValue()); 091 092 for (int i = 0; i < packet.channels.size(); i++) { 093 Token result = new ObjectToken(packet.channels.get(i)); 094 output.broadcast(result); 095 } 096 } 097 } 098 099 } catch (Exception e) { 100 // ... 101 } 102 103 } 104 105 /** 106 * The name of the Antelope ORB to connect to, in the format 107 * "hostname:port". 108 */ 109 110 public Parameter orbname; 111 112 /** The sourcename to request from the ORB. */ 113 114 public Parameter srcname; 115 116 /** 117 * Packets reaped from the ORB will appear on this port as Ptolemy 118 * ObjectTokens. 119 */ 120 121 public TypedIOPort output; 122 public TypedIOPort input; 123 124}