Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / DevGuideExamples / AMH_AMI / client.cpp
blob3a52873f2e0c595895ee889cf30c6f6fc243224a
1 #include "amh_ami_pch.h"
2 #include "ace/Get_Opt.h"
3 #include "middleC.h"
5 #include <iostream>
7 const ACE_TCHAR *ior_file = ACE_TEXT ("file://middle.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior_file = get_opts.opt_arg ();
20 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior_file> "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
36 try {
37 // Initialize the ORB.
38 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
40 if (parse_args (argc, argv) != 0)
41 return 1;
43 // Read and destringify the Asynch_Except_Demo object's IOR.
44 CORBA::Object_var obj = orb->string_to_object(ACE_TEXT_ALWAYS_CHAR(ior_file));
45 if( CORBA::is_nil( obj.in() ) ) {
46 std::cerr << "Could not get middle IOR." << std::endl;
47 return 1;
50 // Narrow the IOR to a Asycnh_Except_Demo object reference.
51 Middle_var mid = Middle::_narrow( obj.in() );
52 if( CORBA::is_nil( mid.in() ) ) {
53 std::cerr << "IOR was not an middle object reference." << std::endl;
54 return 1;
57 CORBA::String_var question =
58 CORBA::string_dup ("How much wood would a woodchuck chuck, if a woodchuck could chuck wood?");
60 std::cout << "Question is: " << question.in() << std::endl;
63 // trigger the exception via AMI call
64 CORBA::String_var answer =
65 mid->get_the_answer (question.in());
67 std::cout << "Answer is: " << answer.in() << std::endl;
69 return 0;
71 catch(const CORBA::Exception& ex) {
72 std::cerr << "CORBA exception: " << ex << std::endl;
75 return 1;