summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_3547_Regression/Stock_Quoter_Server.cpp
blob: 4060f55494dc1e137878493ef49ff9c63fd5a0b5 (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
// $Id$

// Stock Quoter includes
#include "Stock_Quoter_i.h"

// UPDTest
#include "UDPTest_i.h"

// Advanced Resource Factory include
#include "tao/Strategies/advanced_resource.h"

// IORTable include
#include "tao/IORTable/IORTable.h"
#include "ace/streams.h"

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

    // Get the POA from the ORB.
    CORBA::Object_var poa_obj = orb->resolve_initial_references ("RootPOA");

    // Narrow to the POA interface
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_obj.in ());

    // Create a Stock Quoter implementation object
    Stock_Quoter_i* stock_quoter = new Stock_Quoter_i (orb.in ());

    UDPTest_i* UDP = new UDPTest_i ();

    // Activate the Stock Quoter in the RootPOA.
    PortableServer::ObjectId_var oid = root_poa->activate_object (stock_quoter);
    CORBA::Object_var sq_obj = root_poa->id_to_reference (oid.in());

    PortableServer::ObjectId_var oid1 = root_poa->activate_object (UDP);
    CORBA::Object_var udp_obj1 = root_poa->id_to_reference (oid1.in());

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

    ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

    // Also make the Stock Quoter object available via corbaloc
    // ObjectURL by binding it to a simple ObjectKey in the IORTable.
    CORBA::Object_var table_obj = orb->resolve_initial_references ("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow (table_obj.in());
    CORBA::String_var quoter_ior_string = orb->object_to_string (sq_obj.in());
    CORBA::String_var UDP_ior_string = orb->object_to_string (udp_obj1.in());
    table->bind ("UDPTest", UDP_ior_string.in());
    table->bind ("MyStockQuoter", quoter_ior_string.in());

    // Activate the POA Manager
    PortableServer::POAManager_var poa_mgr = root_poa->the_POAManager ();
    poa_mgr->activate ();

    cout << "Server ready" << endl;
    orb->run ();

    if (!UDP->received_send_)
    {
      ACE_ERROR_RETURN ((LM_ERROR, "Not received send\n"), 1);
    }
  }
  catch (CORBA::Exception& e)
  {
    e._tao_print_exception ("Exception caught:");
    return 1;
  }

  return 0;
}