diff options
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; +} |
