summaryrefslogtreecommitdiffstats
path: root/Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp')
-rw-r--r--Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp b/Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp
new file mode 100644
index 0000000..dfb5798
--- /dev/null
+++ b/Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp
@@ -0,0 +1,72 @@
+#include <CORBA.h>
+#include <coss/CosNaming.h>
+
+#include "IPBook_impl.h"
+#include <iostream>
+using namespace std;
+
+int main( int argc, char **argv)
+{
+ int rc = 0;
+
+ try {
+ // init ORB and POA Manager
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv);
+ CORBA::Object_var poaobj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow( poaobj);
+ PortableServer::POAManager_var mgr = poa->the_POAManager();
+
+ // create a new instance of the servant
+ IPBook_impl *impl = new IPBook_impl;
+ // activate the servant
+ IPBook_var f = impl->_this();
+
+ // resolve the naming service
+ CORBA::Object_var nsobj =
+ orb->resolve_initial_references ("NameService");
+ if (CORBA::is_nil( nsobj)) {
+ cerr << "can't resolve NameService\n";
+ exit(1);
+ }
+
+ // narrow the root naming context
+ CosNaming::NamingContext_var nc =
+ CosNaming::NamingContext::_narrow (nsobj);
+
+ // create a name entry
+ CosNaming::Name name;
+ name.length (1);
+ name[0].id = CORBA::string_dup ("AddressBook");
+ name[0].kind = CORBA::string_dup ("");
+
+ // bind or rebind the servant to the naming service
+ try {
+ nc->bind (name, f);
+ }
+ catch (const CosNaming::NamingContext::AlreadyBound_catch &ex) {
+ nc->rebind (name, f);
+ }
+
+ // activate POA manager
+ mgr->activate();
+ // run the ORB
+ orb->run();
+
+ poa->destroy( TRUE, TRUE);
+ delete impl;
+ }
+ catch(CORBA::ORB::InvalidName_catch& ex)
+ {
+ ex->_print(cerr);
+ cerr << endl;
+ cerr << "possible cause: can't locate Naming Service\n";
+ rc = 1;
+ }
+ catch(CORBA::SystemException_catch& ex)
+ {
+ ex->_print(cerr);
+ cerr << endl;
+ rc = 1;
+ }
+ return rc;
+}