Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_2935_Regression / sink.cpp
blob3677b28d347bbfcd259f54896958351b3d059b3b
1 #include "sink_i.h"
2 #include "ace/OS_NS_unistd.h"
4 const ACE_TCHAR * ior_output_file = 0;
6 void eat_args (int & argc, ACE_TCHAR *argv[], int argp, int how_many)
8 for (int marg = argp; marg + how_many < argc; ++marg)
10 argv[marg] = argv[marg + how_many];
12 argc -= how_many;
15 bool parse_args (int & argc, ACE_TCHAR *argv[])
17 int argp = 1;
18 while (argp < argc)
20 const ACE_TCHAR * arg = argv[argp];
21 if(arg[0] == '-' && arg[1] == 'o' && argp + 1 < argc)
23 if (ior_output_file != 0)
25 ACE_ERROR ((LM_DEBUG,
26 "Sink (%P|%t) duplicate -o options\n"));
27 return false;
29 // capture output file name
30 // then remove it from arguemnt list
31 ior_output_file = argv[argp + 1];
32 eat_args(argc, argv, argp, 2);
34 else
36 argp += 1;
37 // just ignore unknown arguments
40 if (ior_output_file == 0)
42 ACE_ERROR ((LM_DEBUG,
43 "Sink (%P|%t) missing required -o option\n"));
44 return false;
46 return true;
50 int
51 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
53 ACE_DEBUG ((LM_DEBUG,
54 "Sink (%P|%t) started\n"));
56 try
58 CORBA::ORB_var orb =
59 CORBA::ORB_init (argc,
60 argv);
62 if (!parse_args (argc, argv))
64 return -1;
66 CORBA::Object_var poa_object =
67 orb->resolve_initial_references ("RootPOA");
69 PortableServer::POA_var root_poa =
70 PortableServer::POA::_narrow (poa_object.in ());
72 PortableServer::POAManager_var poa_manager =
73 root_poa->the_POAManager ();
75 Sink_i sink (orb.in());
76 if (sink.parse_args (argc, argv) )
78 PortableServer::ObjectId_var id =
79 root_poa->activate_object (&sink);
81 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
83 ThreeTier_var server =
84 ThreeTier::_narrow (object.in ());
86 CORBA::String_var ior =
87 orb->object_to_string (server.in ());
89 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
90 if (output_file == 0)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "Cannot open output file for writing IOR: %s",
93 ior_output_file),
94 -1);
95 ACE_OS::fprintf (output_file, "%s", ior.in ());
96 ACE_OS::fclose (output_file);
98 poa_manager->activate ();
99 orb->run ();
102 catch (const CORBA::UserException& userex)
104 userex._tao_print_exception ("SINK: User Exception in main");
105 return -1;
107 catch (const CORBA::SystemException& sysex)
109 sysex._tao_print_exception ("SINK: System Exception in main");
110 return -1;
113 ACE_DEBUG ((LM_DEBUG,
114 "Sink (%P|%t) exits\n"));
116 return 0;