Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_1869_Regression / client.cpp
bloba4187f33b6fb09fb8989d385b5fb23cfc9d57751
1 #include "AMIS.h"
2 #include "ace/Task.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR *hostname = ACE_TEXT ("localhost");
7 const ACE_TCHAR *port = ACE_TEXT ("12345");
9 class AdderCallback
10 : public POA_AMI_test::AMI_adderHandler,
11 public ACE_Task_Base {
12 public:
13 AdderCallback(CORBA::ORB_ptr orb)
14 : orb(CORBA::ORB::_duplicate(orb)) {
15 activate();
18 virtual void add (
19 CORBA::Long ami_return_val
22 ACE_DEBUG ((LM_DEBUG, "Return value: %d\n", ami_return_val));
25 virtual void add_excep (
26 ::Messaging::ExceptionHolder *
29 ACE_DEBUG ((LM_DEBUG, "Caught exception in _excep\n"));
32 virtual int svc() {
33 orb->run();
35 return 0;
38 CORBA::ORB_var orb;
41 int
42 parse_args (int argc, ACE_TCHAR *argv[])
44 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("h:p:"));
45 int c;
47 while ((c = get_opts ()) != -1)
48 switch (c)
50 case 'h':
51 hostname = get_opts.opt_arg ();
52 break;
53 case 'p':
54 port = get_opts.opt_arg ();
55 break;
56 case '?':
57 default:
58 ACE_ERROR_RETURN ((LM_ERROR,
59 "usage: %s "
60 "-h <hostname> "
61 "-p <port> "
62 "\n",
63 argv [0]),
64 -1);
66 // Indicates successful parsing of the command line
67 return 0;
71 int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) {
72 ACE_TCHAR address_servant[1000];
74 try {
75 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
77 if (parse_args (argc, argv) != 0)
78 return 1;
79 // Get reference to Root POA
80 CORBA::Object_var obj
81 = orb->resolve_initial_references ("RootPOA");
83 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (obj.in ());
85 // Activate POA manager
86 PortableServer::POAManager_var mgr
87 = rootPOA->the_POAManager ();
89 mgr->activate();
91 ACE_OS::sprintf(address_servant, ACE_TEXT("corbaloc:iiop:%s:%s/Adder"), hostname, port);
93 // Resolve Adder Reference
94 obj = orb->string_to_object(ACE_TEXT_ALWAYS_CHAR(address_servant));
95 AMI_test::adder_var adder = AMI_test::adder::_narrow(obj.in ());
97 AdderCallback cb_servant(orb.in ());
99 while(true) {
102 adder->sendc_add(cb_servant._this(), 3, 2);
104 catch(...)
106 ACE_ERROR ((LM_ERROR, "ERROR: Caught exception after sendc_add\n"));
108 ACE_OS::sleep (1);
111 catch(...)
113 ACE_ERROR ((LM_ERROR, "ERROR: Caught exception in main\n"));
114 return 1;
117 return 0;