130 likes | 214 Views
Служба іменування ( Naming Service ) CORBA. 2004. ( Курс “Інформаційні технології” ). struct NameComponent { Istring id; Istring kind; }; typedef sequence<NameComponent> Name;. NameComponent, Name. interface NamingContext {
E N D
Служба іменування (NamingService) CORBA 2004 (Курс “Інформаційні технології”)
struct NameComponent { Istring id; Istring kind; }; typedef sequence<NameComponent> Name; NameComponent, Name C++Builder CORBA
interface NamingContext { enum NotFoundReason { missing_node, not_context, not_object }; exception NotFound { NotFoundReason why; Name rest_of_name; }; exception CannotProceed { NamingContext cxt; Name rest_of_name; }; exception InvalidName{}; exception AlreadyBound {}; exception NotEmpty{}; Exceptions (interface NamingContext) C++Builder CORBA
void bind(in Name n, in Object obj) raises(NotFound, CannotProceed, InvalidName, AlreadyBound); void rebind(in Name n, in Object obj) raises(NotFound, CannotProceed, InvalidName); void bind_context(in Name n, in NamingContext nc) raises(NotFound, CannotProceed, InvalidName, AlreadyBound); void rebind_context(in Name n, in NamingContext nc) raises(NotFound, CannotProceed, InvalidName); Object resolve (in Name n) raises(NotFound, CannotProceed, InvalidName); void unbind(in Name n) raises(NotFound, CannotProceed, InvalidName); Methods (interface NamingContext) C++Builder CORBA
NamingContext new_context(); NamingContext bind_new_context(in Name n) raises( NotFound, AlreadyBound, CannotProceed, InvalidName ); void destroy() raises(NotEmpty); void list( in unsigned long how_many, out BindingList bl, out BindingIterator bi ); Methods (interface NamingContext)(Прод.) C++Builder CORBA
interface NamingContextExt: NamingContext { typedef string StringName; typedef string Address; typedef string URLString; StringName to_string(in Name n) raises(InvalidName); Name to_name(in StringName sn) raises(InvalidName); exception InvalidAddress {}; URLString to_url(in Address addr, in StringName sn) raises(InvalidAddress, InvalidName); Object resolve_str(in StringName n) raises( NotFound, CannotProceed, InvalidName ); }; Interface NamingContextExt C++Builder CORBA
NamingContext = interface ['{7DFA1D2B-16FD-AFBF-C509-0FFF155A2060}'] procedure bind (const n : Name; const obj : CORBAObject); procedure rebind (const n : Name; const obj : CORBAObject); procedure bind_context (const n : Name; const nc : NamingContext); procedure rebind_context (const n : Name; const nc : NamingContext); function resolve (const n : Name): CORBAObject; procedure unbind (const n : Name); function new_context : NamingContext; function bind_new_context (const n : Name): NamingContext; procedure _destroy; procedure list (const how_many : Cardinal; out bl : BindingList; out bi : BindingIterator); end; Delphi. NamingContext C++Builder CORBA
NamingContextExt = interface (NamingContext) ['{FA41078E-DA19-0D9F-D34A-F5E550D735A2}'] function to_string (const n : Name): NamingContextExt_StringName; function to_name (const sn : NamingContextExt_StringName): Name; function to_url (const addr : NamingContextExt_Address; const sn : NamingContextExt_StringName): NamingContextExt_URLString; function resolve_str (const n : NamingContextExt_StringName): CORBAObject; end; Delphi. NamingContextExt C++Builder CORBA
// Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // get a reference to the root POA PortableServer::POA_var rootPOA = PortableServer::POA::_narrow( orb->resolve_initial_references("RootPOA")); CORBA::PolicyList policies; policies.length(1); policies[(CORBA::ULong)0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); // get the POA Manager PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager(); // Create myPOA with the right policies PortableServer::POA_var myPOA = rootPOA->create_POA("MyPOA", poa_manager, policies); Приклад програми-сервера C++Builder CORBA
// Create the servant smImpl Servant; // Decide on the ID for the servant PortableServer::ObjectId_var managerId = PortableServer::string_to_ObjectId("Ob1"); // Activate the servant with the ID on myPOA myPOA->activate_object_with_id(managerId, &Servant); // Activate the POA Manager poa_manager->activate(); CORBA::Object_var reference = myPOA->servant_to_reference(&Servant); Приклад програми-сервера (прод.) C++Builder CORBA
CORBA::Object_var nsv; CosNaming::NamingContextExt_var rootN; nsv = orb->resolve_initial_references("NameService"); rootN = CosNaming::NamingContextExt::_narrow(nsv.in()); if (CORBA::is_nil(rootN)) { Cout << "No root context" << endl; } CosNaming::Name_var n1 = rootN->to_name ("Name1.Comment1"); CosNaming::NamingContext_var ct1 = rootN->new_context (); rootN->rebind_context (n1, ct1); CosNaming::NamingContextExt_var Ct1Ext = CosNaming::NamingContextExt::_narrow (ct1); CosNaming::Name_var n2 = rootN->to_name ("Name2.Comment2"); Ct1Ext->rebind(n2, myPOA->servant_to_reference(&Servant)); cout << reference << " is ready" << endl; // Wait for incoming requests orb->run(); Приклад програми-сервера (прод.) C++Builder CORBA
// Initialize the ORB CORBA::ORB_var orb = CORBA::ORB_init(__argc, __argv); // Get a reference to the Naming Service root_context CORBA::Object_var nsv = orb->resolve_initial_references ("NameService"); CosNaming::NamingContextExt_var rootN = CosNaming::NamingContextExt::_narrow (nsv.in()); if(CORBA::is_nil(rootN)) { Cout << "No exist root context" << endl; } CosNaming::Name_var nc = rootN->to_name("Name1.Comment1" "/Name2.Comment2"); // (/) - component separator; // (.) - id and kind attributes separator; // Stringified name example: // "Borland.Company/Engineering.Department/Printer.Resource" CORBA::Object_ptr ob = rootN->resolve(nc); objRef = sm::_narrow (ob); Приклад програми-клієнта (фрагмент) C++Builder CORBA
nameserv [driver_options][nameserv_options] root_context_name driver_options: -J<Java option> Pass the specified option directly to the JVM nameserv_options: -?, -h, -help, -usage Print out the usage information. <ns_name> The name to use for this Naming Service. This is optional; the default name is NameService. nameserv -J-Dvbroker.se.iiop_tp.scm.iiop_tp.listener.port=14000 Serv.exe -ORBInitRef NameService=iioploc://127.0.0.1:14000/ NameService Client.exe -ORBInitRef NameService=iioploc://127.0.0.1:14000/ NameService nameserv C++Builder CORBA