BLPAPI C++  3.20.6
blpapi_event.h
Go to the documentation of this file.
1 /* Copyright 2012. Bloomberg Finance L.P.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions: The above
9  * copyright notice and this permission notice shall be included in all copies
10  * or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  */
20 
28 #ifndef INCLUDED_BLPAPI_EVENT
29 #define INCLUDED_BLPAPI_EVENT
30 
98 #ifndef INCLUDED_BLPAPI_MESSAGE
99 #include <blpapi_message.h>
100 #endif
101 
102 #ifndef INCLUDED_BLPAPI_DEFS
103 #include <blpapi_defs.h>
104 #endif
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
111 int blpapi_Event_eventType(const blpapi_Event_t *event);
112 
114 int blpapi_Event_addRef(const blpapi_Event_t *event);
115 
117 int blpapi_Event_release(const blpapi_Event_t *event);
118 
121 
124 
127  blpapi_EventQueue_t *eventQueue, int timeout);
128 
131 
134  blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer);
135 
138  const blpapi_Event_t *event);
139 
142 
145  blpapi_MessageIterator_t *iterator, blpapi_Message_t **result);
146 
147 #ifdef __cplusplus
148 }
149 
150 #include <cassert>
151 #include <utility>
152 
160 namespace BloombergLP {
161 namespace blpapi {
162 
182 class Event {
183 
184  blpapi_Event_t *d_impl_p;
185 
186  public:
188  enum EventType {
217  UNKNOWN = -1
218  };
219 
220  Event();
227  Event(blpapi_Event_t *handle);
228 
229  Event(const Event& original);
236  ~Event();
243  Event& operator=(const Event& rhs);
250  EventType eventType() const;
255  bool isValid() const;
260  blpapi_Event_t *impl() const;
261 };
262 
278 class EventQueue {
279 
280  blpapi_EventQueue_t *d_handle_p;
281 
282  public:
283  EventQueue();
288  virtual ~EventQueue();
294  virtual Event nextEvent(int timeout = 0);
303  virtual int tryNextEvent(Event *event);
311  virtual void purge();
319  blpapi_EventQueue_t *handle() const;
320 };
321 
337 
338  blpapi_MessageIterator_t *d_impl_p;
339  blpapi_Message_t *d_current_p;
340 
341  private:
343  MessageIterator& operator=(const MessageIterator&);
344 
345  public:
346  MessageIterator(const Event& event);
359  bool next();
368  bool isValid() const;
374  Message message(bool createClonable = false) const;
384 };
385 
389 //=============================================================================
390 // INLINE FUNCTION DEFINITIONS
391 //=============================================================================
392 
393 // -----------
394 // class Event
395 // -----------
396 
397 inline Event::Event()
398  : d_impl_p(0)
399 {
400 }
401 
403  : d_impl_p(handle)
404 {
405 }
406 
407 inline Event::Event(const Event& original)
408  : d_impl_p(original.d_impl_p)
409 {
410  if (d_impl_p) {
411  blpapi_Event_addRef(d_impl_p);
412  }
413 }
414 
416 {
417  if (d_impl_p) {
418  blpapi_Event_release(d_impl_p);
419  }
420 }
421 
422 inline Event& Event::operator=(const Event& rhs)
423 {
424  using std::swap;
425 
426  Event tmp(rhs);
427  swap(tmp.d_impl_p, d_impl_p);
428 
429  return *this;
430 }
431 
433 {
434  return (EventType)blpapi_Event_eventType(d_impl_p);
435 }
436 
437 inline bool Event::isValid() const { return d_impl_p ? true : false; }
438 
439 inline blpapi_Event_t *Event::impl() const { return d_impl_p; }
440 
441 // ----------------
442 // class EventQueue
443 // ----------------
444 
446 
448 
449 inline Event EventQueue::nextEvent(int timeout)
450 {
451  return blpapi_EventQueue_nextEvent(d_handle_p, timeout);
452 }
453 
454 inline int EventQueue::tryNextEvent(Event *event)
455 {
456  assert(event);
457 
458  blpapi_Event_t *impl = 0;
459  int ret = blpapi_EventQueue_tryNextEvent(d_handle_p, &impl);
460  if (0 == ret) {
461  *event = Event(impl);
462  }
463  return ret;
464 }
465 
466 inline void EventQueue::purge() { blpapi_EventQueue_purge(d_handle_p); }
467 
468 inline blpapi_EventQueue_t *EventQueue::handle() const { return d_handle_p; }
469 
470 // ---------------------
471 // class MessageIterator
472 // ---------------------
473 
474 inline MessageIterator::MessageIterator(const Event& event)
475  : d_impl_p(0)
476  , d_current_p(0)
477 {
478  d_impl_p = blpapi_MessageIterator_create(event.impl());
479 }
480 
482 {
484 }
485 
487 {
488  return !blpapi_MessageIterator_next(d_impl_p, &d_current_p);
489 }
490 
491 inline bool MessageIterator::isValid() const
492 {
493  return d_current_p ? true : false;
494 }
495 
496 inline Message MessageIterator::message(bool createClonable) const
497 {
498  if (createClonable) {
499  BLPAPI_CALL_MESSAGE_ADDREF(d_current_p);
500  }
501  return Message(d_current_p, createClonable);
502 }
503 
504 } // close namespace blpapi
505 } // close namespace BloombergLP
506 
507 #endif // #ifdef __cplusplus
508 #endif // #ifndef INCLUDED_BLPAPI_EVENT
#define BLPAPI_EVENTTYPE_TOKEN_STATUS
Definition: blpapi_defs.h:93
Status updates for a request.
Definition: blpapi_event.h:195
Definition: blpapi_message.h:159
#define BLPAPI_EVENTTYPE_RESOLUTION_STATUS
Definition: blpapi_defs.h:91
Status updates for user authorization.
Definition: blpapi_event.h:207
Status updates for a subscription.
Definition: blpapi_event.h:193
int blpapi_Event_eventType(const blpapi_Event_t *event)
int blpapi_EventQueue_purge(blpapi_EventQueue_t *eventQueue)
#define BLPAPI_EVENTTYPE_RESPONSE
Definition: blpapi_defs.h:85
Common definitions used by the library.
struct blpapi_Event blpapi_Event_t
Definition: blpapi_types.h:139
blpapi_EventQueue_t * handle() const
Definition: blpapi_event.h:468
blpapi_EventQueue_t * blpapi_EventQueue_create(void)
void blpapi_MessageIterator_destroy(blpapi_MessageIterator_t *iterator)
Status updates about topics for service providers.
Definition: blpapi_event.h:211
#define BLPAPI_EVENTTYPE_SESSION_STATUS
Definition: blpapi_defs.h:82
Definition: blpapi_abstractsession.h:215
#define BLPAPI_EVENTTYPE_TIMEOUT
Definition: blpapi_defs.h:89
Event & operator=(const Event &rhs)
Definition: blpapi_event.h:422
Data updates resulting from a subscription.
Definition: blpapi_event.h:201
#define BLPAPI_EVENTTYPE_ADMIN
Definition: blpapi_defs.h:81
The final (possibly only) response to a request.
Definition: blpapi_event.h:197
virtual Event nextEvent(int timeout=0)
Definition: blpapi_event.h:449
bool isValid() const
Definition: blpapi_event.h:491
#define BLPAPI_EVENTTYPE_AUTHORIZATION_STATUS
Definition: blpapi_defs.h:90
Definition: blpapi_event.h:278
Status updates for a generate token request.
Definition: blpapi_event.h:213
Status updates for a service.
Definition: blpapi_event.h:203
virtual int tryNextEvent(Event *event)
Definition: blpapi_event.h:454
struct blpapi_EventQueue blpapi_EventQueue_t
Definition: blpapi_types.h:148
EventType
The possible types of event.
Definition: blpapi_event.h:188
struct blpapi_Message blpapi_Message_t
Definition: blpapi_message.h:70
EventQueue()
Definition: blpapi_event.h:445
#define BLPAPI_EVENTTYPE_SUBSCRIPTION_DATA
Definition: blpapi_defs.h:87
Status updates for a resolution operation.
Definition: blpapi_event.h:209
bool next()
Definition: blpapi_event.h:486
EventType eventType() const
Definition: blpapi_event.h:432
#define BLPAPI_EVENTTYPE_TOPIC_STATUS
Definition: blpapi_defs.h:92
~MessageIterator()
Definition: blpapi_event.h:481
struct blpapi_MessageIterator blpapi_MessageIterator_t
Definition: blpapi_types.h:151
~Event()
Definition: blpapi_event.h:415
int blpapi_MessageIterator_next(blpapi_MessageIterator_t *iterator, blpapi_Message_t **result)
Admin event.
Definition: blpapi_event.h:189
Defines a message containing elements.
#define BLPAPI_EVENTTYPE_PARTIAL_RESPONSE
Definition: blpapi_defs.h:86
Event()
Definition: blpapi_event.h:397
#define BLPAPI_EVENTTYPE_REQUEST_STATUS
Definition: blpapi_defs.h:84
virtual void purge()
Definition: blpapi_event.h:466
A partial response to a request.
Definition: blpapi_event.h:199
Request event. Provided to ProviderSession only.
Definition: blpapi_event.h:215
bool isValid() const
Definition: blpapi_event.h:437
Definition: blpapi_event.h:182
#define BLPAPI_EVENTTYPE_SERVICE_STATUS
Definition: blpapi_defs.h:88
blpapi_MessageIterator_t * blpapi_MessageIterator_create(const blpapi_Event_t *event)
Definition: blpapi_event.h:336
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
blpapi_Event_t * blpapi_EventQueue_nextEvent(blpapi_EventQueue_t *eventQueue, int timeout)
int blpapi_EventQueue_destroy(blpapi_EventQueue_t *eventQueue)
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition: blpapi_call.h:360
blpapi_Event_t * impl() const
Definition: blpapi_event.h:439
int blpapi_EventQueue_tryNextEvent(blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer)
#define BLPAPI_EVENTTYPE_SUBSCRIPTION_STATUS
Definition: blpapi_defs.h:83
An Event returned from Session::nextEvent() if it timed out.
Definition: blpapi_event.h:205
#define BLPAPI_EVENTTYPE_REQUEST
Definition: blpapi_defs.h:94
int blpapi_Event_addRef(const blpapi_Event_t *event)
Message message(bool createClonable=false) const
Definition: blpapi_event.h:496
virtual ~EventQueue()
Definition: blpapi_event.h:447
Status updates for a session.
Definition: blpapi_event.h:191
Definition: blpapi_event.h:217
int blpapi_Event_release(const blpapi_Event_t *event)