Merge pull request #1815 from sonndinh/get_signal_info
[ACE_TAO.git] / TAO / interop-tests / wchar / server.cpp
blob6b94ed9fd3592aa3e76667142efb7cd697a97787
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file server.cpp
7 * C++ server side for testing interoperability with wchar data.
9 * @author Phil Mesnier <mesnier_p@ociweb.com>
11 //=============================================================================
13 #include "interop_wchar_i.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/Argv_Type_Converter.h"
16 #if defined (TAO_EXPLICIT_NEGOTIATE_CODESETS)
17 #include "tao/Codeset/Codeset.h"
18 #endif /* TAO_EXPLICIT_NEGOTIATE_CODESETS */
20 const ACE_TCHAR *ior_output_file = ACE_TEXT("IOR");
21 int verbose = 0;
23 int
24 parse_args (int argc, ACE_TCHAR* argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:v"));
28 int c;
30 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 'o':
34 ior_output_file = get_opts.opt_arg ();
35 break;
36 case 'v':
37 verbose = 1;
38 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-o <iorfile> "
44 "-v "
45 "\n",
46 argv [0]),
47 -1);
49 // Indicates successful parsing of the command line
50 return 0;
53 int
54 ACE_TMAIN( int argc, ACE_TCHAR *argv[] )
56 ACE_Argv_Type_Converter command_line(argc, argv);
58 #if (!defined ACE_HAS_WCHAR) && (!defined ACE_HAS_XPG4_MULTIBYTE_CHAR)
59 // the run_test script looks for the ior file. By touching it here, the
60 // script can run at full speed, rather than timing out waiting for a
61 // file that will never come.
62 FILE *output_file = ACE_OS::fopen (ior_output_file, ACE_TEXT("w"));
63 if (output_file == 0)
64 ACE_ERROR_RETURN ((LM_ERROR,
65 ACE_TEXT("Cannot open output file ")
66 ACE_TEXT("for writing IOR: %s"),
67 ior_output_file),
68 1);
69 ACE_OS::fprintf (output_file, "no ior\n");
70 ACE_OS::fclose (output_file);
71 ACE_ERROR_RETURN ((LM_ERROR,"This test requires wchar support\n"),0);
72 #else
73 try
75 // Initialize orb
76 CORBA::ORB_var orb =
77 CORBA::ORB_init(argc, argv);
78 if (parse_args(argc, argv))
80 ACE_ERROR_RETURN ((LM_ERROR,
81 ACE_TEXT ("failed to parse args")),
82 1);
85 //Get reference to Root POA
86 CORBA::Object_var obj =
87 orb->resolve_initial_references( "RootPOA");
89 PortableServer::POA_var poa =
90 PortableServer::POA::_narrow( obj.in());
92 PortableServer::POAManager_var mgr =
93 poa->the_POAManager( );
95 // Activate POA Manager
96 mgr->activate( );
98 // Create an object
99 interop_WChar_Passer_i servant(orb.in(), verbose);
101 // Register the servant with the RootPOA, obtain its object
102 // reference, stringify it, and write it to a file.
103 obj = poa->servant_to_reference(&servant);
105 CORBA::String_var str =
106 orb->object_to_string( obj.in());
108 FILE *output_file = ACE_OS::fopen (ior_output_file, ACE_TEXT("w"));
109 if (output_file == 0)
110 ACE_ERROR_RETURN ((LM_ERROR,
111 ACE_TEXT("Cannot open output file ")
112 ACE_TEXT("for writing IOR: %s"),
113 ior_output_file),
115 ACE_OS::fprintf (output_file, "%s", str.in ());
116 ACE_OS::fclose (output_file);
118 // Accept requests
119 orb->run( );
120 orb->destroy( );
122 catch (const CORBA::Exception& ex)
124 ex._tao_print_exception ("uncaught exception");
125 return 1;
128 return 0;
129 #endif /* ACE_HAS_WCHAR */