Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Multiple_Inheritance / client.cpp
blobcc12876cb2a92066033b297efc0d29a84c57f5dc
1 //=============================================================================
2 /**
3 * @file client.cpp
5 * A client program for the Multiple Inheritance module
7 * @author Irfan Pyarali
8 */
9 //=============================================================================
12 #include "ace/Get_Opt.h"
13 #include "ace/Read_Buffer.h"
14 #include "Multiple_InheritanceC.h"
15 #include "ace/OS_NS_fcntl.h"
16 #include "ace/OS_NS_unistd.h"
17 #include "ace/OS_NS_string.h"
19 static ACE_TCHAR *ior = 0;
20 static ACE_TCHAR *ior_input_file = 0;
22 static int
23 parse_args (int argc, ACE_TCHAR **argv)
25 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:f:"));
26 int c;
28 while ((c = get_opts ()) != -1)
29 switch (c)
31 case 'k':
32 ior = get_opts.opt_arg ();
33 break;
34 case 'f':
35 ior_input_file = get_opts.opt_arg ();
36 break;
37 case '?':
38 default:
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "\nusage: %s "
41 "-i <ior_input_file> "
42 "-k IOR "
43 "\n",
44 argv [0]),
45 -1);
48 if (ior == 0 && ior_input_file == 0)
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "\nPlease specify the IOR or IOR input file"
51 " for the servant"),
52 -1);
53 if (ior != 0 && ior_input_file != 0)
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "\nPlease specify only an IOR or only an IOR"
56 " input file but not both"),
57 -1);
59 // Indicates successful parsing of the command line.
60 return 0;
63 int
64 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
66 try
68 // Initialize the ORB
69 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
71 // Parse the command-line arguments to get the IOR
72 parse_args (argc, argv);
74 // If ior_input_file exists, Read the file, and get the IOR
75 // else, it must have been specified on the command line
76 if (ior_input_file != 0)
78 ACE_HANDLE input_file = ACE_OS::open (ior_input_file, 0);
79 if (input_file == ACE_INVALID_HANDLE)
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "Cannot open input file for reading IOR: %s\n",
82 ior_input_file),
83 -1);
84 ACE_Read_Buffer ior_buffer (input_file);
85 char *data = ior_buffer.read ();
86 if (data == 0)
87 ACE_ERROR_RETURN ((LM_ERROR,
88 "Unable to read ior\n"),
89 -1);
90 ior = ACE_OS::strdup (ACE_TEXT_CHAR_TO_TCHAR(data));
91 ior_buffer.alloc ()->free (data);
92 ACE_OS::close (input_file);
95 // Get the object reference with the IOR
96 CORBA::Object_var object = orb->string_to_object (ior);
98 CORBA::String_var string;
100 // Narrow the object reference
101 A_var a = A::_narrow (object.in ());
103 // Narrow the object reference
104 intB_var b = intB::_narrow (a.in ());
106 // Narrow the object reference
107 C_var c = C::_narrow (a.in ());
109 // Narrow the object reference
110 D_var d = D::_narrow (c.in ());
112 string = a->method1 ();
113 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
115 string = b->method1 ();
116 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
118 string = b->method2 ();
119 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
121 string = c->method1 ();
122 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
124 string = c->method3 ();
125 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
127 string = d->method1 ();
128 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
130 string = d->method2 ();
131 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
133 string = d->method3 ();
134 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
136 string = d->method4 ();
137 ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ()));
139 catch (const CORBA::Exception& ex)
141 ex._tao_print_exception ("client");
142 return 1;
145 return 0;