38 #include <boost/algorithm/string.hpp> 42 #include <boost/lexical_cast.hpp> 62 : msize(size), mds(ds), mupstream(upstream)
73 result = (mupstream->get() && msize == mds->get());
75 result = (msize == mds->get());
91 vector<string> parts = dsb->getMemberNames();
92 if ( parts.empty() ) {
96 targetbag.
setType( dsb->getTypeName() );
99 #if __cplusplus < 201103L 105 for(vector<string>::iterator it = parts.begin(); it != parts.end(); ++it ) {
107 DataSourceBase::shared_ptr part = dsb->getMember( *it );
109 log(
Error) <<
"memberDecomposition: Inconsistent type info for "<< dsb->getTypeName() <<
": reported to have part '"<<*it<<
"' but failed to return it."<<endlog();
112 if ( !part->isAssignable() ) {
114 log(
Debug)<<
"memberDecomposition: Part "<< *it <<
":"<< part->getTypeName() <<
" is not changeable."<<endlog();
118 DataSourceBase::shared_ptr ref = part->getTypeInfo()->buildReference( 0 );
119 dsb->getTypeInfo()->getMember( dynamic_cast<Reference*>(ref.get() ), dsb, *it);
121 PropertyBase* newpb = part->getTypeInfo()->buildProperty(*it,
"Part", ref);
123 log(
Error)<<
"Decomposition failed because Part '"<<*it<<
"' is not known to type system."<<endlog();
128 assert( recurse_bag->value().empty() );
131 if ( converted && converted != dsb ) {
133 targetbag.
add( converted->getTypeInfo()->buildProperty(*it,
"", converted) );
138 recurse_bag->setName(*it);
151 int msize = size->
get();
152 for (
int i=0; i < msize; ++i) {
153 string indx = boost::lexical_cast<
string>( i );
154 DataSourceBase::shared_ptr item = dsb->getMember(indx);
157 if ( !item->isAssignable() ) {
159 log(
Warning)<<
"memberDecomposition: Item '"<< indx <<
"' of type "<< dsb->getTypeName() <<
" is not changeable."<<endlog();
163 PropertyBase* newpb = item->getTypeInfo()->buildProperty( indx,
"",item);
168 recurse_bag->setName( indx );
176 if (targetbag.
empty() )
177 log(
Debug) <<
"memberDecomposition: "<< dsb->getTypeName() <<
" returns an empty property bag." << endlog();
181 ReportingComponent::ReportingComponent( std::string name )
183 report(
"Report"), snapshotted(false),
184 writeHeader(
"WriteHeader",
"Set to true to start each report with a header.", true),
185 decompose(
"Decompose",
"Set to false in order to not decompose the port data. The marshaller must be able to handle this itself for this to work.", true),
186 complexdecompose(
"ComplexDecompose",
"Use slow but more robust procedure for port data decomposition.", false),
187 insnapshot(
"Snapshot",
"Set to true to enable snapshot mode. This will cause a non-periodic reporter to only report data upon the snapshot() operation.",false),
188 synchronize_with_logging(
"Synchronize",
"Set to true if the timestamp should be synchronized with the logging",false),
189 report_data(
"ReportData",
"A PropertyBag which defines which ports or components to report."),
193 timestamp(
"TimeStamp",
"The time at which the data was read.",0.0)
195 this->
provides()->doc(
"Captures data on data ports. A periodic reporter will sample each added port according to its period, a non-periodic reporter will write out data as it comes in, or only during a snapshot() if the Snapshot property is true.");
204 this->
properties()->
addProperty(
"ReportOnlyNewData",
onlyNewData).doc(
"Turn on in order to only write out NewData on ports and omit unchanged ports. Turn off in order to sample and write out all ports (even old data).");
224 boost::shared_ptr<marsh::MarshallInterface> header(headerM);
225 boost::shared_ptr<marsh::MarshallInterface> body(bodyM);
226 if ( !header && !body)
233 marshallers.push_back( std::make_pair( header, body ) );
251 Logger::In in(
"ReportingComponent");
257 log(
Error) <<
"No port or component configuration loaded."<<endlog();
258 log(
Error) <<
"Please use marshalling.loadProperties(), reportComponent() (scripting) or LoadProperties (XML) in order to fill in ReportData." <<endlog();
268 log(
Error) <<
"Expected Property \"" 269 << (*it)->
getName() <<
"\" to be of type string."<< endlog();
270 else if ( compName->
getName() ==
"Component" ) {
271 std::string name = compName->
value();
275 else if ( compName->
getName() ==
"Port" ) {
276 string cname = compName->
value().substr(0, compName->
value().find(
"."));
277 string pname = compName->
value().substr( compName->
value().find(
".")+1, string::npos);
278 if (cname.empty() || pname.empty() ) {
279 log(
Error) <<
"The Port value '"<<compName->
getName()<<
"' must at least consist of a component name followed by a dot and the port name." <<endlog();
286 else if ( compName->
getName() ==
"Data" ) {
287 string cname = compName->
value().substr(0, compName->
value().find(
"."));
288 string pname = compName->
value().substr( compName->
value().find(
".")+1, string::npos);
289 if (cname.empty() || pname.empty() ) {
290 log(
Error) <<
"The Data value '"<<compName->
getName()<<
"' must at least consist of a component name followed by a dot and the property/attribute name." <<endlog();
298 log(
Error) <<
"Expected \"Component\", \"Port\" or \"Data\", got " 299 << compName->
getName() << endlog();
309 Logger::In in(
"ReportingComponent::screenComponent");
310 log(
Error) <<
"not implemented." <<comp<<endlog();
316 Logger::In in(
"ReportingComponent");
319 log(
Error) <<
"Unknown Component: " <<comp<<endlog();
322 output <<
"Screening Component '"<< comp <<
"' : "<<
endl <<
endl;
325 output <<
"Properties :" << endl;
327 output <<
" " << (*it)->getName() <<
" : " << (*it)->getDataSource() << endl;
330 if ( !atts.empty() ) {
331 output <<
"Attributes :" << endl;
332 for (ConfigurationInterface::AttributeNames::iterator it= atts.begin(); it != atts.end(); ++it)
333 output <<
" " << *it <<
" : " << c->
provides()->getValue(*it)->getDataSource() << endl;
337 if ( !ports.empty() ) {
338 output <<
"Ports :" << endl;
339 for (vector<string>::iterator it= ports.begin(); it != ports.end(); ++it) {
340 output <<
" " << *it <<
" : ";
342 output <<
"(connected)" << endl;
344 output <<
"(not connected)" << endl;
351 Logger::In in(
"ReportingComponent");
356 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
359 if ( !
report_data.value().findValue<
string>(component) )
362 for (Ports::iterator it = ports.begin(); it != ports.end() ; ++it) {
363 log(
Debug) <<
"Checking port " << (*it)->getName()<<
"."<<endlog();
364 this->
reportPort( component, (*it)->getName() );
373 log(
Error) <<
"Could not unreport Component " << component <<
" : no such peer."<<endlog();
377 for (Ports::iterator it = ports.begin(); it != ports.end() ; ++it) {
389 Logger::In in(
"ReportingComponent");
392 log(
Warning) <<
"Already reporting "<<component<<
"."<<port<<
": removing old port first."<<endlog();
396 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
399 std::vector<std::string> strs;
400 boost::split(strs, port, boost::is_any_of(
"."));
403 if (strs.empty())
return false;
406 while ( strs.size() != 1 && service) {
407 service = service->getService( strs.front() );
409 strs.erase( strs.begin() );
412 log(
Error) <<
"No such service: '"<< strs.front() <<
"' while looking for port '"<< port<<
"'"<<endlog();
416 porti = service->getPort(strs.front());
418 log(
Error) <<
"Could not report Port " << port
419 <<
" : no such port on Component "<<component<<
"."<<endlog();
425 log(
Error) <<
"Can not report InputPort "<< porti->
getName() <<
" of Component " << component <<endlog();
433 ourport->
setName(component +
"_" + port);
438 log(
Info) <<
"Not buffering of data flow connections. You may miss samples." <<endlog();
440 log(
Info) <<
"Buffering ports with size "<<
report_policy.
size <<
", as set in ReportPolicy property." <<endlog();
446 log(
Error) <<
"Could not connect to OutputPort " << porti->
getName() << endlog();
455 log(
Error) <<
"Failed reporting port " << port << endlog();
461 log(
Info) <<
"Monitoring OutputPort " << port <<
" : ok." << endlog();
463 if ( !
report_data.value().findValue<
string>(component) && !
report_data.value().findValue<
string>( component+
"."+port) )
481 Logger::In in(
"ReportingComponent");
484 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
488 if ( comp->
provides()->getValue( dataname ) ) {
490 comp->
provides()->getValue( dataname )->getDataSource(), 0, false ) ==
false) {
491 log(
Error) <<
"Failed reporting data " << dataname <<endlog();
500 log(
Error) <<
"Failed reporting data " << dataname <<endlog();
506 if ( !
report_data.value().findValue<
string>( component+
"."+dataname) )
518 for (Reports::iterator it =
root.begin();
519 it !=
root.end(); ++it)
528 log(
Error) <<
"Could not report '"<< tag <<
"' : unknown type." << endlog();
531 PropertyBase* prop = 0;
532 root.push_back( boost::make_tuple( tag, orig, type, prop, ipi,
false, track ) );
538 for (Reports::iterator it =
root.begin();
539 it !=
root.end(); ++it)
548 Logger::In in(
"ReportingComponent");
550 log(
Error) <<
"Need at least one marshaller to write reports." <<endlog();
557 starttime = os::TimeService::Instance()->getTicks();
567 it->first->serialize(
report );
575 it->second->serialize(
report );
582 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it )
583 if ( it->get<
T_Port>() ) {
584 #ifndef ORO_SIGNALLING_PORTS 609 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it ) {
624 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it ) {
626 bool decompose_success =
false;
631 if ( decompose_success ) {
637 if ( converted && converted != it->get<
T_PortDS>() ) {
639 PropertyBase* convProp = converted->getTypeInfo()->buildProperty(it->get<
T_QualName>(),
"", converted);
682 for (Reports::const_iterator i =
root.begin();
687 it->second->serialize( i->get<
T_Property>() );
691 it->second->serialize(
report );
virtual base::DataSourceBase::shared_ptr getDataSource() const
DataSourceType get() const
DataSource< bool >::shared_ptr mupstream
virtual result_t get() const =0
void add(base::PropertyBase *p)
bool addMarshaller(RTT::marsh::MarshallInterface *headerM, RTT::marsh::MarshallInterface *bodyM)
base::PortInterface * getPort(const std::string &name) const
virtual void updateHook()
Service::shared_ptr provides()
RTT::Property< RTT::os::TimeService::Seconds > timestamp
PortNames getPortNames() const
RTT::Property< bool > synchronize_with_logging
bool unreportComponent(const std::string &component)
static Logger * Instance(std::ostream &str=std::cerr)
RTT::Property< bool > writeHeader
RTT::Property< bool > insnapshot
void setType(const std::string &newtype)
static int report(lua_State *L, int status)
RTT::internal::DataSource< bool >::shared_ptr mchecker
If false, a sequence size has changed.
const std::string & getName() const
A Dummy Empty MarshallInterface.
base::InputPortInterface & addEventPort(const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
bool unreportPort(const std::string &component, const std::string &port)
bool ownProperty(base::PropertyBase *p)
RTT::DataFlowInterface::Ports Ports
virtual TaskContext * getPeer(const std::string &peer_name) const
boost::shared_ptr< Service > shared_ptr
RTT::Property< bool > complexdecompose
void deletePropertyBag(PropertyBag &target)
std::vector< std::string > AttributeNames
bool unreportDataSource(std::string tag)
DataFlowInterface * ports()
Property< T > & addProperty(const std::string &name, T &attr)
base::PortInterface * getPort(const std::string &name) const
virtual ~ReportingComponent()
base::PropertyBase * find(const std::string &name) const
void removePort(const std::string &name)
virtual bool configureHook()
CheckSizeDataSource(int size, DataSource< int >::shared_ptr ds, DataSource< bool >::shared_ptr upstream)
RTT::ConnPolicy report_policy
bool unreportData(const std::string &component, const std::string &datasource)
bool reportPort(const std::string &component, const std::string &port)
virtual const types::TypeInfo * getTypeInfo() const
bool setName(const std::string &name)
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
bool reportData(const std::string &component, const std::string &dataname)
Properties & getProperties()
virtual PortInterface * antiClone() const =0
Properties::const_iterator const_iterator
basic_ostreams & endl(basic_ostreams &s)
bool typeDecomposition(base::DataSourceBase::shared_ptr dsb, PropertyBag &targetbag, bool recurse)
boost::intrusive_ptr< DataSource< int > > shared_ptr
bool screenImpl(const std::string &comp, std::ostream &output)
bool reportDataSource(std::string tag, std::string type, RTT::base::DataSourceBase::shared_ptr origm, RTT::base::InputPortInterface *ipi, bool)
static DataSource< int > * narrow(base::DataSourceBase *db)
PropertyBag * properties()
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)=0
const std::string & getName() const
bool memberDecomposition(base::DataSourceBase::shared_ptr dsb, PropertyBag &targetbag, DataSource< bool >::shared_ptr &resized)
RTT::Property< bool > decompose
virtual bool screenComponent(const std::string &comp)
RTT::Property< PropertyBag > report_data
Properties::iterator iterator
boost::intrusive_ptr< DataSourceBase > shared_ptr
DataSource< int >::shared_ptr mds
virtual bool connected() const =0
RTT::os::TimeService::ticks starttime
Operation< Signature > & addOperation(Operation< Signature > &op)
ORO_CREATE_COMPONENT_TYPE()
virtual void cleanupHook()
base::ActivityInterface * getActivity()
virtual DataSourceBase::shared_ptr getDataSource() const =0
os::TimeService::ticks getReferenceTime() const
bool reportComponent(const std::string &component)