Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2935_Regression / source.cpp
blob8b688662a21a07a9ec6898a5bb1455de74834cec
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;
53 int
54 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
56 int result = 0;
57 ACE_DEBUG ((LM_DEBUG,
58 "Source (%P|%t) started\n"));
59 try
61 // Initialize the ORB.
62 CORBA::ORB_var orb =
63 CORBA::ORB_init (argc, argv);
65 // Initialize options based on command-line arguments.
66 if (!parse_args (argc, argv))
68 return -1;
71 FILE *input_file = ACE_OS::fopen (ior_input_file, "r");
72 if (input_file == 0)
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "Cannot open input IOR file: %s",
76 ior_input_file),
77 -1);
79 ACE_OS::fread (input_ior, 1, sizeof(input_ior), input_file);
80 ACE_OS::fclose (input_file);
82 // Convert the IOR to an object reference.
83 CORBA::Object_var object =
84 orb->string_to_object (input_ior);
86 // narrow the object reference to a ThreeTier reference
87 ThreeTier_var server = ThreeTier::_narrow (object.in ());
89 if (CORBA::is_nil (server.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "IOR does not refer to a ThreeTier implementation"),
93 -1);
96 Source_i source (server.in ());
97 result = source.run();
99 catch (const CORBA::Exception& ex)
101 ex._tao_print_exception ("Exception caught:");
102 result = -1;
105 ACE_DEBUG ((LM_DEBUG,
106 "Source (%P|%t) exits\n"));
107 return result;