Orocos Real-Time Toolkit  2.8.3
ServiceRequesterI.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 ServiceRequesterI.cpp
3 
4  ServiceRequesterI.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 // -*- C++ -*-
40 //
41 // $Id$
42 
43 // **** Code generated by the The ACE ORB (TAO) IDL Compiler ****
44 // TAO and the TAO IDL Compiler have been developed by:
45 // Center for Distributed Object Computing
46 // Washington University
47 // St. Louis, MO
48 // USA
49 // http://www.cs.wustl.edu/~schmidt/doc-center.html
50 // and
51 // Distributed Object Computing Laboratory
52 // University of California at Irvine
53 // Irvine, CA
54 // USA
55 // http://doc.ece.uci.edu/
56 // and
57 // Institute for Software Integrated Systems
58 // Vanderbilt University
59 // Nashville, TN
60 // USA
61 // http://www.isis.vanderbilt.edu/
62 //
63 // Information about TAO is available at:
64 // http://www.cs.wustl.edu/~schmidt/TAO.html
65 
66 // TAO_IDL - Generated from
67 // ../../../ACE_wrappers/TAO/TAO_IDL/be/be_codegen.cpp:1196
68 
69 #include "ServiceRequesterI.h"
71 #include "TaskContext.hpp"
72 
73 using namespace RTT;
74 using namespace RTT::detail;
75 
76 // Implementation skeleton constructor
78  : mservice(service), mpoa( PortableServer::POA::_duplicate(poa) )
79 {
80 }
81 
82 // Implementation skeleton destructor
84 {
85 }
86 
88  void)
89 {
90  return CORBA::string_dup( mservice->getRequestName().c_str() );
91 }
92 
94  void)
95 {
96  ServiceRequester::RequesterNames names = mservice->getRequesterNames();
97  ::RTT::corba::CRequestNames_var result = new ::RTT::corba::CRequestNames();
98  result->length( names.size() );
99  for (unsigned int i=0; i != names.size(); ++i )
100  result[i] = CORBA::string_dup( names[i].c_str() );
101 
102  return result._retn();
103 }
104 
106  void)
107 {
108  ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
109  ::RTT::corba::COperationCallerNames_var result = new ::RTT::corba::COperationCallerNames();
110  result->length( names.size() );
111  for (unsigned int i=0; i != names.size(); ++i )
112  result[i] = CORBA::string_dup( names[i].c_str() );
113 
114  return result._retn();
115 }
116 
117 ::RTT::corba::CServiceRequester_ptr RTT_corba_CServiceRequester_i::getRequest (
118  const char * service_name)
119 {
120  std::string svc(service_name);
121  if ( svc == "this" )
122  return _this();
123 
124  if ( mservice->requiresService(service_name) == false )
125  return RTT::corba::CServiceRequester::_nil();
126 
127  // Creates service requester
128  if ( mrequests.find(svc) == mrequests.end() ) {
129  log(Debug) << "Creating CServiceRequester for "<< service_name <<endlog();
131  mserv = new RTT_corba_CServiceRequester_i( mservice->requires(service_name), mpoa );
132  CServiceRequester_ptr request = mserv->activate_this();
133  mrequests[svc] = std::pair<RTT::corba::CServiceRequester_var, PortableServer::ServantBase_var>(request,mserv);
134  }
135  // Now return it.
136  return RTT::corba::CServiceRequester::_duplicate( mrequests[svc].first.in() );
137 }
138 
140  const char * name)
141 {
142  return mservice->requiresService( name );
143 }
144 
146  ::RTT::corba::CService_ptr svc)
147 {
148  ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
149 
150  for (unsigned int i=0; i != names.size(); ++i )
151  connectCallerTo( names[i].c_str(), svc);
152 
153  return mservice->ready();;
154 }
155 
157  const char * name,
158  ::RTT::corba::CService_ptr svc)
159 {
160  std::string oname(name);
161  if ( mservice->getOperationCaller(oname) == 0) {
162  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
163  return false;
164  }
165  try {
166  (void) svc->getArity(oname.c_str());
167  } catch( ::RTT::corba::CNoSuchNameException& ) {
168  CORBA::String_var svcname = svc->getName();
169  log(Error) << "No such Operation: " << oname << " in "<< svcname.in() << endlog();
170  return false;
171  }
172 
173  // creates a local factory for this remote method.
174  OperationInterfacePart* tmp = new CorbaOperationCallerFactory(oname,svc, mpoa.in() );
175  return mservice->getOperationCaller(oname)->setImplementationPart( tmp, mservice->getServiceOwner()->engine() );
176 }
177 
179  const char * name )
180 {
181  std::string oname(name);
182  if ( mservice->getOperationCaller(oname) == 0) {
183  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
184  return false;
185  }
186  // disconnects.
187  mservice->getOperationCaller(oname)->disconnect();
188  return true;
189 }
190 
192  const char * name )
193 {
194  std::string oname(name);
195  if ( mservice->getOperationCaller(oname) == 0) {
196  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
197  return false;
198  }
199  // disconnects.
200  return mservice->getOperationCaller(oname)->ready();
201 }
202 
204  void)
205 {
206  return mservice->ready();
207 }
208 
210  void)
211 {
212  mservice->disconnect();
213 }
214 
215 
sequence< string > COperationCallerNames
Is thrown when an operation does not exist.
std::vector< std::string > RequesterNames
PortableServer::POA_var mpoa
virtual ::RTT::corba::CServiceRequester_ptr getRequest(const char *name)
virtual ::CORBA::Boolean ready(void)
RTT::ServiceRequester::shared_ptr mservice
boost::shared_ptr< ServiceRequester > shared_ptr
A local factory for creating remote Corba methods.
virtual ::CORBA::Boolean connectCallerTo(const char *name,::RTT::corba::CService_ptr svc)
Convenient short notation for every sub-namespace of RTT.
virtual ::CORBA::Boolean callerReady(const char *name)
virtual ::CORBA::Boolean hasRequest(const char *name)
virtual ::RTT::corba::COperationCallerNames * getOperationCallerNames(void)
sequence< string > CRequestNames
virtual char * getRequestName(void)
This class defines the interface for creating operation objects without using C++ templates...
virtual ::CORBA::Boolean disconnectCaller(const char *name)
virtual RTT::corba::CServiceRequester_ptr activate_this()
std::map< std::string, std::pair< RTT::corba::CServiceRequester_var, PortableServer::ServantBase_var > > mrequests
virtual ::RTT::corba::CRequestNames * getRequestNames(void)
virtual ::CORBA::Boolean connectTo(::RTT::corba::CService_ptr svc)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
RTT_corba_CServiceRequester_i(RTT::ServiceRequester::shared_ptr service, PortableServer::POA_ptr poa)
std::vector< std::string > OperationCallerNames