Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_2561_Regression / Consumer.cpp
blob8a8f2e3a0e6feecf7e018c257da543ec0a2f624b
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "Notify_Push_Consumer.h"
6 #include "goC.h"
7 #include "Notify_Test_Client.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/Argv_Type_Converter.h"
12 // ******************************************************************
13 // Data Section
14 // ******************************************************************
16 static const ACE_TCHAR* ior = ACE_TEXT ("file://supplier.ior");
17 static Notify_Sequence_Push_Consumer* consumer_1;
18 static bool go = false;
20 // ******************************************************************
21 // Subroutine Section
22 // ******************************************************************
24 class Consumer_Client : public Notify_Test_Client
26 public:
27 virtual int parse_args (int argc, ACE_TCHAR* argv[]);
31 int
32 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
34 ACE_Argv_Type_Converter argcon (argc, argv);
35 ACE_Get_Opt get_opts (argcon.get_argc (),
36 argcon.get_TCHAR_argv (), ACE_TEXT ("gk:"));
37 int c;
39 while ((c = get_opts ()) != -1)
40 switch (c)
42 case 'g':
43 go = true;
44 break;
45 case 'k':
46 ior = get_opts.optarg;
47 break;
49 default:
50 ACE_ERROR_RETURN ((LM_ERROR,
51 "usage: %s "
52 "-g "
53 "-k <ior> "
54 "\n",
55 argv [0]),
56 -1);
58 // Indicates successful parsing of the command line
59 return 0;
63 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
64 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
66 CosNotifyChannelAdmin::AdminID adminid = 0;
67 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
68 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
69 adminid);
72 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
76 static void
77 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
78 Notify_Test_Client* client)
80 // startup the consumer
81 ACE_NEW_THROW_EX (consumer_1,
82 Notify_Sequence_Push_Consumer (*client),
83 CORBA::NO_MEMORY ());
84 consumer_1->init (client->root_poa ());
86 consumer_1->_connect (admin);
89 // ******************************************************************
90 // Main Section
91 // ******************************************************************
93 int
94 ACE_TMAIN (int argc, ACE_TCHAR* argv[])
96 int status = 0;
97 try
99 Consumer_Client client;
100 ACE_Argv_Type_Converter argcon (argc, argv);
101 status = client.init (argcon.get_argc (), argcon.get_TCHAR_argv ());
103 if (status == 0)
105 CosNotifyChannelAdmin::EventChannel_var ec =
106 client.create_event_channel ("MyEventChannel", 1);
108 CORBA::ORB_ptr orb = client.orb ();
109 CORBA::Object_var object =
110 orb->string_to_object (ior);
112 sig_var sig = sig::_narrow (object.in ());
114 if (CORBA::is_nil (sig.in ()))
116 ACE_ERROR_RETURN ((LM_ERROR,
117 "Object reference <%s> is nil\n",
118 ior),
122 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
123 create_consumeradmin (ec.in ());
125 if (!CORBA::is_nil (admin.in ()))
127 create_consumers (admin.in (), &client);
128 if (go)
130 // Tell the supplier to go
131 sig->go ();
134 ACE_DEBUG ((LM_DEBUG, "Consumer waiting for events...\n"));
136 client.ORB_run ();
138 ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
139 consumer_1->disconnect ();
141 if (go)
143 sig->done ();
148 catch (const CORBA::Exception& e)
150 e._tao_print_exception ("Error: ");
151 status = 1;
154 return status;