Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / MC / Structured_Supplier.cpp
blob7f7ff4f8ef21b46fdb989c021172f630907ee951
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "tao/ORB_Core.h"
10 #include "MonitorTestInterfaceC.h"
11 #include "Notify_StructuredPushSupplier.h"
12 #include "Notify_Test_Client.h"
14 // ******************************************************************
15 // Data Section
16 // ******************************************************************
18 static TAO_Notify_Tests_StructuredPushSupplier* supplier_1 = 0;
19 static int max_events = 2000;
20 static const ACE_TCHAR *ior_output_file = ACE_TEXT ("supplier.ior");
21 static const ACE_TCHAR *ior = ACE_TEXT ("file://test_monitor.ior");
23 // ******************************************************************
24 // Subroutine Section
25 // ******************************************************************
27 class Supplier_Client : public Notify_Test_Client
29 public:
30 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
33 int
34 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
36 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:e:"));
37 int c;
39 while ((c = get_opts ()) != -1)
40 switch (c)
42 case 'k':
43 ior = get_opts.optarg;
44 break;
46 case 'e':
47 max_events = ACE_OS::atoi (get_opts.optarg);
48 break;
50 case 'o':
51 ior_output_file = get_opts.optarg;
52 break;
54 default:
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "usage: %s "
57 "-k <ior> "
58 "-o <iorfile> -e <# of events> "
59 "\n",
60 argv [0]),
61 -1);
64 // Indicates successful parsing of the command line
65 return 0;
69 static CosNotifyChannelAdmin::SupplierAdmin_ptr
70 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
72 CosNotifyChannelAdmin::AdminID adminid = 0;
73 CosNotifyChannelAdmin::SupplierAdmin_var admin =
74 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP, adminid);
76 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
80 static void
81 SendEvent (int id)
83 CosNotification::StructuredEvent event;
85 event.header.fixed_header.event_type.domain_name = CORBA::string_dup ("DOC_TAO");
86 event.header.fixed_header.event_type.type_name = CORBA::string_dup ("examples");
88 event.filterable_data.length (1);
89 event.filterable_data[0].name = CORBA::string_dup ("id");
90 event.filterable_data[0].value <<= id;
92 try
94 supplier_1->send_event (event);
96 catch (const CORBA::Exception& e)
98 e._tao_print_exception ("Error: ");
102 static void
103 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
104 PortableServer::POA_ptr poa)
106 // startup the supplier
107 ACE_NEW_THROW_EX (supplier_1,
108 TAO_Notify_Tests_StructuredPushSupplier (),
109 CORBA::NO_MEMORY ());
111 supplier_1->init (poa);
112 supplier_1->connect (admin);
114 CosNotification::EventTypeSeq added (1);
115 CosNotification::EventTypeSeq removed (1);
116 added.length (1);
117 removed.length (1);
118 added[0].domain_name = CORBA::string_dup ("DOC_TAO");
119 added[0].type_name = CORBA::string_dup ("examples");
121 removed[0].domain_name = CORBA::string_dup ("*");
122 removed[0].type_name = CORBA::string_dup ("*");
124 supplier_1->offer_change (added, removed);
128 // ******************************************************************
129 // Main Section
130 // ******************************************************************
132 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
134 int status = 0;
137 Supplier_Client client;
138 status = client.init (argc, argv);
140 if (status == 0)
142 CosNotifyChannelAdmin::EventChannel_var ec =
143 client.create_event_channel ("MyEventChannel", 1);
145 CORBA::ORB_ptr orb = client.orb ();
146 CORBA::Object_var object =
147 orb->string_to_object (ior);
149 MonitorTestInterface_var sig =
150 MonitorTestInterface::_narrow (object.in ());
152 if (CORBA::is_nil (sig.in ()))
153 ACE_ERROR_RETURN ((LM_ERROR, "Error: Structured Supplier: Narrow to MonitorTestInterface failed.\n"),1);
154 CosNotifyChannelAdmin::SupplierAdmin_var admin =
155 create_supplieradmin (ec.in ());
156 if (!CORBA::is_nil (admin.in ()))
158 create_suppliers (admin.in (), client.root_poa ());
160 sig->running (MonitorTestInterface::Supplier);
161 ACE_DEBUG ((LM_DEBUG,
162 "1 supplier sending %d events...\n", max_events));
163 for (int i = 0; i < max_events; ++i)
165 ACE_DEBUG ((LM_DEBUG, "+"));
166 SendEvent (i);
168 ACE_DEBUG ((LM_DEBUG,
169 "\nSupplier sent %d events.\n", max_events));
170 sig->finished (MonitorTestInterface::Supplier);
171 supplier_1->disconnect ();
175 catch (const CORBA::Exception& e)
177 e._tao_print_exception ("Supplier Error: ");
178 status = 1;
181 return status;