| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE _base_. |
|---|
| 6 | |
|---|
| 7 | OSSIE _base_ is free software; you can redistribute it and/or _base_ify |
|---|
| 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 _base_ 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 _base_; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | #include <string> |
|---|
| 24 | #include <iostream> |
|---|
| 25 | #include "_base_.h" |
|---|
| 26 | |
|---|
| 27 | _base__i::_base__i(const char *uuid, omni_condition *condition) : |
|---|
| 28 | Resource_impl(uuid), component_running(condition) |
|---|
| 29 | { |
|---|
| 30 | p_in = complexShort_p_sptr(new standardInterfaces_i::complexShort_p("samples_in")); |
|---|
| 31 | p_out = complexShort_u_sptr(new standardInterfaces_i::complexShort_u("samples_out")); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | CORBA::Object_ptr _base__i::getPort( const char* portName ) |
|---|
| 35 | throw (CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 36 | { |
|---|
| 37 | DEBUG(3, _base_, "getPort() invoked with " << portName) |
|---|
| 38 | |
|---|
| 39 | CORBA::Object_var p; |
|---|
| 40 | |
|---|
| 41 | p = p_in->getPort(portName); |
|---|
| 42 | |
|---|
| 43 | if (!CORBA::is_nil(p)) |
|---|
| 44 | return p._retn(); |
|---|
| 45 | |
|---|
| 46 | p = p_out->getPort(portName); |
|---|
| 47 | |
|---|
| 48 | if (!CORBA::is_nil(p)) |
|---|
| 49 | return p._retn(); |
|---|
| 50 | |
|---|
| 51 | /*exception*/ |
|---|
| 52 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void _base__i::start() |
|---|
| 56 | throw (CORBA::SystemException, CF::Resource::StartError) |
|---|
| 57 | { |
|---|
| 58 | DEBUG(3, _base_, "start() invoked") |
|---|
| 59 | |
|---|
| 60 | if (!processing_active) { |
|---|
| 61 | processing_thread = new omni_thread(process_data, (void*) this); |
|---|
| 62 | processing_active = true; |
|---|
| 63 | processing_thread->start(); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void _base__i::stop() |
|---|
| 68 | throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 69 | { |
|---|
| 70 | DEBUG(3, _base_, "stop() invoked") |
|---|
| 71 | |
|---|
| 72 | processing_active = false; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | void _base__i::releaseObject() |
|---|
| 76 | throw (CORBA::SystemException, CF::LifeCycle::ReleaseError) |
|---|
| 77 | { |
|---|
| 78 | DEBUG(3, _base_, "releaseObject() invoked") |
|---|
| 79 | |
|---|
| 80 | component_running->signal(); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | void _base__i::initialize() |
|---|
| 84 | throw (CF::LifeCycle::InitializeError, CORBA::SystemException) |
|---|
| 85 | { |
|---|
| 86 | DEBUG(3, _base_, "initialize() invoked") |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | void _base__i::configure(const CF::Properties& props) |
|---|
| 90 | throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, |
|---|
| 91 | CF::PropertySet::PartialConfiguration) |
|---|
| 92 | { |
|---|
| 93 | DEBUG(3, _base_, "configure() invoked") |
|---|
| 94 | |
|---|
| 95 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 96 | |
|---|
| 97 | for (unsigned int i = 0; i <props.length(); i++) { |
|---|
| 98 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | _base__i::~_base__i(void) |
|---|
| 103 | { |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | void _base__i::process_data(void *data) |
|---|
| 108 | { |
|---|
| 109 | DEBUG(3, _base_, "ProcessData() invoked") |
|---|
| 110 | |
|---|
| 111 | _base__i *_base_ = (_base__i *) data; |
|---|
| 112 | |
|---|
| 113 | PortTypes::ShortSequence i_out, q_out; |
|---|
| 114 | PortTypes::ShortSequence *i_in(NULL), *q_in(NULL); |
|---|
| 115 | |
|---|
| 116 | while (_base_->processing_active) { |
|---|
| 117 | _base_->p_in->getData(i_in, q_in); |
|---|
| 118 | |
|---|
| 119 | _base_->p_in->bufferEmptied(); |
|---|
| 120 | _base_->p_out->pushPacket(i_out, q_out); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | DEBUG(3, _base_, "ProcessData() exiting") |
|---|
| 124 | _base_->processing_active = false; |
|---|
| 125 | _base_->processing_thread->exit(); |
|---|
| 126 | } |
|---|