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() );
101 for(vector<string>::iterator it = parts.begin(); it != parts.end(); ++it ) {
103 DataSourceBase::shared_ptr part = dsb->getMember( *it );
105 log(
Error) <<
"memberDecomposition: Inconsistent type info for "<< dsb->getTypeName() <<
": reported to have part '"<<*it<<
"' but failed to return it."<<endlog();
108 if ( !part->isAssignable() ) {
110 log(
Debug)<<
"memberDecomposition: Part "<< *it <<
":"<< part->getTypeName() <<
" is not changeable."<<endlog();
114 DataSourceBase::shared_ptr ref = part->getTypeInfo()->buildReference( 0 );
115 dsb->getTypeInfo()->getMember( dynamic_cast<Reference*>(ref.get() ), dsb, *it);
117 PropertyBase* newpb = part->getTypeInfo()->buildProperty(*it,
"Part", ref);
119 log(
Error)<<
"Decomposition failed because Part '"<<*it<<
"' is not known to type system."<<endlog();
124 assert( recurse_bag->value().empty() );
127 if ( converted && converted != dsb ) {
129 targetbag.
add( converted->getTypeInfo()->buildProperty(*it,
"", converted) );
134 recurse_bag->setName(*it);
147 int msize = size->
get();
148 for (
int i=0; i < msize; ++i) {
149 string indx = boost::lexical_cast<
string>( i );
150 DataSourceBase::shared_ptr item = dsb->getMember(indx);
153 if ( !item->isAssignable() ) {
155 log(
Warning)<<
"memberDecomposition: Item '"<< indx <<
"' of type "<< dsb->getTypeName() <<
" is not changeable."<<endlog();
159 PropertyBase* newpb = item->getTypeInfo()->buildProperty( indx,
"",item);
164 recurse_bag->setName( indx );
172 if (targetbag.
empty() )
173 log(
Debug) <<
"memberDecomposition: "<< dsb->getTypeName() <<
" returns an empty property bag." << endlog();
177 ReportingComponent::ReportingComponent( std::string name )
179 report(
"Report"), snapshotted(false),
180 writeHeader(
"WriteHeader",
"Set to true to start each report with a header.", true),
181 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),
182 complexdecompose(
"ComplexDecompose",
"Use slow but more robust procedure for port data decomposition.", false),
183 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),
184 synchronize_with_logging(
"Synchronize",
"Set to true if the timestamp should be synchronized with the logging",false),
185 report_data(
"ReportData",
"A PropertyBag which defines which ports or components to report."),
189 timestamp(
"TimeStamp",
"The time at which the data was read.",0.0)
191 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.");
200 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).");
220 boost::shared_ptr<marsh::MarshallInterface> header(headerM);
221 boost::shared_ptr<marsh::MarshallInterface> body(bodyM);
222 if ( !header && !body)
229 marshallers.push_back( std::make_pair( header, body ) );
247 Logger::In in(
"ReportingComponent");
253 log(
Error) <<
"No port or component configuration loaded."<<endlog();
254 log(
Error) <<
"Please use marshalling.loadProperties(), reportComponent() (scripting) or LoadProperties (XML) in order to fill in ReportData." <<endlog();
264 log(
Error) <<
"Expected Property \"" 265 << (*it)->
getName() <<
"\" to be of type string."<< endlog();
266 else if ( compName->
getName() ==
"Component" ) {
267 std::string name = compName->
value();
271 else if ( compName->
getName() ==
"Port" ) {
272 string cname = compName->
value().substr(0, compName->
value().find(
"."));
273 string pname = compName->
value().substr( compName->
value().find(
".")+1, string::npos);
274 if (cname.empty() || pname.empty() ) {
275 log(
Error) <<
"The Port value '"<<compName->
getName()<<
"' must at least consist of a component name followed by a dot and the port name." <<endlog();
282 else if ( compName->
getName() ==
"Data" ) {
283 string cname = compName->
value().substr(0, compName->
value().find(
"."));
284 string pname = compName->
value().substr( compName->
value().find(
".")+1, string::npos);
285 if (cname.empty() || pname.empty() ) {
286 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();
294 log(
Error) <<
"Expected \"Component\", \"Port\" or \"Data\", got " 295 << compName->
getName() << endlog();
305 Logger::In in(
"ReportingComponent::screenComponent");
306 log(
Error) <<
"not implemented." <<comp<<endlog();
312 Logger::In in(
"ReportingComponent");
315 log(
Error) <<
"Unknown Component: " <<comp<<endlog();
318 output <<
"Screening Component '"<< comp <<
"' : "<<
endl <<
endl;
321 output <<
"Properties :" << endl;
323 output <<
" " << (*it)->getName() <<
" : " << (*it)->getDataSource() << endl;
326 if ( !atts.empty() ) {
327 output <<
"Attributes :" << endl;
328 for (ConfigurationInterface::AttributeNames::iterator it= atts.begin(); it != atts.end(); ++it)
329 output <<
" " << *it <<
" : " << c->
provides()->getValue(*it)->getDataSource() << endl;
333 if ( !ports.empty() ) {
334 output <<
"Ports :" << endl;
335 for (vector<string>::iterator it= ports.begin(); it != ports.end(); ++it) {
336 output <<
" " << *it <<
" : ";
338 output <<
"(connected)" << endl;
340 output <<
"(not connected)" << endl;
347 Logger::In in(
"ReportingComponent");
352 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
355 if ( !
report_data.value().findValue<
string>(component) )
358 for (Ports::iterator it = ports.begin(); it != ports.end() ; ++it) {
359 log(
Debug) <<
"Checking port " << (*it)->getName()<<
"."<<endlog();
360 this->
reportPort( component, (*it)->getName() );
369 log(
Error) <<
"Could not unreport Component " << component <<
" : no such peer."<<endlog();
373 for (Ports::iterator it = ports.begin(); it != ports.end() ; ++it) {
385 Logger::In in(
"ReportingComponent");
388 log(
Warning) <<
"Already reporting "<<component<<
"."<<port<<
": removing old port first."<<endlog();
392 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
395 std::vector<std::string> strs;
396 boost::split(strs, port, boost::is_any_of(
"."));
399 if (strs.empty())
return false;
402 while ( strs.size() != 1 && service) {
403 service = service->getService( strs.front() );
405 strs.erase( strs.begin() );
408 log(
Error) <<
"No such service: '"<< strs.front() <<
"' while looking for port '"<< port<<
"'"<<endlog();
412 porti = service->getPort(strs.front());
414 log(
Error) <<
"Could not report Port " << port
415 <<
" : no such port on Component "<<component<<
"."<<endlog();
421 log(
Error) <<
"Can not report InputPort "<< porti->
getName() <<
" of Component " << component <<endlog();
429 ourport->
setName(component +
"_" + port);
434 log(
Info) <<
"Not buffering of data flow connections. You may miss samples." <<endlog();
436 log(
Info) <<
"Buffering ports with size "<<
report_policy.
size <<
", as set in ReportPolicy property." <<endlog();
442 log(
Error) <<
"Could not connect to OutputPort " << porti->
getName() << endlog();
451 log(
Error) <<
"Failed reporting port " << port << endlog();
457 log(
Info) <<
"Monitoring OutputPort " << port <<
" : ok." << endlog();
459 if ( !
report_data.value().findValue<
string>(component) && !
report_data.value().findValue<
string>( component+
"."+port) )
477 Logger::In in(
"ReportingComponent");
480 log(
Error) <<
"Could not report Component " << component <<
" : no such peer."<<endlog();
484 if ( comp->
provides()->getValue( dataname ) ) {
486 comp->
provides()->getValue( dataname )->getDataSource(), 0, false ) ==
false) {
487 log(
Error) <<
"Failed reporting data " << dataname <<endlog();
496 log(
Error) <<
"Failed reporting data " << dataname <<endlog();
502 if ( !
report_data.value().findValue<
string>( component+
"."+dataname) )
514 for (Reports::iterator it =
root.begin();
515 it !=
root.end(); ++it)
524 log(
Error) <<
"Could not report '"<< tag <<
"' : unknown type." << endlog();
527 PropertyBase* prop = 0;
528 root.push_back( boost::make_tuple( tag, orig, type, prop, ipi,
false, track ) );
534 for (Reports::iterator it =
root.begin();
535 it !=
root.end(); ++it)
544 Logger::In in(
"ReportingComponent");
546 log(
Error) <<
"Need at least one marshaller to write reports." <<endlog();
553 starttime = os::TimeService::Instance()->getTicks();
563 it->first->serialize(
report );
571 it->second->serialize(
report );
578 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it )
579 if ( it->get<
T_Port>() ) {
580 #ifndef ORO_SIGNALLING_PORTS 605 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it ) {
620 for(Reports::iterator it =
root.begin(); it !=
root.end(); ++it ) {
622 bool decompose_success =
false;
627 if ( decompose_success ) {
633 if ( converted && converted != it->get<
T_PortDS>() ) {
635 PropertyBase* convProp = converted->getTypeInfo()->buildProperty(it->get<
T_QualName>(),
"", converted);
678 for (Reports::const_iterator i =
root.begin();
683 it->second->serialize( i->get<
T_Property>() );
687 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)