1 //=============================================================================
5 * A client program for the Multiple Inheritance module
7 * @author Irfan Pyarali
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;
23 parse_args (int argc
, ACE_TCHAR
**argv
)
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:f:"));
28 while ((c
= get_opts ()) != -1)
32 ior
= get_opts
.opt_arg ();
35 ior_input_file
= get_opts
.opt_arg ();
39 ACE_ERROR_RETURN ((LM_ERROR
,
41 "-i <ior_input_file> "
48 if (ior
== 0 && ior_input_file
== 0)
49 ACE_ERROR_RETURN ((LM_ERROR
,
50 "\nPlease specify the IOR or IOR input file"
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"),
59 // Indicates successful parsing of the command line.
64 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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",
84 ACE_Read_Buffer
ior_buffer (input_file
);
85 char *data
= ior_buffer
.read ();
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 "Unable to read ior\n"),
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");