root/ossiedev/branches/ttsou/dist/components/_base_/_base_.cpp @ 8632

Revision 8632, 3.5 KB (checked in by ttsou, 4 years ago)

thread change

Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE _base_.
6
7OSSIE _base_ is free software; you can redistribute it and/or _base_ify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE _base_ is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE _base_; if not, write to the Free Software
19Foundation, 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
34CORBA::Object_ptr _base__i::getPort( const char* portName )
35throw (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
55void _base__i::start()
56throw (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
67void _base__i::stop()
68throw (CORBA::SystemException, CF::Resource::StopError)
69
70    DEBUG(3, _base_, "stop() invoked")
71
72    processing_active = false;
73}
74
75void _base__i::releaseObject()
76throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
77{
78    DEBUG(3, _base_, "releaseObject() invoked")
79   
80    component_running->signal();
81}
82
83void _base__i::initialize()
84throw (CF::LifeCycle::InitializeError, CORBA::SystemException)
85{
86    DEBUG(3, _base_, "initialize() invoked")
87}
88
89void _base__i::configure(const CF::Properties& props)
90throw (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
107void _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}
Note: See TracBrowser for help on using the browser.