29 #include <rtt/Logger.hpp> 30 #include <rtt/os/Mutex.hpp> 31 #include <rtt/Property.hpp> 32 #include <rtt/base/PropertyIntrospection.hpp> 34 #include "socketmarshaller.hpp" 35 #include "datasender.hpp" 36 #include "command.hpp" 37 #include "TcpReporting.hpp" 38 #include <rtt/types/TemplateTypeInfo.hpp> 45 Activity(10), os( _os ), marshaller(_marshaller)
49 reporter = marshaller->getReporter();
51 interpreter =
new TcpReportingInterpreter(
this);
54 Datasender::~Datasender()
56 subscriptions.clear();
61 void Datasender::loop()
63 *os <<
"100 Orocos 1.0 TcpReporting Server 1.0" << std::endl;
64 while( os->isValid() )
66 interpreter->process();
68 Logger::log() << Logger::Info <<
"Connection closed!" << Logger::endl;
71 bool Datasender::breakloop()
82 Socket& Datasender::getSocket()
const 87 bool Datasender::isValid()
const 92 bool Datasender::addSubscription(
const std::string name )
95 log(Debug)<<
"Datasender::addSubscription: "<<name<<endlog();
97 if(reporter->getReport()->find(name)!=NULL){
99 std::vector<std::string>::const_iterator pos =
100 find(subscriptions.begin(),subscriptions.end(),name);
101 if(pos!=subscriptions.end()){
102 Logger::In(
"DataSender");
103 log(Info)<<
"Already subscribed to "<<name<<endlog();
107 Logger::In(
"DataSender");
108 log(Info)<<
"Adding subscription for "<<name<<endlog();
109 subscriptions.push_back(name);
114 Logger::In(
"DataSender");
115 log(Error)<<name<<
" is not available for reporting"<<endlog();
121 void Datasender::remove()
123 getMarshaller()->removeConnection(
this );
126 bool Datasender::removeSubscription(
const std::string& name )
130 std::vector<std::string>::iterator pos =
131 find(subscriptions.begin(),subscriptions.end(),name);
132 if(pos!=subscriptions.end()){
133 Logger::In(
"DataSender");
134 log(Info)<<
"Removing subscription for "<<name<<endlog();
135 subscriptions.erase(pos);
139 Logger::In(
"DataSenser");
140 log(Error)<<
"No subscription found for "<<name<<endlog();
146 void Datasender::listSubscriptions()
148 for(std::vector<std::string>::const_iterator elem=subscriptions.begin();
149 elem!=subscriptions.end();elem++)
150 *os<<
"305 "<< *elem<<std::endl;
151 *os <<
"306 End of list" << std::endl;
154 void Datasender::writeOut(base::PropertyBase* v)
156 *os<<
"202 "<<v->getName()<<
"\n";
157 Property<PropertyBag>* bag =
dynamic_cast< Property<PropertyBag>*
>( v );
159 this->writeOut( bag->value() );
161 *os<<
"205 " <<v->getDataSource()<<
"\n";
166 void Datasender::writeOut(
const PropertyBag &v)
169 PropertyBag::const_iterator i = v.getProperties().begin();
170 i != v.getProperties().end();
173 this->writeOut( *i );
179 void Datasender::checkbag(
const PropertyBag &v)
181 log(Debug)<<
"Let's check the subscriptions"<<endlog();
182 for(std::vector<std::string>::iterator elem = subscriptions.begin();
183 elem!=subscriptions.end();elem++){
184 base::PropertyBase* prop = reporter->getReport()->find(*elem);
188 Logger::In(
"DataSender");
189 log(Error)<<*elem<<
" not longer available for reporting,"<<
190 ", removing the subscription."<<endlog();
191 subscriptions.erase(elem);
197 void Datasender::silence(
bool newstate)
202 void Datasender::setLimit(
unsigned long long newlimit)
207 void Datasender::serialize(
const PropertyBag &v)
214 if( !subscriptions.empty() && ( limit == 0 || curframe <= limit ) ){
215 *os <<
"201 " <<curframe <<
" -- begin of frame\n";
217 *os <<
"203 " << curframe <<
" -- end of frame" << std::endl;
219 if( curframe > limit && limit != 0 )
221 *os <<
"204 Limit reached" << std::endl;
marsh::MarshallInterface which sends data to multiple sockets.
The Orocos Component Library.
bool isValid() const
Check wether the state of the socket is valid or not.