From db9dc73fb458638973a458ba76a2d7f159c96c4d Mon Sep 17 00:00:00 2001 From: Manuel Traut Date: Sun, 3 Jun 2012 14:01:02 +0200 Subject: libdistrio_common: rename common -> helper - include 'common.h' in other components sounds bad Signed-off-by: Manuel Traut --- common/Makefile | 2 +- common/common.cpp | 89 ----------------------------------------------- common/common.h | 40 --------------------- common/distrio_helper.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++ common/distrio_helper.h | 40 +++++++++++++++++++++ 5 files changed, 130 insertions(+), 130 deletions(-) delete mode 100644 common/common.cpp delete mode 100644 common/common.h create mode 100644 common/distrio_helper.cpp create mode 100644 common/distrio_helper.h diff --git a/common/Makefile b/common/Makefile index af3963e..44357f5 100644 --- a/common/Makefile +++ b/common/Makefile @@ -13,7 +13,7 @@ DESTDIR := /usr COMPONENT = distrio_common LIB = lib$(COMPONENT).so -OBJ = $(COMPONENT)C.o $(COMPONENT).o $(COMPONENT)S.o common.o +OBJ = $(COMPONENT)C.o $(COMPONENT).o $(COMPONENT)S.o distrio_helper.o IDL_CLEANFILES = $(COMPONENT)C.cpp $(COMPONENT)C.inl $(COMPONENT)I.h \ $(COMPONENT)S.h $(COMPONENT)C.h $(COMPONENT)S.cpp diff --git a/common/common.cpp b/common/common.cpp deleted file mode 100644 index 9fd35e3..0000000 --- a/common/common.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @author Manuel Traut - * @licence GPLv2 - */ - -#include - -#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; - } - - ref.init = 1; - -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; -} diff --git a/common/common.h b/common/common.h deleted file mode 100644 index 8070544..0000000 --- a/common/common.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * CORBA helpers - * - * - init orb - * - get reference to name service - * - register objects @ name service - * - * @author Manuel Traut - * @licence GPLv2 - */ - -#include -#include -#include - -#include - -/** - * handle to corba objects needed for registration of new objects and running - * the ORB - */ -typedef struct _corba_ref { - /** init > 0 if orb is initialized */ - int init; - CORBA::ORB_var orb; - PortableServer::POA_var poa; - PortableServer::POAManager_var poa_mgr; - CosNaming::NamingContext_var nc; -} corba_ref; - -static corba_ref ref = { - .init = 0, -}; - -/** initialize corba orb - argc, argv as passed to main() */ -int init_corba (int argc, char **argv); -/** register a digital io with a common name at the naming service */ -int register_digital (char *_name, Distrio_Digital_i *digital); -/** run the orb - function blocks until orb shutdown */ -int run_orb (void); diff --git a/common/distrio_helper.cpp b/common/distrio_helper.cpp new file mode 100644 index 0000000..5b368e7 --- /dev/null +++ b/common/distrio_helper.cpp @@ -0,0 +1,89 @@ +/** + * @author Manuel Traut + * @licence GPLv2 + */ + +#include + +#include "distrio_helper.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; + } + + ref.init = 1; + +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; +} diff --git a/common/distrio_helper.h b/common/distrio_helper.h new file mode 100644 index 0000000..8070544 --- /dev/null +++ b/common/distrio_helper.h @@ -0,0 +1,40 @@ +/** + * CORBA helpers + * + * - init orb + * - get reference to name service + * - register objects @ name service + * + * @author Manuel Traut + * @licence GPLv2 + */ + +#include +#include +#include + +#include + +/** + * handle to corba objects needed for registration of new objects and running + * the ORB + */ +typedef struct _corba_ref { + /** init > 0 if orb is initialized */ + int init; + CORBA::ORB_var orb; + PortableServer::POA_var poa; + PortableServer::POAManager_var poa_mgr; + CosNaming::NamingContext_var nc; +} corba_ref; + +static corba_ref ref = { + .init = 0, +}; + +/** initialize corba orb - argc, argv as passed to main() */ +int init_corba (int argc, char **argv); +/** register a digital io with a common name at the naming service */ +int register_digital (char *_name, Distrio_Digital_i *digital); +/** run the orb - function blocks until orb shutdown */ +int run_orb (void); -- cgit v1.2.3