OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / doc / mico / examples / poa / hello-1 / server.cc
1 /*
2  * A simple "Hello World" example that uses the POA
3  */
4
5 #include "hello.h"
6 #ifdef HAVE_ANSI_CPLUSPLUS_HEADERS
7 #include <fstream>
8 #else
9 #include <fstream.h>
10 #endif
11
12
13 using namespace std;
14
15 /*
16  * Hello World implementation inherits the POA skeleton class
17  */
18
19 class HelloWorld_impl : virtual public POA_HelloWorld
20 {
21 public:
22   void hello ();
23 };
24
25 void
26 HelloWorld_impl::hello ()
27 {
28   cout << "Hello World" << endl;
29 }
30
31 int
32 main (int argc, char *argv[])
33 {
34   /*
35    * Initialize the ORB
36    */
37
38   CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
39
40   /*
41    * Obtain a reference to the RootPOA and its Manager
42    */
43
44   CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
45   PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
46   PortableServer::POAManager_var mgr = poa->the_POAManager();
47
48   /*
49    * Create a Hello World object
50    */
51
52   HelloWorld_impl * hello = new HelloWorld_impl;
53
54   /*
55    * Activate the Servant
56    */
57
58   PortableServer::ObjectId_var oid = poa->activate_object (hello);
59
60   /*
61    * Write reference to file
62    */
63
64   ofstream of ("hello.ref");
65   CORBA::Object_var ref = poa->id_to_reference (oid.in());
66   CORBA::String_var str = orb->object_to_string (ref.in());
67   of << str.in() << endl;
68   of.close ();
69
70   /*
71    * Activate the POA and start serving requests
72    */
73
74   cout << "Running." << endl;
75
76   mgr->activate ();
77   orb->run();
78
79   /*
80    * Shutdown (never reached)
81    */
82
83   poa->destroy (TRUE, TRUE);
84   delete hello;
85
86   return 0;
87 }