Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / examples / Notify / Subscribe / Subscribe.h
blobe6294322038a72d5bc2672e9767123673d6a3f81
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file Subscribe.h
6 * Class to demo structured event subscription.
8 * @author Pradeep Gore <pradeep@cs.wustl.edu>
9 */
10 //=============================================================================
13 #ifndef NOTIFY_SUBSCRIBE_CLIENT_H
14 #define NOTIFY_SUBSCRIBE_CLIENT_H
16 #include "orbsvcs/CosNotifyChannelAdminS.h"
17 #include "orbsvcs/CosNotifyCommC.h"
18 #include "orbsvcs/CosNamingC.h"
20 class Subscribe_StructuredPushConsumer;
21 class Subscribe_StructuredPushSupplier;
23 /**
24 * @class Subscribe
26 * @brief Subscribe
28 * Shows how consumers subscribe for events.
30 class Subscribe
32 public:
33 Subscribe (void);
34 ~Subscribe ();
36 /// Init the Client.
37 void init (int argc, ACE_TCHAR *argv []);
39 /// Run the demo.
40 void run (void);
42 /// Called when all events we are waiting for have occurred.
43 void done (void);
45 protected:
46 /// Initializes the ORB.
47 void init_ORB (int argc, ACE_TCHAR *argv []);
49 /// Try to get hold of a running naming service.
50 void resolve_naming_service (void);
52 /// Try to resolve the Notify factory from the Naming service.
53 void resolve_Notify_factory (void);
55 /// Create an EC.
56 void create_EC (void);
58 /// Create the Supplier Admin.
59 void create_supplieradmin(void);
61 /// Create the Consumer Admin.
62 void create_consumeradmin (void);
64 /// Create and initialize the consumers.
65 void create_consumers (void);
67 /// create and initialize the suppliers.
68 void create_suppliers (void);
70 /// send the events.
71 void send_events (void);
73 // = Data Members
74 /// Reference to the root poa.
75 PortableServer::POA_var root_poa_;
77 /// The ORB that we use.
78 CORBA::ORB_var orb_;
80 /// Handle to the name service.
81 CosNaming::NamingContext_var naming_context_;
83 /// Channel factory.
84 CosNotifyChannelAdmin::EventChannelFactory_var notify_factory_;
86 /// The one channel that we create using the factory.
87 CosNotifyChannelAdmin::EventChannel_var ec_;
89 /// The group operator between admin-proxy's.
90 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop_;
92 /// Initial qos specified to the factory when creating the EC.
93 CosNotification::QoSProperties initial_qos_;
95 /// Initial admin props specified to the factory when creating the EC.
96 CosNotification::AdminProperties initial_admin_;
98 /// The consumer admin used by consumers.
99 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin_;
101 /// The supplier admin used by suppliers.
102 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin_;
104 Subscribe_StructuredPushConsumer* consumer_1_;
105 Subscribe_StructuredPushConsumer* consumer_2_;
107 Subscribe_StructuredPushSupplier* supplier_1_;
108 Subscribe_StructuredPushSupplier* supplier_2_;
110 /// Set this flag to exit the run loop.
111 CORBA::Boolean done_;
114 /*****************************************************************/
115 class Subscribe_StructuredPushConsumer
116 : public POA_CosNotifyComm::StructuredPushConsumer
118 // = TITLE
119 // Subscribe_StructuredPushConsumer
121 // = DESCRIPTION
122 // Consumer for the Subscribe example.
124 public:
125 /// Constructor.
126 Subscribe_StructuredPushConsumer (Subscribe* subscribe);
128 /// Connect the Consumer to the EventChannel.
129 /// Creates a new proxy supplier and connects to it.
130 void connect (CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin);
132 /// Disconnect from the supplier.
133 virtual void disconnect (void);
135 /// Accessor for the Proxy that we're connected to.
136 CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr get_proxy_supplier (void);
138 // public data member for evaluating the results of subscription.
139 CosNotification::EventTypeSeq expected_subscription_;
140 protected:
141 // = Data members
142 /// The proxy that we are connected to.
143 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var proxy_supplier_;
145 /// The proxy_supplier id.
146 CosNotifyChannelAdmin::ProxyID proxy_supplier_id_;
148 /// callback <done>
149 Subscribe* subscribe_;
151 // = Methods
152 /// Destructor
153 virtual ~Subscribe_StructuredPushConsumer (void);
155 // = NotifyPublish method
156 virtual void offer_change (
157 const CosNotification::EventTypeSeq & added,
158 const CosNotification::EventTypeSeq & removed);
160 // = StructuredPushSupplier methods
161 virtual void push_structured_event (
162 const CosNotification::StructuredEvent & notification);
164 virtual void disconnect_structured_push_consumer ();
167 /*****************************************************************/
169 class Subscribe_StructuredPushSupplier
170 : public POA_CosNotifyComm::StructuredPushSupplier
172 // = TITLE
173 // Subscribe_StructuredPushSupplier
175 // = DESCRIPTION
176 // Supplier for the SUBSCRIBE example.
178 public:
179 /// Constructor.
180 Subscribe_StructuredPushSupplier (void);
182 /// Connect the Supplier to the EventChannel.
183 /// Creates a new proxy consumer and connects to it.
184 void connect (CosNotifyChannelAdmin::SupplierAdmin_ptr supplier_admin);
186 /// Disconnect from the supplier.
187 void disconnect (void);
189 /// Send one event.
190 virtual void send_event (const CosNotification::StructuredEvent& event);
192 protected:
193 // = Data members
194 /// The proxy that we are connected to.
195 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var proxy_consumer_;
197 /// This supplier's id.
198 CosNotifyChannelAdmin::ProxyID proxy_consumer_id_;
200 // = Protected Methods
201 /// Destructor
202 virtual ~Subscribe_StructuredPushSupplier ();
204 // = NotifySubscribe
205 virtual void subscription_change (
206 const CosNotification::EventTypeSeq & added,
207 const CosNotification::EventTypeSeq & removed);
209 // = StructuredPushSupplier method
210 virtual void disconnect_structured_push_supplier ();
213 #endif /* NOTIFY_SUBSCRIBE_CLIENT_H */