Orocos Real-Time Toolkit  2.9.0
ServiceI.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 ServiceI.cpp
3 
4  ServiceI.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 "ServiceI.h"
70 #include "CorbaLib.hpp"
71 
72 using namespace RTT;
73 using namespace RTT::detail;
74 
75 // Implementation skeleton constructor
77  : RTT_corba_CConfigurationInterface_i( service.get(), PortableServer::POA::_duplicate( poa) ),
78  RTT_corba_COperationInterface_i( service.get(), PortableServer::POA::_duplicate( poa) ),
79  RTT::corba::CDataFlowInterface_i( service.get(), PortableServer::POA::_duplicate( poa) ),
80  mpoa(poa), mservice(service)
81 {
82 }
83 
84 // Implementation skeleton destructor
86 {
87 }
88 
89 PortableServer::POA_ptr RTT_corba_CService_i::_default_POA()
90 {
91  return PortableServer::POA::_duplicate(mpoa);
92 }
93 
95  void)
96 {
97  return CORBA::string_dup( mservice.lock()->getName().c_str() );
98 }
99 
101  void)
102 {
103  return CORBA::string_dup( mservice.lock()->doc().c_str() );
104 }
105 
107  void)
108 {
109  Service::ProviderNames names = mservice.lock()->getProviderNames();
110  ::RTT::corba::CService::CProviderNames_var result = new ::RTT::corba::CService::CProviderNames();
111  result->length( names.size() );
112  for (unsigned int i=0; i != names.size(); ++i )
113  result[i] = CORBA::string_dup( names[i].c_str() );
114 
115  return result._retn();
116 }
117 
118 ::RTT::corba::CService_ptr RTT_corba_CService_i::getService (
119  const char * service_name)
120 {
121  std::string svc(service_name);
122  if ( svc == "this" )
123  return _this();
124 
125  Service::shared_ptr provider = mservice.lock()->getService(svc);
126  if ( !provider )
127  return RTT::corba::CService::_nil();
128 
129  // Creates service requester
130  if ( mservs.find(svc) == mservs.end() ) {
131  log(Debug) << "Creating CService for "<< service_name <<endlog();
132 
133  RTT_corba_CService_i* serv_i;
134  RTT::corba::CService_ptr serv;
135  serv_i = new RTT_corba_CService_i( provider, mpoa );
136  serv = serv_i->activate_this();
137  mservs[svc] = std::pair<RTT::corba::CService_var,PortableServer::ServantBase_var>(serv, serv_i);
138  }
139  // Now return it.
140  return RTT::corba::CService::_duplicate( mservs[svc].first.in() );
141 }
142 
144  const char * name)
145 {
146  return mservice.lock()->hasService( name );
147 }
148 
150  void)
151 {
152  ::RTT::corba::CServiceDescription_var d = new ::RTT::corba::CServiceDescription;
153  unsigned int j = 0;
154 
155  d->name = getName();
156  d->description = getServiceDescription();
157 
158  ::RTT::corba::COperationInterface::COperationDescriptions_var operations = getOperations();
159  d->operations = operations;
160 
161  ::RTT::corba::CDataFlowInterface::CPortDescriptions_var ports = getPortDescriptions();
162  d->ports = ports;
163 
164  ::RTT::corba::CConfigurationInterface::CPropertyNames_var properties = getPropertyList();
165  d->properties = properties;
166 
167  ::RTT::corba::CConfigurationInterface::CAttributeNames_var attributes = getAttributeList();
168  d->attributes = attributes;
169 
170  // Child services
171  Service::ProviderNames providers = mservice.lock()->getProviderNames();
172  d->children.length( providers.size() );
173  d->children_descriptions.length( providers.size() );
174  j = 0;
175  for (unsigned int i=0; i != providers.size(); ++i )
176  {
177  if (providers[i] == "this") continue;
178 
179  // omit PortObject services
180  if (mservice.lock()->getPort(providers[i])) continue;
181 
182  ::RTT::corba::CService_ptr provider = getService(providers[i].c_str());
183  Servants::const_iterator it = mservs.find(providers[i]);
184  if (it != mservs.end()) {
185  RTT_corba_CService_i *child = dynamic_cast<RTT_corba_CService_i *>(it->second.second.in());
186  if (child) {
187  ::RTT::corba::CServiceDescription_var child_description = child->getCServiceDescription();
188  d->children[j] = provider;
189  d->children_descriptions[j] = child_description;
190  j++;
191  }
192  break;
193  }
194  }
195  d->children.length(j); // set real size
196  d->children_descriptions.length(j); // set real size
197 
198  return d._retn();
199 }
virtual ::CORBA::Boolean hasService(const char *name)
Definition: ServiceI.cpp:143
virtual ::RTT::corba::CService_ptr getService(const char *name)
Definition: ServiceI.cpp:118
Complete description of a Service.
Definition: Service.idl:27
virtual char * getName(void)
Definition: ServiceI.cpp:94
virtual ::RTT::corba::CConfigurationInterface::CPropertyNames * getPropertyList(void)
virtual ::RTT::corba::CConfigurationInterface::CAttributeNames * getAttributeList(void)
std::vector< std::string > ProviderNames
Definition: Service.hpp:103
PortableServer::POA_var mpoa
Definition: ServiceI.h:95
virtual ~RTT_corba_CService_i(void)
Definition: ServiceI.cpp:85
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
virtual RTT::corba::COperationInterface::COperationDescriptions * getOperations(void)
PortableServer::POA_ptr _default_POA()
Definition: ServiceI.cpp:89
Convenient short notation for every sub-namespace of RTT.
sequence< string > CProviderNames
Definition: Service.idl:46
RTT_corba_CService_i(RTT::ServicePtr service, PortableServer::POA_ptr poa)
Definition: ServiceI.cpp:76
virtual RTT::corba::CService_ptr activate_this()
Definition: ServiceI.h:107
virtual ::RTT::corba::CService::CProviderNames * getProviderNames(void)
Definition: ServiceI.cpp:106
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
Represents a remote data flow interface.
Definition: DataFlowI.h:111
virtual char * getServiceDescription(void)
Definition: ServiceI.cpp:100
virtual ::RTT::corba::CServiceDescription * getCServiceDescription(void)
Definition: ServiceI.cpp:149
boost::weak_ptr< RTT::Service > mservice
Definition: ServiceI.h:96