root/ossiedev/trunk/system/standardInterfaces-metadata/complexShortMD_p.cpp @ 8173

Revision 8173, 4.6 KB (checked in by shereef, 5 years ago)

simd now under the siMD namespace

Line 
1/****************************************************************************
2
3Copyright 2006, Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Core Framework.
6
7OSSIE Core Framework is free software; you can redistribute it and/or modify
8it under the terms of the Lesser GNU General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or
10(at your option) any later version.
11
12OSSIE Core Framework 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
15Lesser GNU General Public License for more details.
16
17You should have received a copy of the Lesser GNU General Public License
18along with OSSIE Core Framework; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21****************************************************************************/
22
23#include <iostream>
24
25#include <ossie/ossieSupport.h>
26
27#include <standardinterfaces-metadata/complexShortMD_p.h>
28
29standardInterfacesMD_i::complexShort_p::complexShort_p(const char* _name, unsigned int bufLen) : portName(_name), bufferLength(bufLen), rdPtr(0), wrPtr(0)
30{
31
32    data_servant = new complexShort::providesPort(this);
33    data_servant_var = data_servant->_this();
34
35    // Initialize short sequence buffers with default
36    PortTypes::ShortSequence a;
37    I_buf.assign(bufferLength, a);
38    Q_buf.assign(bufferLength, a);
39
40    // Initialize MetaData
41    InitializeMetaData( metadata );
42    metadata_buf.assign(bufferLength, metadata);
43
44    ready_for_input = new omni_semaphore(bufferLength);
45    data_ready = new omni_semaphore(0);
46
47
48}
49
50standardInterfacesMD_i::complexShort_p::complexShort_p(const char* _name, const char* _domain, unsigned int bufLen) : portName(_name), bufferLength(bufLen), rdPtr(0), wrPtr(0)
51{
52    ossieSupport::ORB orb;
53
54    data_servant = new complexShort::providesPort(this);
55    data_servant_var = data_servant->_this();
56
57    PortTypes::ShortSequence a;
58    I_buf.assign(bufferLength, a);
59    Q_buf.assign(bufferLength, a);
60
61    // Initialize MetaData
62    InitializeMetaData( metadata );
63    metadata_buf.assign(bufferLength, metadata);
64
65    ready_for_input = new omni_semaphore(bufferLength);
66    data_ready = new omni_semaphore(0);
67
68    std::string objName;
69    objName = _domain;
70    objName += "/";
71    objName += _name;
72   
73    orb.bind_object_to_name((CORBA::Object_ptr) data_servant_var, objName.c_str());
74}
75
76standardInterfacesMD_i::complexShort_p::~complexShort_p()
77{
78
79}
80
81CORBA::Object_ptr standardInterfacesMD_i::complexShort_p::getPort(const char* _portName)
82{
83    if (portName == _portName)
84        return CORBA::Object::_duplicate(data_servant_var);
85    else
86        return CORBA::Object::_nil();
87}
88
89void standardInterfacesMD_i::complexShort_p::bufferEmptied()
90{
91    ready_for_input->post();
92}
93
94
95void standardInterfacesMD_i::complexShort_p::getData(
96        PortTypes::ShortSequence* &I,
97        PortTypes::ShortSequence* &Q,
98        standardInterfacesMD::MetaData* &packet_data)
99{
100    data_ready->wait();
101
102    I = &I_buf[rdPtr];
103    Q = &Q_buf[rdPtr];
104    packet_data = &metadata_buf[rdPtr];
105    rdPtr = (++rdPtr) % bufferLength;
106}
107
108
109void standardInterfacesMD_i::complexShort_p::getData(PortTypes::ShortSequence* &I, PortTypes::ShortSequence* &Q)
110{
111    data_ready->wait();
112
113    I = &I_buf[rdPtr];
114    Q = &Q_buf[rdPtr];
115    rdPtr = (++rdPtr) % bufferLength;
116}
117
118complexShort::providesPort::providesPort(standardInterfacesMD_i::complexShort_p* _base) : base(_base)
119{
120
121}
122
123complexShort::providesPort::~providesPort()
124{
125
126}
127
128void complexShort::providesPort::pushPacket(
129        const PortTypes::ShortSequence &I,
130        const PortTypes::ShortSequence &Q)
131{
132    base->ready_for_input->wait();
133
134    (base->I_buf)[base->wrPtr] = I;
135    (base->Q_buf)[base->wrPtr] = Q;
136
137    // Create blank metadata object and add it to buffer
138    standardInterfacesMD::MetaData metadata;
139    InitializeMetaData( metadata );
140    (base->metadata_buf)[base->wrPtr] = metadata;
141
142    base->wrPtr = (++(base->wrPtr)) % base->bufferLength;
143
144    base->data_ready->post();
145}
146
147void complexShort::providesPort::pushPacketMetaData(
148        const PortTypes::ShortSequence &I,
149        const PortTypes::ShortSequence &Q,
150        const standardInterfacesMD::MetaData &packet_data)
151{
152    base->ready_for_input->wait();
153
154    (base->I_buf)[base->wrPtr] = I;
155    (base->Q_buf)[base->wrPtr] = Q;
156
157    // Deep copy meta data to complexShort_p base and add it to the buffer
158    base->metadata = packet_data;
159    (base->metadata_buf)[base->wrPtr] = packet_data;
160
161    base->wrPtr = (++(base->wrPtr)) % base->bufferLength;
162
163    base->data_ready->post();
164}
Note: See TracBrowser for help on using the browser.