~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/tests/MT_BiDir/client.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// client.cpp,v 1.1 2002/04/04 19:04:50 bala Exp
2
 
 
3
 
#include "ace/Get_Opt.h"
4
 
#include "Receiver_i.h"
5
 
#include "SenderC.h"
6
 
#include "tao/BiDir_GIOP/BiDirGIOP.h"
7
 
#include "Client_Task.h"
8
 
 
9
 
ACE_RCSID(BiDirectional, client, "client.cpp,v 1.6 2001/03/30 20:11:05 bala Exp")
10
 
 
11
 
const char *ior = "file://test.ior";
12
 
 
13
 
int
14
 
parse_args (int argc, char *argv[])
15
 
{
16
 
  ACE_Get_Opt get_opts (argc, argv, "k:");
17
 
  int c;
18
 
 
19
 
  while ((c = get_opts ()) != -1)
20
 
    switch (c)
21
 
      {
22
 
      case 'k':
23
 
        ior = get_opts.optarg;
24
 
        break;
25
 
      case '?':
26
 
      default:
27
 
        ACE_ERROR_RETURN ((LM_ERROR,
28
 
                           "usage:  %s "
29
 
                           "-k <ior> "
30
 
                           "\n",
31
 
                           argv [0]),
32
 
                          -1);
33
 
      }
34
 
  // Indicates sucessful parsing of the command line
35
 
  return 0;
36
 
}
37
 
 
38
 
int
39
 
main (int argc, char *argv[])
40
 
{
41
 
  ACE_DECLARE_NEW_CORBA_ENV;
42
 
 
43
 
  ACE_TRY
44
 
    {
45
 
      CORBA::ORB_var orb =
46
 
        CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
47
 
      ACE_TRY_CHECK;
48
 
 
49
 
      if (parse_args (argc, argv) != 0)
50
 
        return 1;
51
 
 
52
 
      CORBA::Object_var poa_object =
53
 
        orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
54
 
      ACE_TRY_CHECK;
55
 
 
56
 
      if (CORBA::is_nil (poa_object.in ()))
57
 
        ACE_ERROR_RETURN ((LM_ERROR,
58
 
                           " (%P|%t) Unable to initialize the POA.\n"),
59
 
                          1);
60
 
 
61
 
      PortableServer::POA_var root_poa =
62
 
        PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER);
63
 
      ACE_TRY_CHECK;
64
 
 
65
 
      PortableServer::POAManager_var poa_manager =
66
 
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
67
 
      ACE_TRY_CHECK;
68
 
 
69
 
      // Policies for the childPOA to be created.
70
 
      CORBA::PolicyList policies (1);
71
 
      policies.length (1);
72
 
 
73
 
      CORBA::Any pol;
74
 
      pol <<= BiDirPolicy::BOTH;
75
 
      policies[0] =
76
 
        orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
77
 
                            pol
78
 
                            ACE_ENV_ARG_PARAMETER);
79
 
      ACE_TRY_CHECK;
80
 
 
81
 
      // Create POA as child of RootPOA with the above policies.  This POA
82
 
      // will receive request in the same connection in which it sent
83
 
      // the request
84
 
      PortableServer::POA_var child_poa =
85
 
        root_poa->create_POA ("childPOA",
86
 
                              poa_manager.in (),
87
 
                              policies
88
 
                              ACE_ENV_ARG_PARAMETER);
89
 
      ACE_TRY_CHECK;
90
 
 
91
 
      // Creation of childPOA is over. Destroy the Policy objects.
92
 
      for (CORBA::ULong i = 0;
93
 
           i < policies.length ();
94
 
           ++i)
95
 
        {
96
 
          policies[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
97
 
          ACE_TRY_CHECK;
98
 
        }
99
 
 
100
 
      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
101
 
      ACE_TRY_CHECK;
102
 
 
103
 
      CORBA::Object_var object =
104
 
        orb->string_to_object (ior
105
 
                               ACE_ENV_ARG_PARAMETER);
106
 
      ACE_TRY_CHECK;
107
 
 
108
 
      Sender_var sender =
109
 
        Sender::_narrow (object.in ()
110
 
                         ACE_ENV_ARG_PARAMETER);
111
 
      ACE_TRY_CHECK;
112
 
 
113
 
      if (CORBA::is_nil (sender.in ()))
114
 
        {
115
 
          ACE_ERROR_RETURN ((LM_ERROR,
116
 
                             "Object reference <%s> is nil\n",
117
 
                             ior),
118
 
                            1);
119
 
        }
120
 
 
121
 
 
122
 
      Receiver_i *receiver;
123
 
      ACE_NEW_RETURN (receiver,
124
 
                      Receiver_i (),
125
 
                      -1);
126
 
 
127
 
      PortableServer::ServantBase_var owner_transfer (receiver);
128
 
 
129
 
      Receiver_var receiver_obj =
130
 
        receiver->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
131
 
      ACE_TRY_CHECK;
132
 
 
133
 
      // Send the calback object to the server
134
 
      sender->receiver_object (receiver_obj.in ()
135
 
                               ACE_ENV_ARG_PARAMETER);
136
 
      ACE_TRY_CHECK;
137
 
 
138
 
      // Threads that will handle the call backs
139
 
      Client_Task client_task (orb.in (),
140
 
                               ACE_Thread_Manager::instance ());
141
 
 
142
 
      if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1) == -1)
143
 
        {
144
 
          ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
145
 
        }
146
 
 
147
 
      ACE_Thread_Manager::instance ()->wait ();
148
 
 
149
 
      CORBA::Long count =
150
 
        receiver->get_event_count ();
151
 
 
152
 
      ACE_DEBUG ((LM_DEBUG,
153
 
                  "(%P|%t) Number of events received.. [%d] \n",
154
 
                  count));
155
 
 
156
 
      root_poa->destroy (1,
157
 
                         1
158
 
                         ACE_ENV_ARG_PARAMETER);
159
 
      ACE_TRY_CHECK;
160
 
    }
161
 
  ACE_CATCHANY
162
 
    {
163
 
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
164
 
                           "Catched exception:");
165
 
      return 1;
166
 
    }
167
 
  ACE_ENDTRY;
168
 
 
169
 
  return 0;
170
 
}