1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "orbsvcs/CosNotifyCommC.h"
9 #include "orbsvcs/CosNamingC.h"
10 #include "orbsvcs/TimeBaseC.h"
11 #include "Notify_Structured_Push_Consumer.h"
14 #include "Notify_Test_Client.h"
16 // ******************************************************************
18 // ******************************************************************
20 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
21 static unsigned int expected
= 10;
22 static Notify_Structured_Push_Consumer
* consumer_1
= 0;
24 class Consumer_Client
: public Notify_Test_Client
27 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
32 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
34 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:e:"));
37 while ((c
= get_opts ()) != -1)
41 ior
= get_opts
.optarg
;
45 expected
= ACE_OS::atoi (get_opts
.optarg
);
49 ACE_ERROR_RETURN ((LM_ERROR
,
52 "-e <expected events> "
57 // Indicates successful parsing of the command line
62 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
63 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
65 CosNotifyChannelAdmin::AdminID adminid
= 0;
66 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
67 ec
->new_for_consumers (CosNotifyChannelAdmin::OR_OP
, adminid
);
69 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
74 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
75 Notify_Test_Client
* client
)
77 // startup the consumer
78 ACE_NEW_THROW_EX (consumer_1
,
79 Notify_Structured_Push_Consumer ("consumer1",
83 consumer_1
->init (client
->root_poa ());
84 consumer_1
->_connect (admin
);
87 // ******************************************************************
89 // ******************************************************************
91 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
96 Consumer_Client client
;
98 status
= client
.init (argc
, argv
);
100 ACE_ERROR_RETURN ((LM_ERROR
, "Error: Client init failed.\n"),1);
102 CosNotifyChannelAdmin::EventChannel_var ec
=
103 client
.create_event_channel ("MyEventChannel", 1);
105 CORBA::ORB_ptr orb
= client
.orb ();
106 CORBA::Object_var object
=
107 orb
->string_to_object (ior
);
109 sig_var sig
= sig::_narrow (object
.in ());
111 if (CORBA::is_nil (sig
.in ()))
112 ACE_ERROR_RETURN ((LM_ERROR
, "Error: Narrow failed.\n"),1);
114 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
115 create_consumeradmin (ec
.in ());
117 if (CORBA::is_nil (admin
.in ()))
118 ACE_ERROR_RETURN ((LM_ERROR
, "Error: nil ConsumerAdmin.\n"),1);
120 create_consumers (admin
.in (), &client
);
124 ACE_DEBUG ((LM_DEBUG
, "\nConsumer waiting for events...\n"));
128 ACE_DEBUG ((LM_DEBUG
, "Consumer done.\n"));
129 consumer_1
->disconnect ();
133 catch (const CORBA::Exception
& e
)
135 e
._tao_print_exception ("Error: ");