2 #include "ace/Get_Opt.h"
3 #include "ace/Argv_Type_Converter.h"
5 // who defines index macro?
9 #include "tao/QtResource/QtResource_Loader.h"
10 #include <QtGui/qlcdnumber.h>
11 #include <QtGui/qboxlayout.h>
12 #include <QtGui/qslider.h>
13 #include "ace/OS_NS_stdio.h"
16 const ACE_TCHAR
*ior_output_file
= 0;
19 parse_args (int argc
, ACE_TCHAR
*argv
[])
21 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
24 while ((c
= get_opts ()) != -1)
28 ior_output_file
= get_opts
.opt_arg ();
33 // ignore the first unknown option
35 // ACE_ERROR_RETURN ((LM_ERROR,
42 // Indicates successful parsing of the command line
47 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
49 // We do the command line parsing first
50 if (parse_args (argc
, argv
) != 0)
53 // Qt specific stuff for running with TAO...
54 ACE_Argv_Type_Converter
ct (argc
, argv
);
55 QApplication
app (argc
, ct
.get_ASCII_argv());
56 TAO::QtResource_Loader
qt_resources (&app
);
61 CORBA::ORB_init (argc
, argv
);
63 CORBA::Object_var poa_object
=
64 orb
->resolve_initial_references ("RootPOA");
66 if (CORBA::is_nil (poa_object
.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 " (%P|%t) Unable to initialize the POA.\n"),
71 PortableServer::POA_var root_poa
=
72 PortableServer::POA::_narrow (poa_object
.in ());
74 PortableServer::POAManager_var poa_manager
=
75 root_poa
->the_POAManager ();
77 // Create the Qt stuff..
78 // Instantiate the LCD_Display implementation class
79 LCD_Display_imp
display_impl (orb
.in ());
81 PortableServer::ObjectId_var id
=
82 root_poa
->activate_object (&display_impl
);
84 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
86 LCD_Display_var server
=
87 LCD_Display::_narrow (object
.in ());
89 // Create the LCD after the QVbox is created.
91 mainwindow_
.resize (145, 100);
92 mainwindow_
.setWindowTitle("QtServer");
94 QVBoxLayout
*box
= new QVBoxLayout();
98 // Connect the signal from the hosted servant with the public
99 // SLOT method display () for the LCD Widget.
101 QObject::connect (&display_impl
,
102 SIGNAL (set_value (int)),
104 SLOT (display (int)));
106 mainwindow_
.setLayout(box
);
107 app
.setActiveWindow(&(mainwindow_
));
110 // End of QT specific stuff..
112 CORBA::String_var ior
=
113 orb
->object_to_string (server
.in ());
115 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
117 // If the ior_output_file exists, output the ior to it
118 if (ior_output_file
!= 0)
120 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
121 if (output_file
== 0)
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 "Cannot open output file for writing IOR: %s",
126 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
127 ACE_OS::fclose (output_file
);
130 poa_manager
->activate ();
132 // We choose to run the main Qt event loop..
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Caught exception:");