summaryrefslogtreecommitdiff
path: root/TAO/tests/OBV/Indirection/MessengerClient.cpp
blob: 2269964b8b489cdb6421a0adffc4c0298595174c (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
// $Id$

#include "MessengerC.h"
#include "Factory.h"
#include <iostream>

const char* server_ior = "file://server.ior";
using namespace demo::value::idl;
const char* IOR = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

int ACE_TMAIN (int ac, ACE_TCHAR* av[]) {

  try {

    CORBA::ORB_var orb = CORBA::ORB_init(ac, av);

    NodeFactory::register_new_factory(* orb.in());
    BoxedValueFactory::register_new_factory(* orb.in());
    BaseValueFactory::register_new_factory(* orb.in());
    TValueFactory::register_new_factory(* orb.in());
    ConfigValueFactory::register_new_factory(* orb.in());

    CORBA::Object_var obj = orb->string_to_object(server_ior);
    ValueServer_var tst = ValueServer::_narrow(obj.in());
    ACE_ASSERT(! CORBA::is_nil(tst.in()));

    // invoke operations and print the results
    boxedLong* p1 = new boxedLong (774);
    boxedLong* p2 = new boxedLong (775);
    boxedString* s1 = new boxedString ("hello");
    boxedString* s2 = new boxedString ("world");
    boxedString* null = 0;
    boxedValue* b = new OBV_demo::value::idl::boxedValue ();
    b->b1 (p1);
    b->b2 (p2);
    boxedValue* bb = new OBV_demo::value::idl::boxedValue ();
    bb->b1 (p1);
    bb->b2 (p1);

    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two boxed values in one valuetype: %s\n",
      tst->receive_boxedvalue (b)));
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing one boxed values twice in one valuetype: %s\n",
      tst->receive_boxedvalue (bb)));
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two integers: %s\n",
      tst->receive_long (p1, p2)));
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing one integer twice: %s\n",
      tst->receive_long (p1, p1)));
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two strings: %s\n",
      tst->receive_string (s1, s2)));
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing null: %s\n",
      tst->receive_string (s1, null)));

    Node* n4 = new OBV_demo::value::idl::Node (4, 0);
    Node* n3 = new OBV_demo::value::idl::Node (3, n4);
    Node* n2 = new OBV_demo::value::idl::Node (2, n3);
    Node* n1 = new OBV_demo::value::idl::Node (1, n2);

    n4->next(n1);

    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing a list structure: %s\n",
      tst->receive_list (n1)));

#if 1
    TValue* t = new OBV_demo::value::idl::TValue ();
    t->data (20);
    t->basic_data (10);

    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing inout truncatable: %s\n",
      tst->receive_truncatable (t)));
    if (t->data () != 21 || t->basic_data () != 11)
    {
      std::cerr << "Received incorrect truncatable data" << std::endl;
      return 1;
    }
#endif

    const CORBA::ULong sz = 50;
    ::demo::value::idl::ConfigValues configs (sz);
    configs.length (sz);
    for (CORBA::ULong i = 0; i < sz; ++i)
    {
      configs[i] = new ConfigValueImpl ("IOR", IOR);
    }

    ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing sequence: %s\n",
      tst->receive_sequence (configs)));

    while (orb->work_pending()) {
      orb->perform_work();
    }

    orb->destroy();

  } catch(const CORBA::Exception& e) {
    std::cerr << e << std::endl;
    return 1;
  }

  return 0;
}