summaryrefslogtreecommitdiff
path: root/TAO/tests/Explicit_Event_Loop/client.cpp
blob: 984dcbc34c6deba800d4d79f8d719fba2219ddc5 (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
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Explicit_Event_Loop
//
// = FILENAME
//    client.cpp
//
// = AUTHORS
//   Source code used in TAO has been modified and adapted from the
//   code provided in the book, "Advanced CORBA Programming with C++"
//   by Michi Henning and Steve Vinoski. Copyright
//   1999. Addison-Wesley, Reading, MA.  Used with permission of
//   Addison-Wesley.
//
//   Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
//
// ============================================================================

#include "timeC.h"

// The following header is #included automatically by ACE+TAO.
// Therefore, they don't need to be included explicitly.
//#include <iostream.h>
//#include <iomanip.h>

int
main (int argc, char *argv[])
{
  TAO_ENV_DECLARE_NEW_ENV;
  ACE_TRY
    {
      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            ""
                                            TAO_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Check arguments.
      if  (argc != 2)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Usage: client IOR_string\n"),
                            1);
        }

      // Destringify argv[1].
      CORBA::Object_var obj = orb->string_to_object (argv[1]
                                                     TAO_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if  (CORBA::is_nil (obj.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Nil Time reference\n"),
                            1);
        }

      // Narrow.
      Time_var tm = Time::_narrow (obj.in ()
                                   TAO_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if  (CORBA::is_nil (tm.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Argument is not a Time reference\n"),
                            1);
        }

      // Get time.
      TimeOfDay tod = tm->get_gmt (TAO_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                  "%s%s%d:%s%d:%d\n",
                  "Time in Greenwich is ",
                  tod.hour < 10 ? "0" : "",
                  tod.hour,
                  tod.minute < 10 ? "0" : "",
                  tod.minute,
                  tod.second));
    }

  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "client: a CORBA exception occured");
      return 1;
    }
  ACE_CATCHALL
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "client: an unknown exception was caught\n"),
                        1);
    }
  ACE_ENDTRY;

  ACE_CHECK_RETURN (-1);
  return 0;
}