summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_1383_Regression/SimpleClient.cpp
blob: 4b9cc99d591ddeae7b3717a0732bda7b607201b1 (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
132
133
134
// $Id$

#include "tao/corba.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Thread.h"
#include "simpleC.h"
#include "Callee_i.h"
#include "tao/IORManipulation/IORManip_Loader.h"

CORBA::ORB_var _orb;

ACE_THR_FUNC_RETURN RunFunc(void *)
{
  ACE_DEBUG ((LM_DEBUG, "running the _orb\n"));
  _orb->run();
  ACE_DEBUG ((LM_DEBUG, "done running _orb\n"));
  return 0;
}

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // initialize the ORB
      _orb = CORBA::ORB_init (argc, argv);

      // Get the "RootPOA"
      CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in ());

      // activate its managers so it can handle incoming requests
      poa->the_POAManager()->activate();

      // get a thread going to handle incoming requests
      ACE_Thread::spawn(RunFunc);

      // we could also use the c_orbaloc syntax to get a reference to the
      // object. This will cause the _orb to talk directly to the other
      // _orb with no name service or common file involved.
      obj = _orb->string_to_object("c_orbaloc::localhost:9999/Simple");

      if (CORBA::is_nil(obj.in ()))
        {
          ACE_ERROR ((LM_ERROR, "could not get reference\n"));
          return 1;
        }

      // narrow the reference to the particular type we wish to deal with
      Simple_var simple = Simple::_narrow(obj.in ());
      if (CORBA::is_nil(simple.in ()))
        {
          ACE_ERROR ((LM_ERROR, "could not get reference\n"));
          return 1;
        }

      // create an object reference that has a bogus value for the first
      // profile
      obj = _orb->resolve_initial_references("IORManipulation");
      TAO_IOP::TAO_IOR_Manipulation_var iorm =
        TAO_IOP::TAO_IOR_Manipulation::_narrow(obj.in());

      // Status: The following scenarios appear to work:
      // - first profile invalid host name, second profile valid.
      // - first profile invalid ip number, second profiel valid.
      // - first profiel invalid port number, second profile valid.
      //
      // The following causes a core dump of the server:
      // - first and second invalid
      //
      // Note that he iormanip is being used since it is not practical
      // to have a test case that depends on a VPN being present.
      //
      CORBA::Object_var name1 =
        _orb->string_to_object ("c_orbaloc:iiop:10.0.2.3:6060/xyz");
      CORBA::Object_var name2 =
        _orb->string_to_object ("c_orbaloc:iiop:daisnot:7070/xyz");
      CORBA::String_var name1_ior = _orb->object_to_string(name1.in());
      CORBA::String_var name2_ior = _orb->object_to_string(name2.in());

      // create a callback object
      Callee_i * callee_i = new Callee_i;
      // get the CORBA reference
      PortableServer::ObjectId_var id =
        poa->activate_object (callee_i);

      CORBA::Object_var object_act = poa->id_to_reference (id.in ());

      Callee_var callee = Callee::_narrow (object_act.in ());

      if (CORBA::is_nil(callee.in ()))
        {
          ACE_ERROR ((LM_ERROR, "could not get callback object\n"));
          return 1;
        }
      else
        {
          CORBA::String_var str = _orb->object_to_string(callee.in ());
          FILE *output_file= ACE_OS::fopen ("ior", "w");
          if (output_file == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                              "Cannot open output file for writing IOR: ior\n"),
                              1);
          ACE_OS::fprintf (output_file, "%s", str.in ());
          ACE_OS::fclose (output_file);
        }

      // create a reference with two profiles with the first on being
      // bogus. If things work as they should the callback should be
      // succesful with the ORB trying the second profile.
      TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
      iors.length (2);
      iors [0] = name1;
      iors [1] = name2;

      CORBA::Object_var merged = iorm->merge_iors(iors);
        Callee_var doubleCallee = Callee::_unchecked_narrow(merged.in());

      ACE_DEBUG ((LM_DEBUG, "Profile count is %d\n",
                  iorm->get_profile_count(merged.in())));

      simple->registerCallee(doubleCallee.in ());

      ACE_OS::sleep(120);

      ACE_DEBUG ((LM_DEBUG, "done sleeping\n"));

      _orb->shutdown(1);
    }
  catch (const ::CORBA::Exception &ex)
    {
      ex._tao_print_exception("Caught unexpected CORBA exception :");
    }
  return 0;
}