summaryrefslogtreecommitdiff
path: root/TAO/tests/ORB_Local_Config/Two_DLL_ORB/server.cpp
blob: e44275ac8eb081d9ce2473e3fb0e4f61ac34525a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// $Id$


#include "Test_i.h"
#include "ORB_DLL.h"

#include "ace/Get_Opt.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Argv_Type_Converter.h"


ACE_RCSID (Hello,
           server,
           "$Id$")

//
Server_Worker::Server_Worker ()
  : Abstract_Worker ("test.ior")
{
}

//
const ACE_TCHAR *
Server_Worker::kind (void) const
{
  return ACE_TEXT ("Server");
}

//
Server_Worker::~Server_Worker (void)
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) %@ Server::<dtor>\n", this));
}

//
int
Server_Worker::parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "o:",0);

  for( int c = 0; ((c = get_opts ()) != -1); )
    switch (c)
    {
    case 'o':
      this->ior_file_ = get_opts.opt_arg ();
      break;
    }

  // Indicates sucessful parsing of the command line
  return 0;
}

//
int
Server_Worker::test_main (int argc, ACE_TCHAR *argv[])
{
  // Making sure there are no stale ior files to confuse a client
  ACE_OS::unlink (ior_file_.c_str ());

  ACE_Argv_Type_Converter cvt (argc, argv);
  CORBA::ORB_var orb = CORBA::ORB_init (cvt.get_argc (),
                                        cvt.get_ASCII_argv ());

  CORBA::Object_var poa_object =
    orb->resolve_initial_references("RootPOA");

  PortableServer::POA_var root_poa =
    PortableServer::POA::_narrow (poa_object.in ());

  if (CORBA::is_nil (root_poa.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%P|%t) Panic: nil RootPOA\n")),
                      1);

  PortableServer::POAManager_var poa_manager =
    root_poa->the_POAManager ();

  if (parse_args (cvt.get_argc (), cvt.get_ASCII_argv ()) != 0)
    return 1;

  Hello *hello_impl;
  ACE_NEW_RETURN (hello_impl,
                  Hello (orb.in ()),
                  1);

  PortableServer::ServantBase_var owner_transfer(hello_impl);

  PortableServer::ObjectId_var id =
    root_poa->activate_object (hello_impl);

  CORBA::Object_var hello_obj =
    root_poa->id_to_reference (id.in ());

  Test::Hello_var hello =
    Test::Hello::_narrow (hello_obj.in ());

  CORBA::String_var ior =
    orb->object_to_string (hello.in ());

  poa_manager->activate ();

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Server activated POA manager\n")));

  // Output the IOR to the <ior_output_file>
  FILE *output_file= ACE_OS::fopen (ior_file_.c_str (), "w");
  if (output_file == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%P|%t) Cannot open output file for writing IOR: %s"),
                       ior_file_.c_str ()),
                      1);
  ACE_OS::fprintf (output_file, "%s", ior.in ());
  ACE_OS::fclose (output_file);

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Server entering the event loop\n")));

  orb->run ();

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Server exiting the event loop\n")));

  root_poa->destroy (1, 1);

  // During normal test execution the ORB would have been destroyed
  // by a request from the client.

  //  orb->shutdown (0);

  orb->destroy ();

  return 0;
}