21 #include <yarp/os/all.h> 33 BufferedPort<Bottle> dumpPort;
52 agentName=rf.check(
"agent-name",Value(
"partner")).asString();
53 period=rf.check(
"period",Value(0.1)).asDouble();
57 yError()<<
"OPC seems unavailabe!";
61 dumpPort.open(
"/test_verbRec/dump:o");
62 verbPort.open(
"/test_verbRec/verb:rpc");
63 rpcPort.open(
"/test_verbRec/rpc");
84 Bottle &bDump=dumpPort.prepare();
87 bDump.addString(actionTag);
88 bDump.addString(objectTag);
95 if (
Agent *agent=dynamic_cast<Agent*>(e))
97 bDump.addList()=agent->m_body.asBottle();
98 Bottle &bAgent=bDump.addList();
99 bAgent.addString(agent->name());
100 bAgent.addDouble(agent->m_ego_position[0]);
101 bAgent.addDouble(agent->m_ego_position[1]);
102 bAgent.addDouble(agent->m_ego_position[2]);
103 bAgent.addInt(agent->m_present==1.0?1:0);
109 for (list<Entity*>::iterator itEnt=lEntity.begin(); itEnt!=lEntity.end(); itEnt++)
111 string entityName=(*itEnt)->name();
112 string entityType=(*itEnt)->entity_type();
115 if (
Object *
object=dynamic_cast<Object*>(*itEnt))
117 Bottle &bObject=bDump.addList();
118 bObject.addString(object->name());
119 bObject.addDouble(object->m_ego_position[0]);
120 bObject.addDouble(object->m_ego_position[1]);
121 bObject.addDouble(object->m_ego_position[2]);
122 bObject.addInt(object->m_present==1.0?1:0);
130 if (verbPort.getOutputCount()>0)
134 verbPort.write(cmd,reply);
135 Bottle &response=bDump.addList();
136 response.addString(
"response");
137 response.append(reply);
140 yInfo()<<bDump.toString();
141 dumpPort.writeStrict();
150 int cmd=command.get(0).asVocab();
151 int ack=Vocab::encode(
"ack");
152 int nack=Vocab::encode(
"nack");
154 if (cmd==Vocab::encode(
"start"))
156 if (command.size()>=3)
158 actionTag=command.get(1).asString();
159 objectTag=command.get(2).asString();
161 if (command.size()>=4)
163 int g=command.get(3).asInt();
170 reply.addVocab(nack);
173 else if (cmd==Vocab::encode(
"stop"))
181 else if (cmd==Vocab::encode(
"get"))
184 reply.addString(actionTag);
185 reply.addString(objectTag);
190 return RFModule::respond(command,reply);
209 if (!yarp.checkNetwork())
211 yError()<<
"YARP network seems unavailable!";
216 rf.configure(argc,argv);
219 return recorder.runModule(rf);
Represent any entity that can be stored within the OPC.
void close()
Close the client ports.
bool connect(const std::string &opcName)
Try to connect the client to an OPC server.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
bool respond(const Bottle &command, Bottle &reply)
std::list< Entity * > EntitiesCache() const
Getter of the list of entities stored locally.
Entity * getEntity(const std::string &name, bool forceUpdate=false)
Gets an entity based on its name, but do no create it if it doesn't exist yet.
An OPC client using the datastructures defined within the icub-client library.
void checkout(bool updateCache=true)
Poll the OPC for all entities and relations and store them locally.
bool configure(ResourceFinder &rf)