| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2006, Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Core Framework. |
|---|
| 6 | |
|---|
| 7 | OSSIE Core Framework is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the Lesser GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Core Framework 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 | Lesser GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the Lesser GNU General Public License |
|---|
| 18 | along with OSSIE Core Framework; 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 <iostream> |
|---|
| 24 | |
|---|
| 25 | #include <standardinterfaces/realChar_p.h> |
|---|
| 26 | |
|---|
| 27 | standardInterfaces_i::realChar_p::realChar_p(const char* _name, unsigned int bufLen) : portName(_name), bufferLength(bufLen), rdPtr(0), wrPtr(0) |
|---|
| 28 | { |
|---|
| 29 | |
|---|
| 30 | data_servant = new realChar::providesPort(this); |
|---|
| 31 | data_servant_var = data_servant->_this(); |
|---|
| 32 | |
|---|
| 33 | PortTypes::CharSequence a; |
|---|
| 34 | I_buf.assign(bufferLength, a); |
|---|
| 35 | |
|---|
| 36 | ready_for_input = new omni_semaphore(bufferLength); |
|---|
| 37 | data_ready = new omni_semaphore(0); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | standardInterfaces_i::realChar_p::~realChar_p() |
|---|
| 41 | { |
|---|
| 42 | |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | CORBA::Object_ptr standardInterfaces_i::realChar_p::getPort(const char* _portName) |
|---|
| 46 | { |
|---|
| 47 | if (portName == _portName) |
|---|
| 48 | return CORBA::Object::_duplicate(data_servant_var); |
|---|
| 49 | else |
|---|
| 50 | return CORBA::Object::_nil(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void standardInterfaces_i::realChar_p::bufferEmptied() |
|---|
| 54 | { |
|---|
| 55 | ready_for_input->post(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void standardInterfaces_i::realChar_p::getData(PortTypes::CharSequence* &I) |
|---|
| 59 | { |
|---|
| 60 | data_ready->wait(); |
|---|
| 61 | |
|---|
| 62 | I = &I_buf[rdPtr]; |
|---|
| 63 | rdPtr = ++rdPtr % bufferLength; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | realChar::providesPort::providesPort(standardInterfaces_i::realChar_p* _base) : base(_base) |
|---|
| 67 | { |
|---|
| 68 | |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | realChar::providesPort::~providesPort() |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void realChar::providesPort::pushPacket(const PortTypes::CharSequence &I) |
|---|
| 77 | { |
|---|
| 78 | base->ready_for_input->wait(); |
|---|
| 79 | |
|---|
| 80 | base->I_buf[base->wrPtr] = I; |
|---|
| 81 | base->wrPtr= ++base->wrPtr % base->bufferLength; |
|---|
| 82 | |
|---|
| 83 | base->data_ready->post(); |
|---|
| 84 | } |
|---|