Orocos Real-Time Toolkit  2.9.0
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  ServiceRequester::shared_ptr requester = mservice->requires(svc);
125 
126  // Creates service requester
127  if ( mrequests.find(svc) == mrequests.end() ) {
128  log(Debug) << "Creating CServiceRequester for "<< service_name <<endlog();
130  mserv = new RTT_corba_CServiceRequester_i( requester, mpoa );
131  CServiceRequester_ptr request = mserv->activate_this();
132  mrequests[svc] = std::pair<RTT::corba::CServiceRequester_var, PortableServer::ServantBase_var>(request,mserv);
133  }
134  // Now return it.
135  return RTT::corba::CServiceRequester::_duplicate( mrequests[svc].first.in() );
136 }
137 
139  const char * name)
140 {
141  return mservice->requiresService( name );
142 }
143 
145  ::RTT::corba::CService_ptr svc)
146 {
147  ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
148 
149  for (unsigned int i=0; i != names.size(); ++i )
150  connectCallerTo( names[i].c_str(), svc);
151 
152  return mservice->ready();;
153 }
154 
156  const char * name,
157  ::RTT::corba::CService_ptr svc)
158 {
159  std::string oname(name);
160  if ( mservice->getOperationCaller(oname) == 0) {
161  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
162  return false;
163  }
164  try {
165  (void) svc->getArity(oname.c_str());
166  } catch( ::RTT::corba::CNoSuchNameException& ) {
167  CORBA::String_var svcname = svc->getName();
168  log(Error) << "No such Operation: " << oname << " in "<< svcname.in() << endlog();
169  return false;
170  }
171 
172  // creates a local factory for this remote method.
173  OperationInterfacePart* tmp = new CorbaOperationCallerFactory(oname, svc, mpoa.in() );
174  return mservice->getOperationCaller(oname)->setImplementationPart( tmp, mservice->getServiceOwner()->engine() );
175 }
176 
178  const char * name )
179 {
180  std::string oname(name);
181  if ( mservice->getOperationCaller(oname) == 0) {
182  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
183  return false;
184  }
185  // disconnects.
186  mservice->getOperationCaller(oname)->disconnect();
187  return true;
188 }
189 
191  const char * name )
192 {
193  std::string oname(name);
194  if ( mservice->getOperationCaller(oname) == 0) {
195  log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
196  return false;
197  }
198  // disconnects.
199  return mservice->getOperationCaller(oname)->ready();
200 }
201 
203  void)
204 {
205  return mservice->ready();
206 }
207 
209  void)
210 {
211  mservice->disconnect();
212 }
213 
215  void)
216 {
217  ::RTT::corba::CServiceRequesterDescription_var d = new ::RTT::corba::CServiceRequesterDescription;
218 
219  d->name = getRequestName();
220 
221  ::RTT::corba::COperationCallerNames_var operationcallernames = getOperationCallerNames();
222  d->operationcallernames = operationcallernames;
223 
224  ServiceRequester::RequesterNames requesters = mservice->getRequesterNames();
225  d->children.length( requesters.size() );
226  d->children_descriptions.length( requesters.size() );
227  unsigned int j = 0;
228  for (unsigned int i=0; i != requesters.size(); ++i )
229  {
230  if (requesters[i] == "this") continue;
231 
232  ::RTT::corba::CServiceRequester_ptr requester = getRequest(requesters[i].c_str());
233  RequestersMap::iterator it = mrequests.find(requesters[i]);
234  if (it != mrequests.end()) {
235  RTT_corba_CServiceRequester_i *child = dynamic_cast<RTT_corba_CServiceRequester_i *>(it->second.second.in());
236  if (child) {
237  ::RTT::corba::CServiceRequesterDescription_var child_description = child->getCServiceRequesterDescription();
238  d->children[j] = requester;
239  d->children_descriptions[j] = child_description;
240  j++;
241  }
242  }
243  }
244  d->children.length(j); // set real size
245  d->children_descriptions.length(j); // set real size
246 
247  return d._retn();
248 }
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::CServiceRequesterDescription * getCServiceRequesterDescription(void)
virtual ::RTT::corba::COperationCallerNames * getOperationCallerNames(void)
Complete description of a ServiceRequester.
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()
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:52
RTT_corba_CServiceRequester_i(RTT::ServiceRequester::shared_ptr service, PortableServer::POA_ptr poa)
std::vector< std::string > OperationCallerNames