Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / FL_Cube / server.cpp
blob83f74fac289fdcdb2c3c50aa97eba1a2f3d8b6f0
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/FlResource/FlResource_Loader.h"
5 #include <FL/Fl.H>
7 const ACE_TCHAR *ior_output_file = 0;
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 Fl_Window window(300, 300);
39 TAO::FlResource_Loader fl_loader;
41 Simple_Window sw (10, 10,
42 window.w () - 20, window.h () - 20);
43 window.resizable (&sw);
45 window.end ();
47 try
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv);
52 if (parse_args (argc, argv) != 0)
53 return 1;
55 char* targv[] = { ACE_TEXT_ALWAYS_CHAR (argv[0]) };
56 window.show (1, targv);
58 sw.show ();
60 CORBA::Object_var poa_object =
61 orb->resolve_initial_references("RootPOA");
63 if (CORBA::is_nil (poa_object.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Unable to initialize the POA.\n"),
66 1);
68 PortableServer::POA_var root_poa =
69 PortableServer::POA::_narrow (poa_object.in ());
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 Simple_Server_i server_impl (orb.in (), &sw);
76 PortableServer::ObjectId_var id =
77 root_poa->activate_object (&server_impl);
79 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
81 Simple_Server_var server =
82 Simple_Server::_narrow (object.in ());
84 CORBA::String_var ior =
85 orb->object_to_string (server.in ());
87 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
89 // If the ior_output_file exists, output the ior to it
90 if (ior_output_file != 0)
92 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s",
96 ior_output_file),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
102 poa_manager->activate ();
104 if (Fl::run () == -1)
105 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Fl::run"), -1);
106 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
108 catch (const CORBA::Exception& ex)
110 ex._tao_print_exception ("Caught exception:");
111 return 1;
113 return 0;