Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / AMI / FL_Callback / progress.cpp
blob0408df003477224ce0034de712d1e14953e73ebb
1 #include "Progress_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/FlResource/FlResource_Loader.h"
6 #include <FL/Fl.H>
7 #include <FL/Fl_Window.H>
9 const ACE_TCHAR *ior_output_file = ACE_TEXT("progress.ior");
10 int n_iterations = 1000;
11 int n_peers = 1;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:p:i:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
26 case 'p':
27 n_peers = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
30 case 'i':
31 n_iterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-o <iorfile>"
39 "-p <peers>"
40 "-i <iterations>"
41 "\n",
42 argv [0]),
43 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 TAO::FlResource_Loader fl_loader;
53 try
55 CORBA::ORB_var orb =
56 CORBA::ORB_init (argc, argv);
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 int w = 320;
62 int h = 30 * n_peers + 20;
63 Fl_Window window(w, h);
65 Progress_Window sw (n_peers, n_iterations,
66 10,
67 10,
68 window.w () - 20,
69 window.h () - 20);
70 window.resizable (&sw);
72 window.end ();
74 char* targv[] = { ACE_TEXT_ALWAYS_CHAR (argv[0]) };
75 window.show (1, targv);
77 sw.show ();
79 CORBA::Object_var poa_object =
80 orb->resolve_initial_references("RootPOA");
82 if (CORBA::is_nil (poa_object.in ()))
83 ACE_ERROR_RETURN ((LM_ERROR,
84 " (%P|%t) Unable to initialize the POA.\n"),
85 1);
87 PortableServer::POA_var root_poa =
88 PortableServer::POA::_narrow (poa_object.in ());
90 PortableServer::POAManager_var poa_manager =
91 root_poa->the_POAManager ();
93 poa_manager->activate ();
95 Progress_i server_impl (&sw);
97 Progress_var server =
98 server_impl._this ();
100 CORBA::String_var ior =
101 orb->object_to_string (server.in ());
103 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
105 // If the ior_output_file exists, output the ior to it
106 if (ior_output_file != 0)
108 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
109 if (output_file == 0)
110 ACE_ERROR_RETURN ((LM_ERROR,
111 "Cannot open output file for writing IOR: %s",
112 ior_output_file),
114 ACE_OS::fprintf (output_file, "%s", ior.in ());
115 ACE_OS::fclose (output_file);
118 if (Fl::run () == -1)
119 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Fl::run"), -1);
120 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
122 catch (const CORBA::Exception& ex)
124 ex._tao_print_exception ("Caught exception:");
125 return 1;
127 return 0;