sources:
Aufgabe2.cpp (5.5k)
Aufgabe2.h (2.0k)
Aufgabe2.idl (85 bytes)
Client.cpp (1020 bytes)
Server.cpp (1.8k)


website:
more info here
studies/corba/Corba-Code2/Server.cpp
download file

  1 // ////////////////////////////////////////////////////////
  2 // Lecture on the CORBA Component Model, summer term 2003
  3 // Assignment 2, Stephan Brumme, 702544
  4 //
  5 // CORBA server that provides an operation to reverse
  6 // a string
  7 //
  8
  9 // save and display IOR
 10 #include <iostream>
 11 #include <fstream>
 12
 13 // IDL compiler generated a skeleton
 14 #include "Aufgabe2.h"
 15 using namespace Aufgabe2;
 16
 17
 18 // the server
 19 class Server_Impl : public virtual Server_skel
 20 {
 21 public:
 22     // IDL: string reverse(in string message);
 23     char* reverse(const char* message);
 24 };
 25
 26
 27 // reverse a given message
 28 char* Server_Impl::reverse(const char* message)
 29 {
 30     // some nice info
 31     std::cout << "Invoked by client, incoming: '" << message << "'";
 32
 33     // create new string
 34     unsigned int length = strlen(message);
 35     char* result = CORBA::string_alloc(length);
 36     if (result == NULL)
 37         return result;
 38
 39     // zero-terminated !
 40     result[length] = 0;
 41
 42     // reverse the message
 43     for (unsigned i=0; i<length; i++)
 44         result[i] = message[length-i-1];
 45
 46     // again some info
 47     std::cout << " - returning: '" << result << "'" << std::endl;
 48     // done !
 49     return result;
 50 }
 51
 52
 53
 54 int main(int argc, char* argv[])
 55 {
 56     // initialize CORBA and its BOA components
 57     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "mico-local-orb");
 58     CORBA::BOA_var boa = orb->BOA_init(argc, argv, "mico-local-boa");
 59
 60     // register object
 61     Server_Impl* server = new Server_Impl;
 62     CORBA::String_var reference = orb->object_to_string(server);
 63
 64     // write out the object's IOR
 65     std::cout << reference << std::endl;
 66     std::ofstream ior("ior.txt");
 67     ior << reference;
 68     ior.close();
 69
 70     // wait for requests
 71     boa->impl_is_ready(CORBA::ImplementationDef::_nil());
 72     orb->run();
 73
 74     // game over
 75     CORBA::release(server);
 76     return 0;
 77 }
 78