00001
00020 #ifndef RTC_PORTADMIN_H
00021 #define RTC_PORTADMIN_H
00022
00023 #include <rtm/idl/RTCSkel.h>
00024 #include <rtm/PortBase.h>
00025 #include <rtm/ObjectManager.h>
00026 #include <rtm/SystemLogger.h>
00027
00028 namespace RTC
00029 {
00053 class PortAdmin
00054 {
00055 public:
00075 PortAdmin(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00076
00090 virtual ~PortAdmin(void){};
00091
00112 PortServiceList* getPortServiceList() const;
00113
00134 PortProfileList getPortProfileList() const;
00135
00164 PortService_ptr getPortRef(const char* port_name) const;
00165
00194 PortBase* getPort(const char* port_name) const;
00195
00222 bool addPort(PortBase& port);
00249 bool addPort(PortService_ptr port);
00274 void registerPort(PortBase& port);
00299 void registerPort(PortService_ptr port);
00300
00326 bool removePort(PortBase& port);
00352 bool removePort(PortService_ptr port);
00376 void deletePort(PortBase& port);
00400 void deletePort(PortService_ptr port);
00401
00425 void deletePortByName(const char* port_name);
00426
00445 void activatePorts();
00446
00465 void deactivatePorts();
00466
00484 void finalizePorts();
00485
00486 private:
00487
00488 CORBA::ORB_var m_pORB;
00489
00490
00491 PortableServer::POA_var m_pPOA;
00492
00493
00494 PortServiceList m_portRefs;
00495
00496 mutable Logger rtclog;
00497
00498 template <class T>
00499 class comp_op
00500 {
00501 public:
00502 comp_op(const char* _name)
00503 : m_name(_name)
00504 {
00505 }
00506 comp_op(T* obj)
00507 : m_name((const char*)(obj->getProfile().name))
00508 {
00509 }
00510 bool operator()(T* obj)
00511 {
00512 std::string name((const char*)obj->getProfile().name);
00513 return m_name == name;
00514 }
00515 private:
00516 std::string m_name;
00517 };
00518
00519 class port_prof_collect
00520 {
00521 public:
00522 port_prof_collect(PortProfileList& p) : m_p(p) {}
00523 void operator()(const PortBase* port)
00524 {
00525 CORBA_SeqUtil::push_back(m_p, port->getPortProfile());
00526 }
00527 private:
00528 PortProfileList& m_p;
00529 };
00530
00531 class port_prof_collect2
00532 {
00533 public:
00534 port_prof_collect2(PortProfileList& p) : m_p(p) {}
00535 void operator()(const PortService_ptr port)
00536 {
00537 PortProfile* pp(port->get_port_profile());
00538 CORBA_SeqUtil::push_back(m_p, *(pp));
00539 delete pp;
00540 }
00541 private:
00542 PortProfileList& m_p;
00543 };
00544
00545 struct find_port_name;
00546 struct find_port;
00547 struct del_port;
00548
00549
00550 ObjectManager<const char*, PortBase, comp_op<PortBase> > m_portServants;
00551
00552 };
00553 };
00554 #endif // RTC_PORTADMIN_H