=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / Bug_3506_Regression / server.cpp
blobe16cafeb09ef6e2d7789c0420626c6998048f262
1 #include "IF_EXE_M_R_StructsS.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 CORBA::ORB_var m_ORB_p;
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
36 class IF_Test_impl : public POA_IF_EXE_M_R::IF_ExeCtrlData
38 public:
39 virtual void
40 shutdown ()
42 m_ORB_p->shutdown (0);
45 virtual void
46 foo (const ::IF_EXE_M_R::Test_Struct &ts)
48 const IF_EXE_M_R::CORBA_FOOIInPlan *anUnion_p = new IF_EXE_M_R::CORBA_FOOIInPlan;
49 if (ts.whatEver >>= anUnion_p)
51 ACE_DEBUG((LM_DEBUG, "Any successfully marshalled\nAny is %@\nID: %C\nNAME: %C\nKIND: %d\n", &ts.whatEver,
52 ts.whatEver._tao_get_typecode()->id(),
53 ts.whatEver._tao_get_typecode()->name(),
54 ts.whatEver._tao_get_typecode()->kind()));
56 else
58 ACE_ERROR((LM_ERROR, "ERROR Any not successfully marshalled\nAny is %@\n", &ts.whatEver));
59 if (ts.whatEver._tao_get_typecode ()->kind () != CORBA::tk_null)
61 ACE_ERROR((LM_ERROR, "ID: %C\nNAME: %C\nKIND: %d\n",
62 ts.whatEver._tao_get_typecode()->id(),
63 ts.whatEver._tao_get_typecode()->name(),
64 ts.whatEver._tao_get_typecode()->kind()));
66 else
68 ACE_ERROR((LM_ERROR, "Typecode is NULL\nKIND: %d\n",
69 ts.whatEver._tao_get_typecode()->kind()));
75 class Main_C
77 public:
78 int Create (int argc, ACE_TCHAR *argv[]);
81 int
82 Main_C::Create (int argc, ACE_TCHAR *argv[])
84 try
86 // ENTER your code here ...
87 CORBA::Object_var obj = m_ORB_p->resolve_initial_references ("RootPOA");
89 if (parse_args (argc, argv) != 0)
90 return 1;
92 PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ());
94 PortableServer::POAManager_var mgr = poa->the_POAManager ();
95 mgr->activate ();
97 IF_Test_impl *servant = new IF_Test_impl;
99 PortableServer::ServantBase_var owner_transfer(servant);
101 PortableServer::ObjectId_var id =
102 poa->activate_object (servant);
104 CORBA::Object_var object = poa->id_to_reference (id.in ());
106 IF_EXE_M_R::IF_ExeCtrlData_var hello = IF_EXE_M_R::IF_ExeCtrlData::_narrow (object.in ());
108 CORBA::String_var ior = m_ORB_p->object_to_string (hello.in ());
110 // Output the IOR to the <ior_output_file>
111 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
112 if (output_file == 0)
113 ACE_ERROR_RETURN((LM_ERROR,
114 "Cannot open output file for writing IOR: %s\n",
115 ior_output_file),
117 ACE_OS::fprintf (output_file, "%s", ior.in ());
118 ACE_OS::fclose (output_file);
120 m_ORB_p->run ();
122 catch (const CORBA::Exception &ex)
124 ex._tao_print_exception ("Exception caught:");
125 return 1;
127 return 0;
131 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
133 m_ORB_p = CORBA::ORB_init (argc, argv);
135 Main_C main_cs;
136 return main_cs.Create (argc, argv);