diff options
| author | Manuel Traut <manut@mecka.net> | 2012-06-03 13:53:44 +0200 |
|---|---|---|
| committer | Manuel Traut <manut@mecka.net> | 2012-06-03 13:53:44 +0200 |
| commit | 0f322594c1a54f5058c77173a4eef04f73bc7a29 (patch) | |
| tree | f3f9e90f935455f34fb033d2a454fadbf8a740c0 /common/common.cpp | |
| parent | 9846551e704f5998cd8f62a95b044e2ae8208579 (diff) | |
libdistrio_common: add corba helper functions
- to initialize orb
- to register new digital objects at the naming service
- to run the orb
Signed-off-by: Manuel Traut <manut@mecka.net>
Diffstat (limited to 'common/common.cpp')
| -rw-r--r-- | common/common.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/common/common.cpp b/common/common.cpp new file mode 100644 index 0000000..b8c4453 --- /dev/null +++ b/common/common.cpp @@ -0,0 +1,87 @@ +/** + * @author Manuel Traut <manut@mecka.net> + * @licence GPLv2 + */ + +#include <iostream> + +#include "common.h" + +int init_corba (int argc, char **argv) +{ + int ret = 0; + CORBA::Object_var obj, root_poa, naming_service; + + try { + ref.orb = CORBA::ORB_init (argc, argv); + root_poa = ref.orb->resolve_initial_references ("RootPOA"); + ref.poa = PortableServer::POA::_narrow (root_poa.in ()); + + naming_service = ref.orb->resolve_initial_references ("NameService"); + if (CORBA::is_nil (naming_service)) { + std::cerr << "can't resolve NameService" << std::endl; + ret = -EINVAL; + goto out; + } + ref.nc = CosNaming::NamingContext::_narrow (naming_service.in ()); + if (CORBA::is_nil (ref.nc)) { + std::cerr << "resolved invalid NameService object" << std::endl; + ret = -EINVAL; + goto out; + } + } catch (CORBA::Exception &e) { + std::cerr << "CORBA initialization failed: " << e << std::endl; + ret = -EINVAL; + goto out; + } + +out: + return ret; +} + +int register_digital (char *_name, Distrio_Digital_i *digital) +{ + CosNaming::Name name; + CORBA::Object_var obj; + PortableServer::ObjectId_var oid; + + if (!ref.init) { + std::cerr << "corba not initialized" << std::endl; + return -1; + } + + try { + oid = ref.poa->activate_object (digital); + obj = digital->_this (); + + /* TODO: find out how to build a tree @ the nameservice "distrio/manager" */ + name.length (1); + name[0].id = CORBA::string_dup (_name); + ref.nc->rebind (name, obj.in ()); + } catch (CORBA::Exception &e) { + std::cerr << "CORBA initialization failed: " << e << std::endl; + return -1; + } + + return 0; +} + +int run_orb () +{ + if (!ref.init) { + std::cerr << "corba not initialized" << std::endl; + return -1; + } + + try { + ref.poa_mgr = ref.poa->the_POAManager (); + ref.poa_mgr->activate (); + ref.orb->run (); + ref.orb->destroy (); + } catch (CORBA::Exception &e) { + std::cerr << "CORBA initialization failed: " << e << std::endl; + return -1; + } + + return 0; +} |
