rllib  1
rlcorba.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlcorba.h - description
3  -------------------
4  begin : Tue Jan 02 2001
5  copyright : (C) 2001 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #ifndef _RL_CORBA_H_
17 #define _RL_CORBA_H_
18 
19 #include "rldefine.h"
20 #define rlMICO
21 //#define rlVISIBROKER
22 //#define rlOMNIORB
23 
24 #include <CORBA.h>
25 #ifdef rlMICO
26 #include <mico/throw.h>
27 #endif
28 
29 template <class T, class Tvar>
31 {
32 public:
33 #ifdef rlMICO
34  rlCorbaClient(int ac, char **av, const char *iname)
35  {
36  idlname = adr = NULL;
37  if(iname == NULL) return;
38  idlname = new char[strlen(iname)+1];
39  strcpy(idlname,iname);
40  for(int i=0; i<ac; i++)
41  {
42  if(strncmp(av[i],"inet:",5) == 0)
43  {
44  if(adr != NULL) delete adr;
45  adr = new char[strlen(av[i])+1];
46  strcpy(adr,av[i]);
47  }
48  }
49  orb = CORBA::ORB_init(ac,av);
50  obj = orb->bind(idlname, adr);
51  if(CORBA::is_nil(obj))
52  {
53  cerr << "cannot bind to " << adr << endl;
54  delete adr;
55  adr = NULL;
56  return;
57  }
58  client = T::_narrow(obj);
59  if(CORBA::is_nil(client))
60  {
61  cerr << "Argument is not a " << idlname << " reference" << endl;
62  }
63  }
65  {
66  if(idlname != NULL) delete idlname;
67  if(adr != NULL) delete adr;
68  }
69 #endif
70  char *idlname;
71  char *adr;
72  CORBA::ORB_var orb;
73  CORBA::Object_var obj;
74  Tvar client;
75 };
76 
77 template <class Timpl, class Tvar>
79 {
80 public:
81 #ifdef rlMICO
82  rlCorbaServer(int ac, char **av, const char *)
83  {
84  orb = CORBA::ORB_init(ac,av);
85  obj = orb->resolve_initial_references("RootPOA");
86  poa = PortableServer::POA::_narrow(obj);
87  mgr = poa->the_POAManager();
88  server = server_servant._this();
89  CORBA::String_var str = orb->object_to_string(server);
90  cout << str << endl; // write reference to stdout
91  mgr->activate();
92  }
94  {
95  }
96 #endif
97  void run()
98  {
99  orb->run();
100  }
101  char *adr;
102  CORBA::ORB_var orb;
103  CORBA::Object_var obj;
104  PortableServer::POA_var poa;
105  PortableServer::POAManager_var mgr;
107  Tvar server;
108 };
109 
110 #endif
Tvar server
Definition: rlcorba.h:107
~rlCorbaClient()
Definition: rlcorba.h:64
Tvar client
Definition: rlcorba.h:74
char * adr
Definition: rlcorba.h:71
~rlCorbaServer()
Definition: rlcorba.h:93
PortableServer::POA_var poa
Definition: rlcorba.h:104
rlCorbaServer(int ac, char **av, const char *)
Definition: rlcorba.h:82
CORBA::ORB_var orb
Definition: rlcorba.h:72
Timpl server_servant
Definition: rlcorba.h:106
CORBA::ORB_var orb
Definition: rlcorba.h:102
CORBA::Object_var obj
Definition: rlcorba.h:103
char * idlname
Definition: rlcorba.h:70
void run()
Definition: rlcorba.h:97
char * adr
Definition: rlcorba.h:101
rlCorbaClient(int ac, char **av, const char *iname)
Definition: rlcorba.h:34
PortableServer::POAManager_var mgr
Definition: rlcorba.h:105
CORBA::Object_var obj
Definition: rlcorba.h:73