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 public:
21 // IDL: string reverse(in string message);
22 char* reverse(const char* message);
23 };
24
25
26 // reverse a given message
27 char* Server_Impl::reverse(const char* message)
28 {
29 // some nice info
30 std::cout << "Invoked by client, incoming: '" << message << "'";
31
32 // create new string
33 unsigned int length = strlen(message);
34 char* result = CORBA::string_alloc(length);
35 if (result == NULL)
36 return result;
37
38 // zero-terminated !
39 result[length] = 0;
40
41 // reverse the message
42 for (unsigned i=0; i<length; i++)
43 result[i] = message[length-i-1];
44
45 // again some info
46 std::cout << " - returning: '" << result << "'" << std::endl;
47 // done !
48 return result;
49 }
50
51
52
53 int main(int argc, char* argv[])
54 {
55 // initialize CORBA and its BOA components
56 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "mico-local-orb");
57 CORBA::BOA_var boa = orb->BOA_init(argc, argv, "mico-local-boa");
58
59 // register object
60 Server_Impl* server = new Server_Impl;
61 CORBA::String_var reference = orb->object_to_string(server);
62
63 // write out the object's IOR
64 std::cout << reference << std::endl;
65 std::ofstream ior("ior.txt");
66 ior << reference;
67 ior.close();
68
69 // wait for requests
70 boa->impl_is_ready(CORBA::ImplementationDef::_nil());
71 orb->run();
72
73 // game over
74 CORBA::release(server);
75 return 0;
76 }
77