| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2006 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE ChannelDemo. |
|---|
| 6 | |
|---|
| 7 | OSSIE ChannelDemo is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE ChannelDemo is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE ChannelDemo; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include <string> |
|---|
| 25 | #include <iostream> |
|---|
| 26 | //#include "ossie/cf.h" |
|---|
| 27 | #include "ChannelDemo.h" |
|---|
| 28 | //#include ossie/PortTypes.h" |
|---|
| 29 | |
|---|
| 30 | //#include "ossie/Resource_impl.h" |
|---|
| 31 | |
|---|
| 32 | ChannelDemo_i::ChannelDemo_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition) |
|---|
| 33 | { |
|---|
| 34 | dataOut = new standardInterfaces_i::complexShort_u("outPort"); |
|---|
| 35 | dataIn = new standardInterfaces_i::complexShort_p("inPort"); |
|---|
| 36 | |
|---|
| 37 | processing_thread = new omni_thread(process_data, (void *) this); //Create the thread for the writer's processing function |
|---|
| 38 | processing_thread->start(); //Start the thread containing the writer's processing function |
|---|
| 39 | |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | CORBA::Object_ptr ChannelDemo_i::getPort( const char* portName ) throw (CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 43 | { |
|---|
| 44 | std::cout << "ChannelDemo_i getPort called with : " << portName << std::endl; |
|---|
| 45 | |
|---|
| 46 | CORBA::Object_var p; |
|---|
| 47 | |
|---|
| 48 | p = dataOut->getPort(portName); |
|---|
| 49 | |
|---|
| 50 | if (!CORBA::is_nil(p)) |
|---|
| 51 | return p._retn(); |
|---|
| 52 | |
|---|
| 53 | p = dataIn->getPort(portName); |
|---|
| 54 | |
|---|
| 55 | if (!CORBA::is_nil(p)) |
|---|
| 56 | return p._retn(); |
|---|
| 57 | |
|---|
| 58 | /*exception*/ |
|---|
| 59 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | void ChannelDemo_i::start() throw (CORBA::SystemException, CF::Resource::StartError) |
|---|
| 63 | { |
|---|
| 64 | std::cout << "start called on ChannelDemo" << std::endl; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void ChannelDemo_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 68 | { |
|---|
| 69 | std::cout << "stop called on ChannelDemo" << std::endl; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void ChannelDemo_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError) |
|---|
| 73 | { |
|---|
| 74 | std::cout << "releaseObject called on ChannelDemo" << std::endl; |
|---|
| 75 | |
|---|
| 76 | component_running->signal(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void ChannelDemo_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException) |
|---|
| 80 | { |
|---|
| 81 | std::cout << "initialize called on ChannelDemo" << std::endl; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | void ChannelDemo_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration) |
|---|
| 85 | { |
|---|
| 86 | std::cout << "configure called on ChannelDemo" << std::endl; |
|---|
| 87 | |
|---|
| 88 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 89 | |
|---|
| 90 | for (unsigned int i = 0; i <props.length(); i++) |
|---|
| 91 | { |
|---|
| 92 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 93 | |
|---|
| 94 | if (strcmp(props[i].id, "DCE:85d02594-1d91-49cf-ab93-2c533b55abe5") == 0) |
|---|
| 95 | { |
|---|
| 96 | props[i].value >>= simple; |
|---|
| 97 | att_factor = (short)simple; |
|---|
| 98 | |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void process_data(void *data) |
|---|
| 105 | { |
|---|
| 106 | std::cout << "ChannelDemo process_data thread started" << std::endl; |
|---|
| 107 | |
|---|
| 108 | ChannelDemo_i *channel = (ChannelDemo_i *) data; |
|---|
| 109 | PortTypes::ShortSequence *I_in(NULL), *Q_in(NULL); |
|---|
| 110 | PortTypes::ShortSequence I_out, Q_out; |
|---|
| 111 | while(1) |
|---|
| 112 | { |
|---|
| 113 | channel->dataIn->getData(I_in, Q_in); |
|---|
| 114 | std::cout<<"Data is in Channel"<<std::endl; |
|---|
| 115 | std::cout<<"Applying Simple Scaling Factor of 1/"<< channel->att_factor << std::endl; |
|---|
| 116 | std::cout<<"Output from Channel is..." <<std::endl; |
|---|
| 117 | I_out.length(I_in->length()); |
|---|
| 118 | Q_out.length(Q_in->length()); |
|---|
| 119 | for(unsigned int i=0; i < I_out.length(); i = i+1) |
|---|
| 120 | { |
|---|
| 121 | I_out[i] = (*I_in)[i]/(channel->att_factor); |
|---|
| 122 | Q_out[i] = (*Q_in)[i]/(channel->att_factor); |
|---|
| 123 | std::cout << "Input (" << i << ") to channel is I " << (*I_in)[i] << ", and Q " << (*Q_in)[i] << std::endl; |
|---|
| 124 | std::cout << "Output (" << i << ") from channel I " << I_out[i] << ", and Q " << Q_out[i] <<std::endl; |
|---|
| 125 | } |
|---|
| 126 | channel->dataIn->bufferEmptied(); |
|---|
| 127 | std::cout<<"Channel pushing data"<<std::endl; |
|---|
| 128 | channel->dataOut->pushPacket(I_out, Q_out); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|