Orocos Real-Time Toolkit  2.8.3
TaskContextI.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 TaskContextI.cpp
3 
4  TaskContextI.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 "TaskContextI.h"
70 #include "TaskContextServer.hpp"
71 #include "TaskContextProxy.hpp"
72 #include "ServiceI.h"
73 #include "ServiceRequesterI.h"
74 #include "DataFlowI.h"
75 #include "../../OperationCaller.hpp"
76 #include "../../rtt-detail-fwd.hpp"
77 
78 
79 using namespace RTT;
80 using namespace RTT::detail;
81 using namespace RTT::corba;
82 
83 // Implementation skeleton constructor
85  : mpoa( PortableServer::POA::_duplicate(the_poa) )
86  , mtask( orig ), mRequest_i(0), mService_i(0)
87 {
88  // Add the corba object to the interface:
89  mtask->addOperation("shutdown", &RTT_corba_CTaskContext_i::shutdownCORBA, this).doc("Shutdown CORBA ORB. This function makes RunOrb() return.");
90 }
91 
92 // Implementation skeleton destructor
94 {
95  //CDataFlowInterface_i::deregisterServant(mtask->ports()); causes invalid read (freed already)
96 }
97 
99  TaskContextServer::ShutdownOrb(false);
100 }
101 
103  void)
104 {
105  return CORBA::string_dup( mtask->getName().c_str() );
106 }
107 
109  void)
110 {
111  return CORBA::string_dup( mtask->provides()->doc().c_str() );
112 }
113 
115  void)
116 {
118 }
119 
121  void)
122 {
123  return mtask->configure();
124 }
125 
127  void)
128 {
129  return mtask->start();
130 }
131 
133  void)
134 {
135  return mtask->activate();
136 }
137 
139  void)
140 {
141  return mtask->stop();
142 }
143 
145  void)
146 {
147  return mtask->recover();
148 }
149 
151  void)
152 {
153  return mtask->cleanup();
154 }
155 
157  void)
158 {
160  return mtask->recover();
161  return false;
162 }
163 
165  void)
166 {
167  return mtask->isActive();
168 }
169 
171  void)
172 {
173  return mtask->isRunning();
174 }
175 
177  void)
178 {
179  return mtask->isConfigured();
180 }
181 
183  void)
184 {
185  return mtask->inFatalError();
186 }
187 
189  void)
190 {
191  return mtask->inRunTimeError();
192 }
193 
195  void)
196 {
197  return mtask->inException();
198 }
199 
200 ::RTT::corba::CDataFlowInterface_ptr RTT_corba_CTaskContext_i::ports (
201  void)
202 {
203  return getProvider("this");
204 }
205 
206 ::RTT::corba::CService_ptr RTT_corba_CTaskContext_i::getProvider (
207  const char * service_name)
208 {
209  if ( mtask->provides()->hasService(service_name) == false)
210  return CService::_nil();
211  // Creates Service for "this"
212  if ( CORBA::is_nil( mService ) ) {
213  log(Debug) << "Creating CService for "<< mtask->getName()<<endlog();
214  RTT_corba_CService_i* mserv;
215  mService_i = mserv = new RTT_corba_CService_i( mtask->provides(), mpoa );
216  mService = mserv->activate_this();
217  CDataFlowInterface_i::registerServant(CDataFlowInterface::_narrow(mService), mserv);
218  }
219  // Now the this service is available, check for the service name:
220  std::string svc(service_name);
221  if ( svc == "this" )
222  return ::RTT::corba::CService::_duplicate( mService.in() );
223  return mService->getService( service_name );
224 }
225 
226 ::RTT::corba::CServiceRequester_ptr RTT_corba_CTaskContext_i::getRequester (
227  const char * service_name)
228 {
229  std::string svc(service_name);
230  if ( mtask->requires()->requiresService(service_name) == false && svc != "this")
231  return CServiceRequester::_nil();
232  // Creates service requester for "this"
233  if ( CORBA::is_nil( mRequest ) ) {
234  log(Debug) << "Creating CServiceRequester for "<< mtask->getName()<<endlog();
237  mRequest = mserv->activate_this();
238  //CServiceRequester_i::registerServant(mRequest, mtask->requires());
239  }
240  // Now the this service is available, check for the service name:
241  if ( svc == "this" )
242  return ::RTT::corba::CServiceRequester::_duplicate( mRequest.in() );
243  return mRequest->getRequest( service_name );
244 }
245 
247  void)
248 {
250  ::RTT::corba::CTaskContext::CPeerNames_var result = new ::RTT::corba::CTaskContext::CPeerNames();
251  result->length( peers.size() );
252  for (unsigned int i=0; i != peers.size(); ++i )
253  result[i] = CORBA::string_dup( peers[i].c_str() );
254 
255  return result._retn();
256 }
257 
258 ::RTT::corba::CTaskContext_ptr RTT_corba_CTaskContext_i::getPeer (
259  const char * name)
260 {
261  std::string pname(name);
262  TaskContext* task = mtask->getPeer( pname );
263  if ( task ) {
264  // create or lookup new server for this peer.
265  // do not export it to the naming service.
266  return TaskContextServer::CreateServer( task, false );
267  }
268  return RTT::corba::CTaskContext::_nil();
269 }
270 
272  const char * name)
273 {
274  std::string mname(name);
275  return mtask->hasPeer(mname);
276 }
277 
279  ::RTT::corba::CTaskContext_ptr p,
280  const char * alias)
281 {
282  std::string malias(alias);
283  if (mtask->hasPeer(alias) == false )
284  return mtask->addPeer( TaskContextProxy::Create(p), alias );
285  return false;
286 }
287 
289  const char * name)
290 {
291  std::string mname(name);
292  mtask->removePeer( mname );
293  return true;
294 }
295 
297  ::RTT::corba::CTaskContext_ptr p)
298 {
299  TaskContext* t = TaskContextProxy::Create( p );
300  return mtask->connectPeers( t );
301 }
302 
304  const char * name)
305 {
306  std::string pname(name);
307  mtask->disconnectPeers( pname );
308  return true;
309 }
310 
312  ::RTT::corba::CTaskContext_ptr p)
313 {
314  TaskContext* t = TaskContextProxy::Create( p );
315  return mtask->connectPorts( t );
316 }
317 
319  ::RTT::corba::CTaskContext_ptr p)
320 {
321  TaskContext* t = TaskContextProxy::Create( p );
322  return mtask->connectServices( t );
323 }
324 
325 
virtual ::CORBA::Boolean cleanup(void)
virtual ::CORBA::Boolean removePeer(const char *name)
The state indicating the component encountered a C++ exception.
Definition: TaskCore.hpp:103
virtual ::CORBA::Boolean start(void)
Service::shared_ptr provides()
Returns this Service.
virtual ~RTT_corba_CTaskContext_i(void)
virtual ::CORBA::Boolean inFatalError(void)
virtual ::CORBA::Boolean inRunTimeError(void)
virtual bool stop()
This method stops the execution of updateHook() of this component.
PortableServer::ServantBase_var mRequest_i
Definition: TaskContextI.h:98
virtual bool recover()
Call this method in a RunTimeError or Exception state to indicate that the run-time error conditions ...
Definition: TaskCore.cpp:190
virtual char * getDescription(void)
virtual ::RTT::corba::CServiceRequester_ptr getRequester(const char *service_name)
virtual ::CORBA::Boolean isConfigured(void)
virtual bool connectPeers(TaskContext *peer)
Add a two-way connection from this task to a peer task.
virtual char * getName(void)
virtual void removePeer(const std::string &name)
Remove a one-way connection from this task to a peer task.
virtual ::CORBA::Boolean inException(void)
PortableServer::POA_var mpoa
Definition: TaskContextI.h:92
RTT::corba::CServiceRequester_var mRequest
Definition: TaskContextI.h:96
virtual bool isConfigured() const
Inspect if the component is configured, i.e.
Definition: TaskCore.cpp:270
virtual bool activate()
This method starts the ExecutionEngine of this component in case it was not running.
Definition: TaskCore.cpp:258
virtual ::CORBA::Boolean stop(void)
virtual bool isRunning() const
Inspect if the component is in the Running or RunTimeError state.
Definition: TaskCore.cpp:266
virtual bool configure()
This method instructs the component to (re-)read configuration data and try to enter the Stopped stat...
Definition: TaskCore.cpp:104
virtual TaskContext * getPeer(const std::string &peer_name) const
Get a pointer to a peer of this task.
virtual ::CORBA::Boolean recover(void)
virtual bool inException() const
Inspect if the component is in the Exception state.
Definition: TaskCore.cpp:278
virtual bool hasPeer(const std::string &peer_name) const
Return true if it knows a peer by that name.
sequence< string > CPeerNames
Definition: TaskContext.idl:35
virtual ::RTT::corba::CTaskState getTaskState(void)
ServiceRequester::shared_ptr requires()
Returns the object that manages which methods this Task requires to be implemented by another task...
virtual ::CORBA::Boolean disconnectPeers(const char *name)
virtual ::CORBA::Boolean addPeer(::RTT::corba::CTaskContext_ptr p, const char *alias)
Convenient short notation for every sub-namespace of RTT.
PortableServer::ServantBase_var mService_i
Definition: TaskContextI.h:99
virtual ::CORBA::Boolean connectServices(::RTT::corba::CTaskContext_ptr p)
virtual bool inFatalError() const
Inspect if the component is in the FatalError state.
Definition: TaskCore.cpp:274
virtual ::RTT::corba::CDataFlowInterface_ptr ports(void)
virtual PeerList getPeerList() const
Return a standard container which contains all the Peer names of this TaskContext.
std::vector< std::string > PeerList
A list of Peer TaskContext names.
virtual ::CORBA::Boolean activate(void)
virtual void disconnectPeers(const std::string &name)
Remove a two-way connection from this task to a peer task.
RTT_corba_CTaskContext_i(RTT::TaskContext *orig, PortableServer::POA_ptr the_poa)
virtual TaskState getTaskState() const
Returns the current state of the TaskCore.
Definition: TaskCore.cpp:82
virtual bool isActive() const
Inspect if the component&#39;s ExecutionEngine is processing requests.
Definition: TaskCore.cpp:286
virtual bool inRunTimeError() const
Inspect if the component is in the RunTimeError state.
Definition: TaskCore.cpp:282
virtual RTT::corba::CServiceRequester_ptr activate_this()
virtual ::RTT::corba::CTaskContext::CPeerNames * getPeerList(void)
CORBA (OmniORB/TAO) code for network data transport.
virtual ::RTT::corba::CTaskContext_ptr getPeer(const char *name)
virtual RTT::corba::CService_ptr activate_this()
Definition: ServiceI.h:107
virtual ::CORBA::Boolean connectPeers(::RTT::corba::CTaskContext_ptr p)
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
virtual ::CORBA::Boolean connectPorts(::RTT::corba::CTaskContext_ptr p)
virtual bool connectPorts(TaskContext *peer)
Add a data flow connection from this task&#39;s ports to a peer&#39;s ports.
RTT::TaskContext * mtask
Definition: TaskContextI.h:93
virtual bool connectServices(TaskContext *peer)
Connects all requires/provides services of this component to these of a peer.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
virtual ::RTT::corba::CService_ptr getProvider(const char *service_name)
virtual ::CORBA::Boolean resetException(void)
virtual ::CORBA::Boolean isRunning(void)
Operation< Signature > & addOperation(Operation< Signature > &op)
Add an operation object to the interface.
virtual ::CORBA::Boolean configure(void)
CTaskState
Maps 1-to-1 to RTT::base::TaskCore::TaskState.
Definition: TaskContext.idl:26
virtual ::CORBA::Boolean isActive(void)
RTT::corba::CService_var mService
Definition: TaskContextI.h:95
virtual bool start()
This method starts the execution of the updateHook() with each trigger or period. ...
virtual bool addPeer(TaskContext *peer, std::string alias="")
Add a one-way connection from this task to a peer task.
virtual ::CORBA::Boolean hasPeer(const char *name)
virtual bool cleanup()
This method instructs a stopped component to enter the pre-operational state again.
Definition: TaskCore.cpp:136
virtual const std::string & getName() const
Returns the name of this TaskContext.