Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_2935_Regression / source.cpp
blob2c47c3ebe4719afb22176d9f0006cd8d337520da
1 # include "source_i.h"
3 // A ThreeTier client that calls tick and/or tock
5 const ACE_TCHAR * ior_input_file = 0;
7 char input_ior[5000];
9 void eat_args (int & argc, ACE_TCHAR *argv[], int argp, int how_many)
11 for (int marg = argp; marg + how_many < argc; ++marg)
13 argv[marg] = argv[marg + how_many];
15 argc -= how_many;
18 bool parse_args (int & argc, ACE_TCHAR *argv[])
20 int argp = 1;
21 while (argp < argc)
23 const ACE_TCHAR* arg = argv[argp];
24 if(arg[0] == '-' && arg[1] == 'f' && argp + 1 < argc)
26 if (ior_input_file != 0)
28 ACE_ERROR ((LM_DEBUG,
29 "Sink (%P|%t) duplicate -f options\n"));
30 return false;
32 // capture input file name
33 // then remove it from arguemnt list
34 ior_input_file = argv[argp + 1];
35 eat_args (argc, argv, argp, 2);
37 else
39 argp += 1;
40 // just ignore unknown arguments
43 if (ior_input_file == 0)
45 ACE_ERROR ((LM_DEBUG,
46 "Sink (%P|%t) missing required -f option\n"));
47 return false;
49 return true;
54 int
55 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
57 int result = 0;
58 ACE_DEBUG ((LM_DEBUG,
59 "Source (%P|%t) started\n"));
60 try
62 // Initialize the ORB.
63 CORBA::ORB_var orb =
64 CORBA::ORB_init (argc, argv);
66 // Initialize options based on command-line arguments.
67 if (!parse_args (argc, argv))
69 return -1;
72 FILE *input_file = ACE_OS::fopen (ior_input_file, "r");
73 if (input_file == 0)
75 ACE_ERROR_RETURN ((LM_ERROR,
76 "Cannot open input IOR file: %s",
77 ior_input_file),
78 -1);
80 ACE_OS::fread (input_ior, 1, sizeof(input_ior), input_file);
81 ACE_OS::fclose (input_file);
83 // Convert the IOR to an object reference.
84 CORBA::Object_var object =
85 orb->string_to_object (input_ior);
87 // narrow the object reference to a ThreeTier reference
88 ThreeTier_var server = ThreeTier::_narrow (object.in ());
90 if (CORBA::is_nil (server.in ()))
92 ACE_ERROR_RETURN ((LM_ERROR,
93 "IOR does not refer to a ThreeTier implementation"),
94 -1);
97 Source_i source (server.in ());
98 result = source.run();
100 catch (const CORBA::Exception& ex)
102 ex._tao_print_exception ("Exception caught:");
103 result = -1;
106 ACE_DEBUG ((LM_DEBUG,
107 "Source (%P|%t) exits\n"));
108 return result;