Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Timeout / Structured_Consumer.cpp
blob6ff370a47a3bdec8cd73e93156a8afd9a6ebe5e1
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "sigC.h"
9 #include "Notify_Structured_Push_Consumer.h"
10 #include "Notify_Test_Client.h"
12 // ******************************************************************
13 // Data Section
14 // ******************************************************************
16 static const ACE_TCHAR* ior = ACE_TEXT("file://supplier.ior");
17 static unsigned int expected = 2;
18 static Notify_Structured_Push_Consumer* consumer_1 = 0;
20 class Consumer_Client : public Notify_Test_Client
22 public:
23 virtual int parse_args (int argc, ACE_TCHAR* argv[]);
27 int
28 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
30 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
31 int c;
33 while ((c = get_opts ()) != -1)
34 switch (c)
36 case 'k':
37 ior = get_opts.optarg;
38 break;
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-k <ior> "
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
53 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
54 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
56 CosNotifyChannelAdmin::AdminID adminid = 0;
57 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
58 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP, adminid);
60 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
64 static void
65 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
66 Notify_Test_Client* client)
68 // startup the consumer
69 ACE_NEW_THROW_EX (consumer_1,
70 Notify_Structured_Push_Consumer ("consumer1",
71 expected,
72 *client),
73 CORBA::NO_MEMORY ());
74 consumer_1->init (client->root_poa ());
75 consumer_1->_connect (admin);
78 // ******************************************************************
79 // Main Section
80 // ******************************************************************
82 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
84 int status = 0;
85 try
87 Consumer_Client client;
89 status = client.init (argc, argv);
90 if (status != 0)
91 ACE_ERROR_RETURN ((LM_ERROR, "Error: Client init failed.\n"),1);
93 CosNotifyChannelAdmin::EventChannel_var ec =
94 client.create_event_channel ("MyEventChannel", 1);
96 CORBA::ORB_ptr orb = client.orb ();
97 CORBA::Object_var object =
98 orb->string_to_object (ior);
100 sig_var sig = sig::_narrow (object.in ());
102 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
103 create_consumeradmin (ec.in ());
105 if (CORBA::is_nil (admin.in ()))
106 ACE_ERROR_RETURN ((LM_ERROR, "Error: nil ConsumerAdmin.\n"),1);
108 create_consumers (admin.in (), &client);
110 ACE_DEBUG ((LM_DEBUG, "\nConsumer waiting for events...\n"));
112 sig->go ();
113 ACE_Time_Value tv (5);
114 orb->run (tv);
116 ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
118 catch (const CORBA::Exception& e)
120 e._tao_print_exception ("Consumer Error: ");
121 status = 1;
124 return status;