summaryrefslogtreecommitdiffstats
path: root/Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp')
-rw-r--r--Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp b/Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp
new file mode 100644
index 0000000..4bd45b0
--- /dev/null
+++ b/Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp
@@ -0,0 +1,67 @@
+#include <CORBA.h>
+#include <coss/CosNaming.h>
+#include "IPBook.h"
+
+#include <iostream>
+using namespace std;
+
+int main( int argc, char **argv)
+{
+ // init ORB
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv);
+
+ int rc = 0;
+ /*if (argc != 3) {
+ cerr << "usage: " << argv[0] << " name number\n";
+ exit(1);
+ }*/
+
+ try {
+ // 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 component
+ CosNaming::Name name;
+ name.length (1);
+ name[0].id = CORBA::string_dup ("AddressBook");
+ name[0].kind = CORBA::string_dup ("");
+
+ // resolve the name component with the naming service
+ CORBA::Object_var obj = nc->resolve( name);
+
+ // narrow this object to IPBook
+ IPBook_var f = IPBook::_narrow( obj);
+
+ // work with IPBook
+ //f->addEntry( argv[1], argv[2]);
+ cout << f->count() << endl;
+ }
+ catch(CORBA::ORB::InvalidName_catch& ex)
+ {
+ ex->_print(cerr);
+ cerr << endl;
+ cerr << "possible cause: can't locate Naming Service\n";
+ rc = 1;
+ }
+ catch(CosNaming::NamingContext::NotFound_catch& ex)
+ {
+ cerr << "Name not found at Naming Service\n";
+ rc = 1;
+ }
+ catch(CORBA::SystemException_catch& ex)
+ {
+ ex->_print(cerr);
+ cerr << endl;
+ rc = 1;
+ }
+
+ return rc;
+}