CorbaDeploymentComponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 3 15:34:48 CEST 2008 CorbaDeploymentComponent.cpp
3 
4  CorbaDeploymentComponent.cpp - description
5  -------------------
6  begin : Thu July 03 2008
7  copyright : (C) 2008 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 
33 #include "ocl/Component.hpp"
34 #include <fstream>
35 
36 namespace OCL
37 {
38 
44  {
45  log(Debug) << "createTaskContextProxy" <<endlog();
46  return ::RTT::corba::TaskContextProxy::Create(name, false);
47  }
48 
54  {
55  log(Debug) << "createTaskContextProxyIORFile" <<endlog();
56  std::ifstream iorfile( iorfilename.c_str() );
57  if (iorfile.is_open() && iorfile.good() ) {
58  std::string ior;
59  iorfile >> ior;
60  return ::RTT::corba::TaskContextProxy::Create( ior, true);
61  }
62  else {
63  log(Error) << "Could not open IORFile: '" << iorfilename <<"'."<< endlog();
64  return 0;
65  }
66  }
67 
73  {
74  log(Debug) << "createTaskContextProxyIOR" <<endlog();
75  return ::RTT::corba::TaskContextProxy::Create( ior, true);
76  }
77 
78 
79 CorbaDeploymentComponent::CorbaDeploymentComponent(const std::string& name, const std::string& siteFile)
80  : DeploymentComponent(name, siteFile)
81  {
82  log(Info) << "Registering TaskContextProxy factory." <<endlog();
83  ComponentLoader::Instance()->addFactory("TaskContextProxy", &createTaskContextProxy);
84  ComponentLoader::Instance()->addFactory("CORBA", &createTaskContextProxy);
87 
88  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.");
89  this->addOperation("aliasServer", &CorbaDeploymentComponent::createAliasServer, this, ClientThread).doc("Creates a CORBA TaskContext server for the given component using an alias").arg("tc", "Name of the RTT::TaskContext (must be a peer).").arg("alias", "Alias to use when registering to the CORBA Namingservice").arg("UseNamingService", "Set to true to use the naming service.");
90  }
91 
93  {
94  // removes our own server, before removing peer's.
96  }
97 
98  bool CorbaDeploymentComponent::createServer(const std::string& tc, bool use_naming)
99  {
100  RTT::TaskContext* peer = this->getPeer(tc);
101  if (!peer) {
102  log(Error)<<"No such peer: "<< tc <<endlog();
103  return false;
104  }
105  if ( ::RTT::corba::TaskContextServer::Create(peer, use_naming) != 0 )
106  return true;
107  return false;
108  }
109 
110  bool CorbaDeploymentComponent::createAliasServer(const std::string& tc, const std::string& alias, bool use_naming)
111  {
112  RTT::TaskContext* peer = this->getPeer(tc);
113  if (!peer) {
114  log(Error)<<"No such peer: "<< tc <<endlog();
115  return false;
116  }
117  if ( ::RTT::corba::TaskContextServer::Create(peer, alias, use_naming) != 0 )
118  return true;
119  return false;
120  }
121 
123  {
124  if ( dynamic_cast<RTT::corba::TaskContextProxy*>(c) ) {
125  // is a proxy.
126  for ( CompMap::iterator cit = compmap.begin(); cit != compmap.end(); ++cit) {
127  if (cit->second.instance == c) {
128  cit->second.proxy = true;
129  return true;
130  }
131  }
132  // impossible: proxy not found
133  assert(false);
134  return false;
135  }
136  bool use_naming = compmap[c->getName()].use_naming;
137  bool server = compmap[c->getName()].server;
138  log(Info) << "Name:"<< c->getName() << " Server: " << server << " Naming: " << use_naming <<endlog();
139  // create a server, use naming.
140  if (server)
142  return true;
143  }
144 
146  {
148  }
149 }
bool createServer(const std::string &tc, bool use_naming)
bool createAliasServer(const std::string &tc, const std::string &alias, bool use_naming)
virtual bool componentLoaded(RTT::TaskContext *c)
static boost::shared_ptr< ComponentLoader > Instance()
virtual TaskContext * getPeer(const std::string &peer_name) const
virtual void componentUnloaded(RTT::TaskContext *c)
CorbaDeploymentComponent(const std::string &name, const std::string &siteFile="")
static void CleanupServer(TaskContext *tc)
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
RTT::TaskContext * createTaskContextProxyIOR(std::string ior)
Debug
Error
Info
RTT::TaskContext * createTaskContextProxyIORFile(std::string iorfilename)
RTT::TaskContext * createTaskContextProxy(std::string name)
Operation< Signature > & addOperation(Operation< Signature > &op)
ClientThread
virtual const std::string & getName() const


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27