Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / interop-tests / wchar / server.cpp
blobf855f940610dd9220ece34f79afd2aa964dd9f1e
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[])
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:v"));
27 int c;
29 while ((c = get_opts ()) != -1)
30 switch (c)
32 case 'o':
33 ior_output_file = get_opts.opt_arg ();
34 break;
35 case 'v':
36 verbose = 1;
37 break;
38 case '?':
39 default:
40 ACE_ERROR_RETURN ((LM_ERROR,
41 "usage: %s "
42 "-o <iorfile> "
43 "-v "
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN( int argc, ACE_TCHAR *argv[] )
55 ACE_Argv_Type_Converter command_line(argc, argv);
57 #if (!defined ACE_HAS_WCHAR) && (!defined ACE_HAS_XPG4_MULTIBYTE_CHAR)
58 // the run_test script looks for the ior file. By touching it here, the
59 // script can run at full speed, rather than timing out waiting for a
60 // file that will never come.
61 FILE *output_file = ACE_OS::fopen (ior_output_file, ACE_TEXT("w"));
62 if (output_file == 0)
63 ACE_ERROR_RETURN ((LM_ERROR,
64 ACE_TEXT("Cannot open output file ")
65 ACE_TEXT("for writing IOR: %s"),
66 ior_output_file),
67 1);
68 ACE_OS::fprintf (output_file, "no ior\n");
69 ACE_OS::fclose (output_file);
70 ACE_ERROR_RETURN ((LM_ERROR,"This test requires wchar support\n"),0);
71 #else
72 try
74 // Initialize orb
75 CORBA::ORB_var orb =
76 CORBA::ORB_init(argc, argv);
77 if (parse_args(argc, argv))
79 ACE_ERROR_RETURN ((LM_ERROR,
80 ACE_TEXT ("failed to parse args")),
81 1);
84 //Get reference to Root POA
85 CORBA::Object_var obj =
86 orb->resolve_initial_references( "RootPOA");
88 PortableServer::POA_var poa =
89 PortableServer::POA::_narrow( obj.in());
91 PortableServer::POAManager_var mgr =
92 poa->the_POAManager( );
94 // Activate POA Manager
95 mgr->activate( );
97 // Create an object
98 interop_WChar_Passer_i servant(orb.in(), verbose);
100 // Register the servant with the RootPOA, obtain its object
101 // reference, stringify it, and write it to a file.
102 obj = poa->servant_to_reference(&servant);
104 CORBA::String_var str =
105 orb->object_to_string( obj.in());
107 FILE *output_file = ACE_OS::fopen (ior_output_file, ACE_TEXT("w"));
108 if (output_file == 0)
109 ACE_ERROR_RETURN ((LM_ERROR,
110 ACE_TEXT("Cannot open output file ")
111 ACE_TEXT("for writing IOR: %s"),
112 ior_output_file),
114 ACE_OS::fprintf (output_file, "%s", str.in ());
115 ACE_OS::fclose (output_file);
117 // Accept requests
118 orb->run( );
119 orb->destroy( );
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("uncaught exception");
124 return 1;
127 return 0;
128 #endif /* ACE_HAS_WCHAR */