00001
00020 #ifndef CorbaPort_h
00021 #define CorbaPort_h
00022
00023 #include <rtm/PortBase.h>
00024 #include <rtm/CorbaConsumer.h>
00025 #include <rtm/NVUtil.h>
00026
00041 namespace RTC
00042 {
00135 class CorbaPort
00136 : public PortBase
00137 {
00138 public:
00153 CorbaPort(const char* name);
00154
00166 virtual ~CorbaPort();
00167
00202 bool registerProvider(const char* instance_name, const char* type_name,
00203 PortableServer::RefCountServantBase& provider);
00204
00245 bool registerConsumer(const char* instance_name, const char* type_name,
00246 CorbaConsumerBase& consumer);
00247
00248 protected:
00336 virtual ReturnCode_t
00337 publishInterfaces(ConnectorProfile& connector_profile);
00338
00419 virtual ReturnCode_t
00420 subscribeInterfaces(const ConnectorProfile& connector_profile);
00421
00443 virtual void
00444 unsubscribeInterfaces(const ConnectorProfile& connector_profile);
00445
00446 private:
00454 NVList m_providers;
00455
00463 struct Consumer
00464 {
00465 Consumer(const char* _instance_name, const char* _type_name,
00466 CorbaConsumerBase& _cons)
00467 : name(std::string("port.")
00468 + _type_name
00469 + std::string(".")
00470 + _instance_name),
00471 consumer(_cons)
00472 {}
00473 Consumer(const Consumer& cons)
00474 : name(cons.name), consumer(cons.consumer)
00475 {
00476 }
00477 Consumer operator=(const Consumer& _cons)
00478 {
00479 Consumer cons(_cons);
00480 return cons;
00481 }
00482 std::string name;
00483 CorbaConsumerBase& consumer;
00484 };
00485 std::vector<Consumer> m_consumers;
00486
00487
00497 struct subscribe
00498 {
00499 subscribe(std::vector<Consumer>& cons)
00500 : m_cons(cons), m_len(cons.size())
00501 {
00502 }
00503
00504 void operator()(const SDOPackage::NameValue& nv)
00505 {
00506 for (CORBA::ULong i = 0; i < m_len; ++i)
00507 {
00508 std::string name(nv.name);
00509 if (m_cons[i].name == name)
00510 {
00511 CORBA::Object_var obj;
00512 CORBA::Any::to_object to_obj(obj.inout());
00513 if (nv.value >>= to_obj)
00514 {
00515 m_cons[i].consumer.setObject(obj);
00516 }
00517 }
00518 }
00519 }
00520 std::vector<Consumer> m_cons;
00521 CORBA::ULong m_len;
00522 };
00523
00531 struct unsubscribe
00532 {
00533 unsubscribe(std::vector<Consumer>& cons)
00534 : m_cons(cons), m_len(cons.size())
00535 {
00536 }
00537
00538 void operator()(const SDOPackage::NameValue& nv)
00539 {
00540 for (CORBA::ULong i = 0; i < m_len; ++i)
00541 {
00542 std::string name(nv.name);
00543 if (m_cons[i].name == name)
00544 {
00545 m_cons[i].consumer.releaseObject();
00546 }
00547 }
00548 }
00549 std::vector<Consumer> m_cons;
00550 CORBA::ULong m_len;
00551 };
00552 };
00553 };
00554 #endif // CorbaPort_h