Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / QtTests / server.cpp
blob8f9b685715f0cd90c7ed4f11dcf64209215e630f
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Argv_Type_Converter.h"
5 // who defines index macro?
6 #ifdef index
7 #undef index
8 #endif
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;
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'o':
28 ior_output_file = get_opts.opt_arg ();
29 break;
31 case '?':
32 default:
33 // ignore the first unknown option
34 return 0;
35 // ACE_ERROR_RETURN ((LM_ERROR,
36 // "usage: %s "
37 // "-o <iorfile>"
38 // "\n",
39 // argv [0]),
40 // -1);
42 // Indicates successful parsing of the command line
43 return 0;
46 int
47 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
49 // We do the command line parsing first
50 if (parse_args (argc, argv) != 0)
51 return 1;
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);
58 try
60 CORBA::ORB_var orb =
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"),
69 1);
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.
90 QWidget mainwindow_;
91 mainwindow_.resize (145, 100);
92 mainwindow_.setWindowTitle("QtServer");
94 QVBoxLayout *box = new QVBoxLayout();
95 QLCDNumber lcd (2);
96 box->addWidget(&lcd);
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)),
103 &lcd,
104 SLOT (display (int)));
106 mainwindow_.setLayout(box);
107 app.setActiveWindow(&(mainwindow_));
108 mainwindow_.show ();
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",
124 ior_output_file),
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..
133 app.exec ();
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Caught exception:");
138 return 1;
140 return 0;