Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "CorbaDeploymentComponent.hpp"
00030 #include <rtt/transports/corba/TaskContextProxy.hpp>
00031 #include <rtt/transports/corba/TaskContextServer.hpp>
00032 #include <rtt/deployment/ComponentLoader.hpp>
00033 #include "ocl/Component.hpp"
00034 #include <fstream>
00035
00036 namespace OCL
00037 {
00038
00043 RTT::TaskContext* createTaskContextProxy(std::string name)
00044 {
00045 log(Debug) << "createTaskContextProxy" <<endlog();
00046 return ::RTT::corba::TaskContextProxy::Create(name, false);
00047 }
00048
00053 RTT::TaskContext* createTaskContextProxyIORFile(std::string iorfilename)
00054 {
00055 log(Debug) << "createTaskContextProxyIORFile" <<endlog();
00056 std::ifstream iorfile( iorfilename.c_str() );
00057 if (iorfile.is_open() && iorfile.good() ) {
00058 std::string ior;
00059 iorfile >> ior;
00060 return ::RTT::corba::TaskContextProxy::Create( ior, true);
00061 }
00062 else {
00063 log(Error) << "Could not open IORFile: '" << iorfilename <<"'."<< endlog();
00064 return 0;
00065 }
00066 }
00067
00072 RTT::TaskContext* createTaskContextProxyIOR(std::string ior)
00073 {
00074 log(Debug) << "createTaskContextProxyIOR" <<endlog();
00075 return ::RTT::corba::TaskContextProxy::Create( ior, true);
00076 }
00077
00078
00079 CorbaDeploymentComponent::CorbaDeploymentComponent(const std::string& name, const std::string& siteFile)
00080 : DeploymentComponent(name, siteFile)
00081 {
00082 log(Info) << "Registering TaskContextProxy factory." <<endlog();
00083 ComponentLoader::Instance()->addFactory("TaskContextProxy", &createTaskContextProxy);
00084 ComponentLoader::Instance()->addFactory("CORBA", &createTaskContextProxy);
00085 ComponentLoader::Instance()->addFactory("IORFile", &createTaskContextProxyIORFile);
00086 ComponentLoader::Instance()->addFactory("IOR", &createTaskContextProxyIOR);
00087
00088 this->addOperation("server", &CorbaDeploymentComponent::createServer, this, ClientThread).doc("Creates a CORBA TaskContext server for the given component").arg("tc", "Name of the RTT::TaskContext (must be a peer).").arg("UseNamingService", "Set to true to use the naming service.");
00089 }
00090
00091 CorbaDeploymentComponent::~CorbaDeploymentComponent()
00092 {
00093
00094 ::RTT::corba::TaskContextServer::CleanupServer(this);
00095 }
00096
00097 bool CorbaDeploymentComponent::createServer(const std::string& tc, bool use_naming)
00098 {
00099 RTT::TaskContext* peer = this->getPeer(tc);
00100 if (!peer) {
00101 log(Error)<<"No such peer: "<< tc <<endlog();
00102 return false;
00103 }
00104 if ( ::RTT::corba::TaskContextServer::Create(peer, use_naming) != 0 )
00105 return true;
00106 return false;
00107 }
00108
00109
00110 bool CorbaDeploymentComponent::componentLoaded(RTT::TaskContext* c)
00111 {
00112 if ( dynamic_cast<RTT::corba::TaskContextProxy*>(c) ) {
00113
00114 for ( CompList::iterator cit = comps.begin(); cit != comps.end(); ++cit) {
00115 if (cit->second.instance == c) {
00116 cit->second.proxy = true;
00117 return true;
00118 }
00119 }
00120
00121 assert(false);
00122 return false;
00123 }
00124 bool use_naming = comps[c->getName()].use_naming;
00125 bool server = comps[c->getName()].server;
00126 log(Info) << "Name:"<< c->getName() << " Server: " << server << " Naming: " << use_naming <<endlog();
00127
00128 if (server)
00129 ::RTT::corba::TaskContextServer::Create(c, use_naming);
00130 return true;
00131 }
00132
00133 void CorbaDeploymentComponent::componentUnloaded(TaskContext* c)
00134 {
00135 ::RTT::corba::TaskContextServer::CleanupServer( c );
00136 }
00137 }