Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Smart_Proxies / dtor / server.cpp
blob2969f2471b83e9654e666acfa19c2f1c31cd0eab
1 #include "testS.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_string.h"
5 class Test_i: public virtual POA_Test
7 public:
8 Test_i (CORBA::ORB_ptr orb);
10 void hello (CORBA::Long howmany);
12 //FUZZ: disable check_for_lack_ACE_OS
13 void shutdown ();
14 //FUZZ: enable check_for_lack_ACE_OS
16 private:
17 CORBA::ORB_var orb_;
20 Test_i::Test_i (CORBA::ORB_ptr orb)
21 : orb_ (CORBA::ORB::_duplicate (orb))
25 void
26 Test_i::hello (CORBA::Long howmany)
28 ACE_DEBUG ((LM_DEBUG, "hello called with : %i\n", howmany));
31 void
32 Test_i::shutdown ()
34 this->orb_->shutdown (false);
37 static const ACE_TCHAR *ior_output_file = 0;
39 int
40 parse_args (int argc, ACE_TCHAR *argv[])
42 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
43 int c;
45 while ((c = get_opts ()) != -1)
46 switch (c)
48 case 'o':
49 ior_output_file = get_opts.opt_arg ();
50 break;
51 case '?':
52 default:
53 ACE_ERROR_RETURN ((LM_ERROR,
54 "usage: %s "
55 "-o <iorfile>"
56 "\n",
57 argv [0]),
58 -1);
60 // Indicates successful parsing of the command line
61 return 0;
64 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
66 try
68 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
70 if (parse_args (argc, argv) != 0)
71 return 1;
73 // Obtain RootPOA.
74 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
76 PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in());
78 // Get the POAManager of the RootPOA
79 PortableServer::POAManager_var poa_mgr =
80 root_poa->the_POAManager ();
82 poa_mgr->activate ();
84 // Create a servant
85 Test_i servant (orb.in ());
87 PortableServer::ObjectId_var oid =
88 root_poa->activate_object (&servant);
90 obj = root_poa->id_to_reference (oid.in());
92 CORBA::String_var ior =
93 orb->object_to_string (obj.in());
95 // If the ior_output_file exists, output the ior to it
96 if (ior_output_file != 0)
98 FILE *output_file =
99 ACE_OS::fopen (ior_output_file, "w");
101 if (output_file == 0)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "Cannot open output file %s for writing IOR: %C",
104 ior_output_file,
105 ior.in ()),
108 ACE_OS::fprintf (output_file, "%s", ior.in ());
109 ACE_OS::fclose (output_file);
111 else
112 ACE_ERROR_RETURN ((LM_ERROR,"ior file name is null\n"),1);
114 orb->run ();
116 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
118 root_poa->destroy (true, true);
120 orb->destroy ();
122 catch (const CORBA::Exception& ex)
124 ex._tao_print_exception ("Exception in setting up server");
125 return 1;
128 return 0;