socketmarshaller.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  socketmarshaller.cpp - description
4  -------------------
5  begin : Mon August 7 2006
6  copyright : (C) 2006 Bas Kemper
7  email : kst@baskemper.be
8 
9  ***************************************************************************
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2.1 of the License, or (at your option) any later version. *
14  * *
15  * This library is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Lesser General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Lesser General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 59 Temple Place, *
23  * Suite 330, Boston, MA 02111-1307 USA *
24  * *
25  ***************************************************************************/
26 
27 #include <rtt/Logger.hpp>
28 #include <rtt/Property.hpp>
30 #include <rtt/os/Mutex.hpp>
31 #include "TcpReporting.hpp"
32 #include "socketmarshaller.hpp"
33 #include "datasender.hpp"
34 
35 using RTT::Logger;
36 
37 namespace RTT
38 {
40  : _reporter(reporter)
41  {
42  }
43 
45  {
47  }
48 
50  {
51  lock.lock();
52  OCL::TCP::Datasender* conn = new OCL::TCP::Datasender(this, os);
53  _connections.push_front( conn );
54  conn->Activity::start();
55  lock.unlock();
56  }
57 
59  {
60  // TODO: locking, proper connection shutdown
61  while( !_connections.empty() )
62  {
63  removeConnection( _connections.front() );
64  }
65  }
66 
68  {}
69 
71  {
72  lock.lock();
73  _connections.remove( sender );
74  sender->breakLoop();
75  delete sender;
76  lock.unlock();
77  }
78 
80  {
81  return _reporter;
82  }
83 
85  {
86  // This method is pure virtual in the parent class.
87  Logger::log() << Logger::Error << "Unexpected call to SocketMarshaller::serialize" <<
89  }
90 
92  {
93  lock.lock();
94  // TODO: sending data does not run in parallel!
95  for( std::list<OCL::TCP::Datasender*>::iterator it = _connections.begin();
96  it != _connections.end(); )
97  {
98  if( (*it)->isValid() )
99  {
100  (*it)->serialize(v);
101  it++;
102  } else {
103  OCL::TCP::Datasender* torm = *it;
104  it++;
105  removeConnection( torm );
106  }
107  }
108  lock.unlock();
109  }
110 
112  {
114  }
115 }
virtual void serialize(RTT::base::PropertyBase *)
OCL::TcpReporting * getReporter() const
A component which writes data reports to a tcp/ip socket. It can serve different clients. It uses a ASCI-based protocol.
virtual void unlock()
RTT::os::MutexRecursive lock
SocketMarshaller(OCL::TcpReporting *reporter)
void removeConnection(OCL::TCP::Datasender *sender)
virtual bool breakLoop()
static std::ostream & endl(std::ostream &__os)
std::list< OCL::TCP::Datasender * > _connections
OCL::TcpReporting * _reporter
static Logger & log()
void addConnection(OCL::TCP::Socket *os)


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27