Hello (CORBA) Universe

H



slide: Hello (CORBA) Universe


  module universe { 
universe.idl
interface world {
world
void hello(); void ask(in string x); string tell(); oneway void halt(); }; };

C++ realization


slide: C++ realization


C++ broker -- class


  class broker { 
broker.h
public: broker(); void init(int& argc, char**& argv, int fl=0); // 1 = client int operator()(); // to run the server char* ref(corba::object* x); // object_to_string corba::object* ref(const char* s); // string_to object corba::object* object(const char* file); // get object IOR file void refout(const char* f, corba::object* x); // IOR to file };

slide: C++ broker -- class


C++ broker -- implementation


  broker::broker() { }  
broker.c
void broker::init(int& argc, char**& argv, int fl=0) { _orb = CORBA_ORB_init(argc, argv); if (!fl) _boa = _orb -> BOA_init(argc, argv); } } int broker::operator()() { _boa -> impl_is_ready(CORBA_ImplementationDef::_nil()); }

slide: C++ broker -- implementation


C++ client


      int main(int argc, char* argv[], char*[]) { 
client.c
broker* _broker = new broker(); // get yourself a broker try { _broker->init(argc,argv); // initialize broker corba::object* obj = _broker->object("world.ref"); universe_world_var world = universe_world::_narrow(obj); { // some object invocations world -> hello(); world -> ask("How are Clinton's affairs?"); cout << "client:" << world->tell() << endl; } } catch(corba::exception ex) { ... } }

slide: client


C++ server


  int main(int argc, char* argv[], char*[]) 
server.c
{ broker* _broker = new broker(); // get yourself a broker try { _broker->init(argc,argv); // initialize orb and boa universe_world_var p = new universe_world_srv; _broker->refout("world.ref", p); // write identity _broker->operator()(); // run the the world } catch(corba::exception& ex) { ... } }

slide: server


C++ world implementation


  void universe_world_srv::hello() {  
world_srv.c
cout << "Hello World!" << endl; } void universe_world_srv::ask(const char* s) { cout << "Asking: " << s << endl; } char* universe_world_srv::tell() { char result[] = "ok"; CORBA_String_var s = (const char*) result; return s._retn(); } void universe_world_srv::halt() { exit(0); }

slide: world-srv.c


Java realization


slide: Java realization



  import org.omg.CORBA.*; 
broker.java
import java.io.*; public class broker { boolean _fl = false; java.applet.Applet _applet = null; public broker() { } public broker(boolean fl) { _fl = fl; } public broker(java.applet.Applet x) { _applet = x; init(null); } public void init(String[] args) { if (_applet == null) { _orb = ORB.init(args,new java.util.Properties()); if (!_fl) _boa = _orb.BOA_init(args,new java.util.Properties()); } else _orb = ORB.init(_applet, null); } public int operator() {
run -- server-only
if (!_fl) _boa.impl_is_ready(null); return 0; // OK } .... };

slide: Java -- broker


Java -- client


  package universe;
  
  import org.omg.CORBA.*; 
client.java
import java.io.*; import hush.broker; // see broker.java public class client { public static void main(String args[]) { broker _broker = new broker(true); // true means client only try { _broker.init(args); // init orb org.omg.CORBA.Object obj = _broker.object("world.ref"); world world = worldHelper.narrow(obj); if (world == null) throw new RuntimeException(); System.out.println("Enter 'h' (hello) or 'x' (exit):"); ... // do some requests to the world } catch(...) { ... } } };

slide: Java -- client

Java -- server


  package universe; 
server.java
import org.omg.CORBA.*; import java.io.*; import hush.broker; // see broker.java public class server { public static void main(String args[]) { broker _broker = new broker(); try { _broker.init(args); // create orb en boa; world_srv p = new world_srv(); // create impl object _broker.refout("world.ref",p); // write ref _broker.html("world.htm",p, // create world.htm " code=universe/applet.class " + "width=500 height=300"); _broker.operator(); // run == boa.impl_is_ready(null); } catch(SystemException ex) { _broker.print(ex); System.exit(1); } System.exit(0); } }

Java -- server implementation


  package universe; 
world_srv.java
import org.omg.CORBA.*; public class world_srv extends _worldImplBase { public void hello() { System.out.println("Hello World!"); } public void ask(String msg) { System.out.println(msg); } public String tell() { String s = new String("ok"); return s; } public void halt() { System.exit(0); } }

Prolog realization


slide: Prolog realization



  broker(client(M:F)) :- 
broker.pl
... corba_initialize_orb([], _), factory(F). // gives a handle to the server object broker(server(M:I)) :- ... corba_initialize_server([server,server(test), timeout(infinite)],Server), ... // create server object G =.. [_Create,_Server,Self], call(G), corba_object_to_string(Self,IOR), open(IORFile,write,Fd), // write reference to file format(Fd,'string',[IOR]), close(Fd), corba_main_loop(Server). // enter main loop

slide: Prolog -- broker



  
client.pl
:- use_module(universe). // see universe.pl :- [broker]. // include broker main :- broker(client(universe:F)), // initialize the broker assert(client(factory(F))), run. run :- h, ask('What is the state of Clinton s affairs?'), write('Type h to say hallo, x to quit.'),nl. ask(X) :- client(factory(F)), write(client(ask(X))),nl, world_ask(F,X), world_tell(F,R), write(client(ans(R))),nl. h :- client(factory(F)), world_hello(F). q :- client(factory(F)), world_halt(F), halt. x :- halt.

slide: Prolog -- client



  :- [broker]. 
server.pl
main :- broker(server(universe:world)).

slide: Prolog -- server


Prolog -- implementation


  :- module('universe',[]). 
universe.pl
world_hello(_Self) :- write('Hello World'),nl. world_ask(_Self, X) :- write(asking(X)), nl. world_tell(_Self,Y) :- Y = 'logically, ok', write(telling(Y)),nl. world_halt(_Self) :- halt.

slide: Prolog -- implementation


Configure, make and test


slide: Configure, make and test


Conclusions


slide: Conclusions