summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorManuel Traut <manut@mecka.net>2012-06-03 20:12:26 +0200
committerManuel Traut <manut@mecka.net>2012-06-03 20:12:26 +0200
commitf79ee1d59423488c3de89e97e3648515a9143b36 (patch)
tree93e4922283a5d03c1c559f48970317b8f50056f1 /common
parent796c97ef8d5a437fff1edb5679b82db49806e576 (diff)
add simple_dev example
- registers device at the manager - fixup manager to enable device registration - extend distrio_helper to support device registration Signed-off-by: Manuel Traut <manut@mecka.net>
Diffstat (limited to 'common')
-rw-r--r--common/distrio_helper.cpp40
-rw-r--r--common/distrio_helper.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/common/distrio_helper.cpp b/common/distrio_helper.cpp
index 2f49941..aaf43c1 100644
--- a/common/distrio_helper.cpp
+++ b/common/distrio_helper.cpp
@@ -96,6 +96,46 @@ int register_digital (std::string _name, Distrio_Digital_i *digital)
return 0;
}
+int register_device (std::string _name, Distrio_Device_i *dev)
+{
+ CosNaming::Name name;
+ CORBA::Object_var obj, manager_obj;
+ PortableServer::ObjectId_var oid;
+ Distrio::Device_ptr ptr;
+ Distrio::Error *e;
+
+ if (ref.init != ORB_RUNNING) {
+ std::cerr << "corba not initialized" << std::endl;
+ return -1;
+ }
+
+ try {
+ oid = ref.poa->activate_object (dev);
+ obj = dev->_this ();
+ name.length (1);
+ name[0].id = CORBA::string_dup (_name.c_str ());
+ name[0].kind = CORBA::string_dup ("devices");
+ ref.nc->rebind (name, obj.in ());
+ } catch (CORBA::Exception &e) {
+ std::cerr << "CORBA bind digital io at naming service failed: "
+ << e << std::endl;
+ return -1;
+ }
+
+ try {
+ ptr = Distrio::Device::_narrow (obj);
+ e = ref.manager->register_io_device (ptr);
+ std::cout << e->description << std::endl;
+ free (e);
+ } catch (CORBA::Exception &_e) {
+ std::cerr << "CORBA register device at distrio manager failed: "
+ << _e << std::endl;
+ return -1;
+ }
+
+ return 0;
+}
+
pthread_t orb_thread;
void *orb_runner (void *args)
diff --git a/common/distrio_helper.h b/common/distrio_helper.h
index da1e290..e46b42f 100644
--- a/common/distrio_helper.h
+++ b/common/distrio_helper.h
@@ -43,5 +43,7 @@ static corba_ref ref = {
int init_corba (int argc, char **argv);
/** register a digital io with a common name at the naming service */
int register_digital (std::string _name, Distrio_Digital_i *digital);
+/** register a device with a common name at the naming service */
+int register_device (std::string _name, Distrio_Device_i *dev);
/** run the orb - function blocks until orb shutdown */
int run_orb (void);