summaryrefslogtreecommitdiff
path: root/TAO/examples/PluggableUDP/tests/Basic/UDP_Client_i.cpp
blob: 1b0da8ea29918c1c7be6c0975da2cdf4e08a1605 (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
// $Id$

#include "UDP_Client_i.h"
#include "ace/SString.h"
#include "ace/OS_NS_unistd.h"

// This is the interface program that accesses the remote object

// Constructor.
UDP_Client_i::UDP_Client_i (CORBA::ORB_ptr orb,
                            UDP_ptr udp,
                            UDP_ptr udpHandler,
                            ACE_UINT32 msec,
                            ACE_UINT32 iterations)
: orb_ (CORBA::ORB::_duplicate (orb))
, udp_ (UDP::_duplicate (udp))
, udpHandler_ (UDP::_duplicate (udpHandler))
, delay_ (msec)
, iterations_ (iterations)
{

}

//Destructor.
UDP_Client_i::~UDP_Client_i (void)
{
  //no-op
}

int
UDP_Client_i::svc (void)
{
  ACE_CString client_name ("UDP");

  char pid[256];
  ACE_OS::sprintf (pid,
                   "%u",
                   static_cast<u_int> (ACE_OS::getpid ()));
  client_name += "_";
  client_name += pid;

  ACE_DECLARE_NEW_CORBA_ENV;

  ACE_TRY
    {
      CORBA::String_var corba_client_name =
        CORBA::string_dup (client_name.c_str ());

      for (ACE_UINT32 i = 0;
           i < iterations_;
           i++)
        {
          udp_->invoke (corba_client_name.in (),
                        udpHandler_.inout (),
                        i
                        ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_DEBUG ((LM_DEBUG,
                      "invoked %s %d, going to wait %d ms\n",
                      corba_client_name.in (),
                      i,
                                                  delay_));
          ACE_Time_Value tv (0, delay_ * 1000);
          ACE_OS::sleep (tv);  // wait to not flood the server
        }

      // shut down remote ORB
      udp_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_Time_Value tv (0, 500); // 50ms
      ACE_OS::sleep (tv);  // let the previous request go through

      // Shut down local ORB, trigger the end of the ORB event loop
          // in the main thread.
      orb_->shutdown ();

    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "\tException");
      return -1;
    }
  ACE_ENDTRY;


  return 0;
}