=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / DII_Discard_Deferred / client.cpp
blobbaa645a9cd415633d7b66408a88f8ef9d97a1926
1 // -*- C++ -*-
2 #include "tao/DynamicInterface/Request.h"
3 #include "tao/DynamicInterface/DII_CORBA_methods.h"
4 #include "TestC.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-k <ior> "
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
43 if (parse_args (argc, argv) != 0)
44 return 1;
46 CORBA::Object_var obj = orb->string_to_object(ior);
48 const char* the_string = 0;
50 ACE_DEBUG ((LM_INFO, "(%P|%t) - #### Deferred twoway DII (using get_response())\n"));
52 CORBA::Request_var req = obj->_request ("get_string");
53 req->set_return_type (CORBA::_tc_string);
55 req->send_deferred ();
56 ACE_DEBUG ((LM_INFO, "(%P|%t) - Get response...\n"));
57 req->get_response ();
58 req->return_value () >>= the_string;
60 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
61 the_string));
62 ACE_DEBUG ((LM_INFO, "(%P|%t) - #### Deferred twoway DII (using poll_response())\n"));
64 req = obj->_request ("get_string");
65 req->set_return_type (CORBA::_tc_string);
67 req->send_deferred ();
68 do {
69 ACE_OS::sleep(1);
70 ACE_DEBUG ((LM_INFO, "(%P|%t) - Polling...\n"));
71 } while (!req->poll_response ());
72 req->return_value () >>= the_string;
74 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
75 the_string));
77 ACE_DEBUG ((LM_INFO, "(%P|%t) - #### Deferred twoway DII with discarded request\n"));
79 req = obj->_request ("get_string");
80 req->set_return_type (CORBA::_tc_string);
82 req->send_deferred ();
83 ACE_DEBUG ((LM_INFO, "(%P|%t) - Discarding request and waiting 5 seconds\n"));
85 // simulate a lot of other activity messing up dynamic memory
86 req = CORBA::Request::_nil ();
87 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - discarded\n"));
88 for (int i=0; i<50 ;++i)
90 ACE_Time_Value tv(0, 100000);
91 orb->perform_work (tv);
92 ACE_OS::sleep (tv); // sleep the rest if any
94 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - continue\n"));
97 ACE_DEBUG ((LM_INFO, "(%P|%t) - #### Oneway shutdown DII\n"));
99 req = obj->_request ("shutdown");
100 req->send_oneway ();
102 orb->destroy ();
104 catch (const CORBA::Exception& ex)
106 ex._tao_print_exception ("Exception caught:");
107 return 1;
110 return 0;