diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Verteilte Systeme/Praktikum3 | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Bachelor/Verteilte Systeme/Praktikum3')
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/IPBook.idl | 18 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.cpp | 28 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.h | 22 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/Makefile | 28 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/cabadd_ns.cpp | 66 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/cabcount_ns.cpp | 67 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/cabsearch_ns.cpp | 59 | ||||
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum3/cabsrv_ns.cpp | 72 |
8 files changed, 360 insertions, 0 deletions
diff --git a/Bachelor/Verteilte Systeme/Praktikum3/IPBook.idl b/Bachelor/Verteilte Systeme/Praktikum3/IPBook.idl new file mode 100644 index 0000000..efbc907 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/IPBook.idl @@ -0,0 +1,18 @@ +#ifndef _IPBook_idl +#define _IPBook_idl + +/** + * Interface for a very simple phone book + **/ +interface IPBook { + /* Add an entry */ + void addEntry( in string name, in string number); + + /* Search for an entry */ + string searchEntry( in string name); + + /* Count all entries */ + long count( ); +}; + +#endif diff --git a/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.cpp b/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.cpp new file mode 100644 index 0000000..44e57b8 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.cpp @@ -0,0 +1,28 @@ +#include <CORBA.h> +#include "IPBook_impl.h" + +void IPBook_impl::addEntry( const char* name, const char* number) +{ + string nam = name; + string num = number; + + _numbers[nam] = num; +} + +char* IPBook_impl::searchEntry( const char* name ) +{ + map <string, string, less<string> >::iterator r; + r = _numbers.find(name); + if (r != _numbers.end()) { + return CORBA::string_dup( (*r).second.c_str()); + } + else { + return CORBA::string_dup( "NOT FOUND"); + } +} + +CORBA::Long IPBook_impl::count() +{ + + return _numbers.size(); +} diff --git a/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.h b/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.h new file mode 100644 index 0000000..a42daea --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/IPBook_impl.h @@ -0,0 +1,22 @@ +#ifndef IPBook_impl_h +#define IPBook_impl_h 1 + +#include "IPBook.h" + +#include <map> +#include <string> +using namespace std; + +class IPBook_impl : virtual public POA_IPBook +{ +public: + // implement pure virtual functions from POA_IPBook + virtual void addEntry( const char* name, const char* number ); + virtual char* searchEntry( const char* name ); + virtual CORBA::Long count( ); + +private: + map <string, string, less<string> > _numbers; +}; + +#endif diff --git a/Bachelor/Verteilte Systeme/Praktikum3/Makefile b/Bachelor/Verteilte Systeme/Praktikum3/Makefile new file mode 100644 index 0000000..ed838a1 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/Makefile @@ -0,0 +1,28 @@ +#MICOVERSION=2.3.12 +MICOVERSION=2.3.11 +CXX=mico-c++ -w + +all: cabsrv_ns cabadd_ns cabsearch_ns cabcount_ns + +cabsrv_ns: IPBook.h IPBook.o IPBook_impl.o cabsrv_ns.o + mico-ld -o $@ $@.o IPBook.o IPBook_impl.o -lmico$(MICOVERSION) -lmicocoss$(MICOVERSION) + +cabadd_ns: IPBook.h IPBook.o cabadd_ns.o + mico-ld -o $@ $@.o IPBook.o -lmico$(MICOVERSION) -lmicocoss$(MICOVERSION) + +cabsearch_ns: IPBook.h IPBook.o cabsearch_ns.o + mico-ld -o $@ $@.o IPBook.o -lmico$(MICOVERSION) -lmicocoss$(MICOVERSION) + +cabcount_ns: IPBook.h IPBook.o cabcount_ns.o + mico-ld -o $@ $@.o IPBook.o -lmico$(MICOVERSION) -lmicocoss$(MICOVERSION) + +IPBook.h IPBook.cpp: IPBook.idl +# idl --poa --c++-suffix cpp --use-quotes $< + idl --poa --c++-suffix cpp $< + +clean: + rm -f IPBook.cpp IPBook.h *.o core *~ + +distclean: clean + rm -f cabsrv_ns cabadd_ns cabsearch_ns cabcount_ns + rm -f IPBook.ref diff --git a/Bachelor/Verteilte Systeme/Praktikum3/cabadd_ns.cpp b/Bachelor/Verteilte Systeme/Praktikum3/cabadd_ns.cpp new file mode 100644 index 0000000..8cbc0c3 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/cabadd_ns.cpp @@ -0,0 +1,66 @@ +#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]); + } + 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; +} 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; +} diff --git a/Bachelor/Verteilte Systeme/Praktikum3/cabsearch_ns.cpp b/Bachelor/Verteilte Systeme/Praktikum3/cabsearch_ns.cpp new file mode 100644 index 0000000..f1f1fa3 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum3/cabsearch_ns.cpp @@ -0,0 +1,59 @@ +#include <CORBA.h> +#include <coss/CosNaming.h> +#include "IPBook.h" + +#include <iostream> +using namespace std; + +int main( int argc, char **argv) +{ + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv); + + int rc = 0; + if (argc != 2) { + cerr << "usage: " << argv[0] << " name\n"; + exit(1); + } + + try { + CORBA::Object_var nsobj = + orb->resolve_initial_references ("NameService"); + if (CORBA::is_nil( nsobj)) { + cerr << "can't resolve NameService\n"; + exit(1); + } + CosNaming::NamingContext_var nc = + CosNaming::NamingContext::_narrow (nsobj); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("AddressBook"); + name[0].kind = CORBA::string_dup (""); + + CORBA::Object_var obj = nc->resolve( name); + + IPBook_var f = IPBook::_narrow( obj); + + cout << f->searchEntry( argv[1]) << 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; +} 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; +} |
