summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_1495_Regression/Threaded_Client.cpp
blob: 6b4d64176959c189bda12ddecd718fb6b61600ed (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * $Id$
 *
 * @file Threaded_Client.cpp
 * @author Will Otte <wotte@dre.vanderbilt.edu>
 *
 * This program spawns two threads:
 *    1.)  A "server" thread using Server_Task that acts as a server meant to
 *         recieve forwarded requests.
 *    2.)  A "client" thread using Client_Task that acts as a client that sends
 *         a get_thread_id request that is forwarded by a remote server to
 *         the server in thread (1).
 *
 *
 * The test passes if the thread id of the thread that services the get_thread_id
 * request is the same as the thread that makes the request.
 *
 */

#include "Server_Task.h"
#include "Client_Task.h"
#include "ace/Get_Opt.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/Manual_Event.h"

const char *ior_input_file = "file://test.ior";
const char *ior_output_file = "thr_server.ior";

int
parse_args (int argc, char *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "i:o:");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
        case 'i':
          ior_input_file = get_opts.opt_arg ();
          break;
        case 'o':
          ior_output_file = get_opts.opt_arg ();
          break;
        case '?':
        default:
            ACE_ERROR_RETURN ((LM_ERROR,
                               "usage:  %s "
                               "-i alternate_remote_ior "
                               "-o alternate_local_ior "
                               "\n",
                               argv [0]),
                              -1);
      }
  return 0;
}


int
main (int argc, char *argv[])
{
  // Parse command line
  if (parse_args (argc, argv) == -1)
    {
      return -1;
    }

  try
    {
      ACE_Argv_Type_Converter main_args_s (argc, argv);

      CORBA::ORB_var sorb =
        CORBA::ORB_init (main_args_s.get_argc (),
                         main_args_s.get_TCHAR_argv (),
                         "Server_ORB");

      ACE_Manual_Event me;

      Server_Task server_task (ior_output_file,
                               sorb.in (),
                               me,
                               ACE_Thread_Manager::instance ());

      if (server_task.activate (THR_JOINABLE, 1, 1) == -1)
        {
          ACE_ERROR ((LM_ERROR, "Error activating the server task."));
          return -1;
        }

      // Wait for the server task to activate.
      me.wait ();

      ACE_Argv_Type_Converter main_args_c (argc, argv);

      CORBA::ORB_var corb =
        CORBA::ORB_init (main_args_c.get_argc (),
                         main_args_c.get_TCHAR_argv (),
                         "Client_ORB");

      {
        Client_Task client_task (ior_input_file,
                                 corb.in (),
                                 ACE_Thread_Manager::instance ());

        if (client_task.activate (THR_JOINABLE, 1, 1) == -1)
          {
            ACE_ERROR ((LM_ERROR, "Error activating client thread.\n"));
            return -1;
          }

        ACE_Thread_Manager::instance ()->wait ();
      }

      corb->destroy ();
    }
  catch (const CORBA::Exception&)
    {
      // ignore exceptions
    }

  ACE_DEBUG ((LM_DEBUG, "Threaded client ready.\n"));

  return 0;
}