Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / MT_Dispatching / Structured_Consumer.cpp
blob911bb91a96dd714ad07bdc1f152a8cb1cc250ba0
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
7 #include "orbsvcs/CosNotifyCommC.h"
8 #include "orbsvcs/CosNamingC.h"
9 #include "Notify_Structured_Push_Consumer.h"
10 #include "goC.h"
11 #include "ace/OS_NS_sys_time.h"
13 #include "Notify_Test_Client.h"
15 // ******************************************************************
16 // Data Section
17 // ******************************************************************
19 static Notify_Structured_Push_Consumer* consumers[1024] = {0};
20 static const ACE_TCHAR *ior = ACE_TEXT ("file://supplier.ior");
21 static unsigned int consumer_count = 1;
22 static unsigned int expected = 1;
24 // ******************************************************************
25 // Subroutine Section
26 // ******************************************************************
28 class Consumer_Client : public Notify_Test_Client
30 public:
31 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
35 int
36 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
38 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:e:c:f"));
39 int c;
41 while ((c = get_opts ()) != -1)
42 switch (c)
44 case 'k':
45 ior = get_opts.optarg;
46 break;
48 case 'c':
49 consumer_count = ACE_OS::atoi (get_opts.optarg);
50 break;
52 case 'e':
53 expected = ACE_OS::atoi (get_opts.optarg);
54 break;
56 default:
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "usage: %s "
59 "-k <ior> "
60 "-c <# of consumers> "
61 "-e <expected events> "
62 "\n",
63 argv [0]),
64 -1);
66 // Indicates successful parsing of the command line
67 return 0;
71 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
72 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
74 CosNotifyChannelAdmin::AdminID adminid = 0;
75 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
76 ec->new_for_consumers (CosNotifyChannelAdmin::AND_OP,
77 adminid);
80 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
84 static void
85 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
86 Notify_Test_Client* client)
88 for (unsigned int i = 0; i < consumer_count; i++)
90 // startup the consumers
91 char name[64] = "";
92 ACE_OS::sprintf (name, "consumer%u", i);
93 ACE_NEW_THROW_EX (consumers[ i ],
94 Notify_Structured_Push_Consumer (
95 name,
96 expected,
97 *client),
98 CORBA::NO_MEMORY ());
100 consumers[ i ]->init (client->root_poa ());
102 consumers[ i ]->connect (admin);
106 static void
107 disconnect_consumers (void)
109 for (unsigned int i = 0; i < consumer_count; i++)
111 consumers[ i ]->disconnect ();
115 // ******************************************************************
116 // Main Section
117 // ******************************************************************
119 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
121 int status = 0;
124 Consumer_Client client;
126 status = client.init (argc, argv);
128 if (status == 0)
130 CosNotifyChannelAdmin::EventChannel_var ec =
131 client.create_event_channel ("MyEventChannel", 1);
133 CORBA::Object_var object =
134 client.orb ()->string_to_object (ior);
136 sig_var sig = sig::_narrow (object.in ());
138 if (CORBA::is_nil (sig.in ()))
140 ACE_ERROR_RETURN ((LM_ERROR,
141 "Object reference <%s> is nil\n",
142 ior),
146 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
147 create_consumeradmin (ec.in ());
149 if (!CORBA::is_nil (admin.in ()))
151 create_consumers (admin.in (), &client);
153 // Tell the supplier to go
154 sig->go ();
156 client.ORB_run( );
158 disconnect_consumers();
160 ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
161 sig->done ();
165 catch (const CORBA::Exception& e)
167 e._tao_print_exception ("Error: ");
168 status = 1;
171 return status;