Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_2678_Regression / server.cpp
blobf1b3a445bd837db18c640832dc46bb7fee0dc917
1 #include "testS.h"
3 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
5 class Test_impl : public virtual POA_Test
7 public:
8 Test_impl (CORBA::ORB_ptr orb);
9 virtual AnySeq *RunTest(const AnySeq &params);
11 //FUZZ: disable check_for_lack_ACE_OS
12 virtual void shutdown ();
13 //FUZZ: enable check_for_lack_ACE_OS
14 private:
15 CORBA::ORB_var orb_;
18 Test_impl::Test_impl (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb))
22 void
23 Test_impl::shutdown()
25 this->orb_->shutdown (false);
28 AnySeq *Test_impl::RunTest(const AnySeq &params)
30 ACE_DEBUG ((LM_DEBUG, "RunTest: params.length == %d\n", params.length()));
31 for (CORBA::ULong count = 0; count < params.length(); ++count)
33 const Container* container = 0;
34 if (!(params[count] >>= container))
36 ACE_ERROR ((LM_ERROR, "ERROR, failed extract\n"));
38 else
40 const Inner* inner = 0;
41 if (!(container->contents >>= inner))
43 ACE_ERROR ((LM_ERROR, "ERROR, failed extract\n"));
45 else
46 ACE_DEBUG ((LM_DEBUG, "%d %d %d %d %d\n", inner->value1, inner->value2, inner->value3, inner->value4, inner->value5));
50 AnySeq *result = new AnySeq(params);
51 return result;
54 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
56 try
58 // Initialize orb
59 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
61 // Get reference to Root POA.
62 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
63 PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ());
64 PortableServer::POAManager_var mgr = root_poa->the_POAManager ();
66 PortableServer::LifespanPolicy_var lifespan =
67 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
68 CORBA::PolicyList policy_list;
69 policy_list.length (1);
70 policy_list[0] = PortableServer::LifespanPolicy::_duplicate (
71 lifespan.in ());
72 PortableServer::POA_var persistent_poa =
73 root_poa->create_POA ("PersistentPOA", mgr.in (),
74 policy_list);
75 lifespan->destroy ();
77 Test_impl *test_servant = 0;
78 ACE_NEW_RETURN (test_servant,
79 Test_impl (orb.in ()),
80 1);
81 PortableServer::ServantBase_var receiver_owner_transfer(test_servant);
83 PortableServer::ObjectId_var id =
84 persistent_poa->activate_object (test_servant);
86 obj =
87 persistent_poa->id_to_reference (id.in ());
89 CORBA::String_var ior = orb->object_to_string (obj.in ());
91 // Output the IOR to the <ior_output_file>
92 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s\n",
96 ior_output_file),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
101 // Activate POA manager
102 mgr->activate ();
104 // Accept requests
105 orb->run ();
107 catch (const CORBA::Exception &ex)
109 ex._tao_print_exception ("Exception caught: ");
110 return 1;
112 return 0;