Because OmniBroker supports C++ as well as Java, the client and/or the server can be written in C++ instead of Java. For example, here is the client program that we have been using written in C++ instead of Java:
0294: #include <iostream.h> 0295: #include <stdlib.h> 0296: #include <OB/CORBA.h> 0297: #include <OB/CosNaming.h> 0298: #include <Count.h> 0299: int main(int argc, char* argv[], char*[]) { 0300: try { 0301: CORBA_ORB_var orb = CORBA_ORB_init(argc, argv); 0302: CORBA_BOA_var boa = orb -> BOA_init(argc, argv); 0303: CORBA_Object_var objRef = orb -> string_to_object(argv[1]); 0304: CosNaming_NamingContext_var ncRef = 0305: CosNaming_NamingContext::_narrow(objRef); 0306: CosNaming_Name path; 0307: path.length(1); 0308: path[0].id = CORBA_string_dup("second Count"); 0309: path[0].kind = CORBA_string_dup(""); 0310: CountApp_Count_var stubCount = 0311: CountApp_Count::_narrow(ncRef -> resolve(path)); 0312: cout << "before loop" << endl; 0313: while ( true ) { 0314: char stdinLine[100]; 0315: cin >> stdinLine; 0316: if ( stdinLine[0] == 'q' ) break; 0317: if ( stdinLine[0] == 's' ) 0318: cout << stubCount -> getCount() << endl; 0319: else { 0320: int intVal = atoi(stdinLine); 0321: stubCount -> setCount(intVal); 0322: } 0323: } 0324: cout << "after loop" << endl; 0325: } 0326: catch ( ... ) { 0327: cout << "whoops" << endl; 0328: } 0329: }
To support C++, OmniBroker comes with a program called idl that can be used to process the interface in the file Count.idl:
setenv PATH /usr/local/utils/OB/current/bin:$PATH idl Count.idlThis will create the files Count_skel.h, Count_skel.cpp, Count.h and Count.cpp in the current directory. The client program can now be compiled using a C++ compiler, such as the GNU C++ compiler:
g++ -c --no-implicit-templates -fhandle-exceptions \ -I. -I/usr/local/utils/OB/current/include CountClient.cpp g++ -c --no-implicit-templates -fhandle-exceptions \ -I. -I/usr/local/utils/OB/current/include Count.cppThis will produce the files CountClient.o and Count.o. These can be linked to produce a binary in the file CountClient by the command:
g++ -o CountClient CountClient.o Count.o -L/usr/local/utils/OB/current/lib \ -lOB -lCosNaming -lIDL -lsocket -lnsl
Finally, the C++ version of the client program can be run, e.g., by using the command:
CountClient `grep IOR ../../IDL/CountNSIOR/nameserv.ior`
The text of the above program is at http://www.dur.ac.uk/barry.cornelius/papers/OB/CountNSIORPP/.