Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_1385_Regression / Structured_Consumer.cpp
blobf858208573966d5c149479c57eab24ce1b6edf7f
1 // ******************************************************************
2 // Include Section
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"
12 #include "goC.h"
14 #include "Notify_Test_Client.h"
16 // ******************************************************************
17 // Data Section
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
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_Get_Opt get_opts (argc, argv, ACE_TEXT("k:e:"));
35 int c;
37 while ((c = get_opts ()) != -1)
38 switch (c)
40 case 'k':
41 ior = get_opts.optarg;
42 break;
44 case 'e':
45 expected = ACE_OS::atoi (get_opts.optarg);
46 break;
48 default:
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "usage: %s "
51 "-k <ior> "
52 "-e <expected events> "
53 "\n",
54 argv [0]),
55 -1);
57 // Indicates successful parsing of the command line
58 return 0;
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 ());
73 static void
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",
80 expected,
81 *client),
82 CORBA::NO_MEMORY ());
83 consumer_1->init (client->root_poa ());
84 consumer_1->_connect (admin);
87 // ******************************************************************
88 // Main Section
89 // ******************************************************************
91 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
93 int status = 0;
94 try
96 Consumer_Client client;
98 status = client.init (argc, argv);
99 if (status != 0)
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);
122 sig->go ();
124 ACE_DEBUG ((LM_DEBUG, "\nConsumer waiting for events...\n"));
126 client.ORB_run ();
128 ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
129 consumer_1->disconnect ();
131 sig->done ();
133 catch (const CORBA::Exception& e)
135 e._tao_print_exception ("Error: ");
136 status = 1;
139 return status;