sources:
Aufgabe2.cpp (7.7k)
Aufgabe2.h (2.9k)
Client.cpp (1.8k)
Helper.h (741 bytes)
Server.cpp (3.7k)
aufgabe2.idl (85 bytes)


website:
more info here
studies/corba/Corba-Code3/Client.cpp
download file

  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     {
 26         // initialize CORBA
 27         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 28    
 29         //////////////////////////////////////
 30         // Connect to Naming Service
 31         cout << "Resolve Naming Service ..." << endl;
 32         // resolve naming service
 33         CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
 34         // not found ?
 35         CorbaAssert(namingService, "Couldn't locate the Naming Service.");
 36
 37         // get the naming context
 38         CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
 39         // not found ?
 40         CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
 41
 42         // my Windows(R)(TM)(C) login name: "Stephan.Brumme"
 43         CosNaming::Name name;
 44         name.length(1);
 45         name[0].id   = CORBA::string_dup("Stephan.Brumme");
 46         name[0].kind = CORBA::string_dup("CCM");
 47
 48
 49         // create and cast the remote object
 50         CORBA::Object_var obj = namingContext->resolve(name);
 51         CorbaAssert(obj, "Invalid object.");
 52         Server_var remote = Server::_narrow(obj);
 53         CorbaAssert(remote, "Invalid object.");
 54
 55         // invoke the "reverse" operation
 56         std::cout << remote->reverse("Corba Component Model") << std::endl;
 57     }
 58     catch (CORBA::Exception& e)
 59     {
 60         CorbaError("Corba failed to run properly.");
 61     }
 62
 63     return 0;
 64 }
 65