Orocos Real-Time Toolkit  2.8.3
ApplicationServer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:25:59 CEST 2006 ApplicationServer.cxx
3 
4  ApplicationServer.cxx - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 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 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 #include "ApplicationServer.hpp"
40 #include "../../Logger.hpp"
41 
42 #if defined( CORBA_IS_TAO ) && defined( CORBA_TAO_HAS_MESSAGING )
43 #include <tao/TimeBaseC.h>
44 #include <tao/Messaging/Messaging.h>
45 #endif
46 
47 namespace RTT
48 {namespace corba
49 {
50 
51  CORBA::ORB_var RTT_API ApplicationServer::orb;
52 
53  PortableServer::POA_var ApplicationServer::rootPOA;
54 
55  RTT_CORBA_API bool ApplicationServer::InitOrb(int argc, char* argv[], Seconds timeout ) {
56  if ( !CORBA::is_nil(orb) )
57  return false;
58 
59  try {
60  // First initialize the ORB, that will remove some arguments...
61  orb =
62  CORBA::ORB_init (argc, const_cast<char**>(argv),
63  "omniORB4");
64  if(timeout >= 0.1e-7)
65  {
66 #if defined( CORBA_IS_TAO ) && defined( CORBA_TAO_HAS_MESSAGING )
67  // Set the timeout value as a TimeBase::TimeT (100 nanosecond units)
68  // and insert it into a CORBA::Any.
69  TimeBase::TimeT relative_rt_timeout = timeout * 1.0e7;
70  CORBA::Any relative_rt_timeout_as_any;
71  relative_rt_timeout_as_any <<= relative_rt_timeout;
72 
73  // Create the policy and put it in a policy list.
74  CORBA::PolicyList policies;
75  policies.length(1);
76  policies[0] =
77  orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
78  relative_rt_timeout_as_any);
79 
80  // Apply the policy at the ORB level using the ORBPolicyManager.
81  CORBA::Object_var obj = orb->resolve_initial_references ("ORBPolicyManager");
82  CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow (obj.in());
83  policy_manager->set_policy_overrides (policies, CORBA::SET_OVERRIDE);
84 #else
85  log(Error) << "Ignoring ORB timeout setting in non-TAO/Messaging build." <<endlog();
86 #endif // CORBA_IS_TAO
87  }
88  // Also activate the POA Manager, since we may get call-backs !
89  CORBA::Object_var poa_object =
90  orb->resolve_initial_references ("RootPOA");
91  rootPOA =
92  PortableServer::POA::_narrow (poa_object.in ());
93  PortableServer::POAManager_var poa_manager =
94  rootPOA->the_POAManager ();
95  poa_manager->activate ();
96 
97  return true;
98  }
99  catch (CORBA::Exception &e) {
100  log(Error) << "Orb Init : CORBA exception raised!" << Logger::nl;
101  Logger::log() << CORBA_EXCEPTION_INFO(e) << endlog();
102  }
103  return false;
104  }
105 
106 }}
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
static std::ostream & nl(std::ostream &__os)
Insert a newline &#39; &#39; in the ostream.
Definition: Logger.cpp:373
#define CORBA_EXCEPTION_INFO(x)
Definition: corba.h:70
#define RTT_API
Definition: rtt-config.h:97
static RTT_CORBA_API bool InitOrb(int argc, char *argv[], Seconds orb_timeout=0)
Invoke this method once to initialise the Orb which will run the task servers.
static PortableServer::POA_var rootPOA
The root POA of this process.
static Logger & log()
As Instance(), but more userfriendly.
Definition: Logger.cpp:117
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
static CORBA::ORB_var orb
The orb of this process.