1 // ////////////////////////////////////////////////////////
2 // Lecture on the CORBA Component Model, summer term 2003
3 // Assignment 3, Stephan Brumme, 702544
4 //
5 // CORBA client that calls a remote "reverse" operation
6 // using the naming service
7 //
8
9 // save and display IOR
10 #include <iostream>
11 using namespace std;
12
13 #include "Helper.h"
14
15 // IDL compiler generated a stub
16 #include "Aufgabe2.h"
17 using namespace Aufgabe2;
18 // CORBA's naming service
19 #include <coss/CosNaming.h>
20
21
22 int main(int argc, char* argv[])
23 {
24 try
{
25 // initialize CORBA
26 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
27
28 //////////////////////////////////////
29 // Connect to Naming Service
30 cout << "Resolve Naming Service ..." << endl;
31 // resolve naming service
32 CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
33 // not found ?
34 CorbaAssert(namingService, "Couldn't locate the Naming Service.");
35
36 // get the naming context
37 CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
38 // not found ?
39 CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
40
41 // my Windows(R)(TM)(C) login name: "Stephan.Brumme"
42 CosNaming::Name name;
43 name.length(1);
44 name[0].id = CORBA::string_dup("Stephan.Brumme");
45 name[0].kind = CORBA::string_dup("CCM");
46
47
48 // create and cast the remote object
49 CORBA::Object_var obj = namingContext->resolve(name);
50 CorbaAssert(obj, "Invalid object.");
51 Server_var remote = Server::_narrow(obj);
52 CorbaAssert(remote, "Invalid object.");
53
54 // invoke the "reverse" operation
55 std::cout << remote->reverse("Corba Component Model") << std::endl;
56 }
57 catch (CORBA::Exception& e)
58 {
59 CorbaError("Corba failed to run properly.");
60 }
61
62 return 0;
63 }
64