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 "ocl/Component.hpp"
00033 #include <fstream>
00034
00035 namespace OCL
00036 {
00037
00042 RTT::TaskContext* createTaskContextProxy(std::string name)
00043 {
00044 log(Debug) << "createTaskContextProxy" <<endlog();
00045 return ::RTT::corba::TaskContextProxy::Create(name, false);
00046 }
00047
00052 RTT::TaskContext* createTaskContextProxyIORFile(std::string iorfilename)
00053 {
00054 log(Debug) << "createTaskContextProxyIORFile" <<endlog();
00055 std::ifstream iorfile( iorfilename.c_str() );
00056 if (iorfile.is_open() && iorfile.good() ) {
00057 std::string ior;
00058 iorfile >> ior;
00059 return ::RTT::corba::TaskContextProxy::Create( ior, true);
00060 }
00061 else {
00062 log(Error) << "Could not open IORFile: '" << iorfilename <<"'."<< endlog();
00063 return 0;
00064 }
00065 }
00066
00071 RTT::TaskContext* createTaskContextProxyIOR(std::string ior)
00072 {
00073 log(Debug) << "createTaskContextProxyIOR" <<endlog();
00074 return ::RTT::corba::TaskContextProxy::Create( ior, true);
00075 }
00076
00077
00078 CorbaDeploymentComponent::CorbaDeploymentComponent(const std::string& name, const std::string& siteFile)
00079 : DeploymentComponent(name, siteFile)
00080 {
00081 log(Info) << "Registering TaskContextProxy factory." <<endlog();
00082 getFactories()["TaskContextProxy"] = &createTaskContextProxy;
00083 getFactories()["CORBA"] = &createTaskContextProxy;
00084 getFactories()["IORFile"] = &createTaskContextProxyIORFile;
00085 getFactories()["IOR"] = &createTaskContextProxyIOR;
00086
00087 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.");
00088 }
00089
00090 CorbaDeploymentComponent::~CorbaDeploymentComponent()
00091 {
00092
00093 ::RTT::corba::TaskContextServer::CleanupServer(this);
00094 }
00095
00096 bool CorbaDeploymentComponent::createServer(const std::string& tc, bool use_naming)
00097 {
00098 RTT::TaskContext* peer = this->getPeer(tc);
00099 if (!peer) {
00100 log(Error)<<"No such peer: "<< tc <<endlog();
00101 return false;
00102 }
00103 if ( ::RTT::corba::TaskContextServer::Create(peer, use_naming) != 0 )
00104 return true;
00105 return false;
00106 }
00107
00108
00109 bool CorbaDeploymentComponent::componentLoaded(RTT::TaskContext* c)
00110 {
00111 if ( dynamic_cast<RTT::corba::TaskContextProxy*>(c) ) {
00112
00113 for ( CompList::iterator cit = comps.begin(); cit != comps.end(); ++cit) {
00114 if (cit->second.instance == c) {
00115 cit->second.proxy = true;
00116 return true;
00117 }
00118 }
00119
00120 assert(false);
00121 return false;
00122 }
00123 bool use_naming = comps[c->getName()].use_naming;
00124 bool server = comps[c->getName()].server;
00125 log(Info) << "Name:"<< c->getName() << " Server: " << server << " Naming: " << use_naming <<endlog();
00126
00127 if (server)
00128 ::RTT::corba::TaskContextServer::Create(c, use_naming);
00129 return true;
00130 }
00131
00132 void CorbaDeploymentComponent::componentUnloaded(TaskContext* c)
00133 {
00134 ::RTT::corba::TaskContextServer::CleanupServer( c );
00135 }
00136 }