summaryrefslogtreecommitdiff
path: root/TAO/tests/Collocation_Oneway_Tests/Client_Task.cpp
blob: 405fce98fc4c7aeb49d80a7d72bdedfd9f3e1950 (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
//
// $Id$
//

#include "tao/Messaging/Messaging.h"
#include "tao/AnyTypeCode/Any.h"
#include "Client_Task.h"
#include "TestC.h"

ACE_RCSID(Collocation_Oneway_Tests, Client_Task, "$Id$")

Client_Task::Client_Task (const ACE_TCHAR *ior,
                          CORBA::ORB_ptr corb,
                          Client_Task::ClientSyncModeEnum syncMode,
                          ACE_Thread_Manager *thr_mgr)
  : ACE_Task_Base (thr_mgr)
    , input_ (ior)
    , corb_ (CORBA::ORB::_duplicate (corb))
    , syncMode_ (syncMode)

{
}

int
Client_Task::svc (void)
{
  try
    {
      CORBA::Object_var tmp =
        this->corb_->string_to_object (input_);

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

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Hello reference <%s>\n",
                             input_),
                             1);
        }

      Test::Hello_var tmpVar = hello;
      CORBA::Any anyPolicy;

      Messaging::SyncScope selectedScope = Messaging::SYNC_NONE; // default

      if(syncMode_ == Client_Task::MODE_TRANSPORT) {
          selectedScope = Messaging::SYNC_WITH_TRANSPORT;
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_TRANSPORT collocated oneway test\n"));
      }
      else if(syncMode_ == Client_Task::MODE_SERVER) {
          selectedScope = Messaging::SYNC_WITH_SERVER;
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_SERVER collocated oneway test\n"));
      }
      else if(syncMode_ == Client_Task::MODE_TARGET) {
          selectedScope = Messaging::SYNC_WITH_TARGET;
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_TARGET collocated oneway test\n"));
      }
      else if(syncMode_ == Client_Task::MODE_NONE) {
          selectedScope = Messaging::SYNC_NONE;
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_NONE collocated oneway test\n"));
      }

      anyPolicy <<= selectedScope;
      CORBA::PolicyList polList;
      polList.length(1);
      polList[0] = this->corb_->create_policy(
        Messaging::SYNC_SCOPE_POLICY_TYPE, anyPolicy);

      CORBA::Object_var tmpGenericVar =
        tmpVar->_set_policy_overrides(polList,CORBA::ADD_OVERRIDE);

      // do unchecked narrow because ORB's not activated. Otherwise get TRANSIENT exception
      hello = Test::Hello::_narrow(tmpGenericVar.in());

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Hello reference <%s>\n",
                             input_),
                             1);
        }

      CORBA::String_var the_string =
        hello->get_string ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
                  the_string.in ()));

      hello->onewayTest();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - returned from onewayTest() call \n"));

      hello->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;

}