ApplicationServer.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 26 13:25:59 CEST 2006  ApplicationServer.cxx
00003 
00004                         ApplicationServer.cxx -  description
00005                            -------------------
00006     begin                : Mon June 26 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #include "ApplicationServer.hpp"
00040 #include "../../Logger.hpp"
00041 
00042 #if defined( CORBA_IS_TAO ) && defined( CORBA_TAO_HAS_MESSAGING )
00043 #include <tao/TimeBaseC.h>
00044 #include <tao/Messaging/Messaging.h>
00045 #endif
00046 
00047 namespace RTT
00048 {namespace corba
00049 {
00050 
00051     CORBA::ORB_var ApplicationServer::orb;
00052 
00053     PortableServer::POA_var ApplicationServer::rootPOA;
00054 
00055     RTT_CORBA_API bool ApplicationServer::InitOrb(int argc, char* argv[], Seconds timeout ) {
00056         if ( !CORBA::is_nil(orb) )
00057             return false;
00058 
00059         try {
00060             // First initialize the ORB, that will remove some arguments...
00061             orb =
00062                 CORBA::ORB_init (argc, const_cast<char**>(argv),
00063                                  "omniORB4");
00064             if(timeout >= 0.1e-7)
00065             {
00066 #if defined( CORBA_IS_TAO ) && defined( CORBA_TAO_HAS_MESSAGING )
00067                 // Set the timeout value as a TimeBase::TimeT (100 nanosecond units)
00068                 // and insert it into a CORBA::Any.
00069                 TimeBase::TimeT relative_rt_timeout = timeout * 1.0e7;
00070                 CORBA::Any relative_rt_timeout_as_any;
00071                 relative_rt_timeout_as_any <<= relative_rt_timeout;
00072 
00073                 // Create the policy and put it in a policy list.
00074                 CORBA::PolicyList policies;
00075                 policies.length(1);
00076                 policies[0] = 
00077                 orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
00078                                     relative_rt_timeout_as_any);
00079 
00080                 // Apply the policy at the ORB level using the ORBPolicyManager.
00081                 CORBA::Object_var obj = orb->resolve_initial_references ("ORBPolicyManager");
00082                 CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow (obj.in());
00083                 policy_manager->set_policy_overrides (policies, CORBA::SET_OVERRIDE);
00084 #else
00085                 log(Error) << "Ignoring ORB timeout setting in non-TAO/Messaging build." <<endlog();
00086 #endif // CORBA_IS_TAO
00087             }
00088             // Also activate the POA Manager, since we may get call-backs !
00089             CORBA::Object_var poa_object =
00090                 orb->resolve_initial_references ("RootPOA");
00091             rootPOA =
00092                 PortableServer::POA::_narrow (poa_object.in ());
00093             PortableServer::POAManager_var poa_manager =
00094                 rootPOA->the_POAManager ();
00095             poa_manager->activate ();
00096 
00097             return true;
00098         }
00099         catch (CORBA::Exception &e) {
00100             log(Error) << "Orb Init : CORBA exception raised!" << Logger::nl;
00101             Logger::log() << CORBA_EXCEPTION_INFO(e) << endlog();
00102         }
00103         return false;
00104     }
00105 
00106 }}


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:33