BLPAPI C++ 3.25.10
Loading...
Searching...
No Matches
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
113#include <blpapi_call.h>
114#include <blpapi_defs.h>
115#include <blpapi_message.h>
116
117#ifdef __cplusplus
118extern "C" {
119#endif
120
123
126
129
132
135
138 blpapi_EventQueue_t *eventQueue, int timeout);
139
142
145 blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer);
146
149 const blpapi_Event_t *event);
150
153
156 blpapi_MessageIterator_t *iterator, blpapi_Message_t **result);
157
160
161#ifdef __cplusplus
162}
163
164#include <cassert>
165#include <utility>
166
174namespace BloombergLP {
175namespace blpapi {
176
196class Event {
197
198 blpapi_Event_t *d_impl_p;
199
200 public:
233
243 class iterator {
244 // DATA
245 blpapi_MessageIterator_t *d_impl_p;
246 Message d_currentMessage;
247
248 public:
249 // TYPES
250 using difference_type = std::ptrdiff_t;
252 using pointer = Message *;
254 using iterator_category = std::input_iterator_tag;
255
256 // CREATORS
257 iterator();
260 explicit iterator(const Event& event);
266 iterator(const iterator& original);
273 ~iterator();
274
275 // MANIPULATORS
276 iterator& operator=(const iterator& original);
290 iterator operator++(int);
299 void swap(iterator& other);
304 // ACCESSORS
305 const Message& operator*() const noexcept;
306 const Message *operator->() const noexcept;
307
308 // FRIENDS
309 friend bool operator==(const iterator& lhs, const iterator& rhs);
310 };
311
312 Event();
319 Event(blpapi_Event_t *handle);
320
321 Event(const Event& original);
328 ~Event();
335 Event& operator=(const Event& rhs);
342 EventType eventType() const;
347 bool isValid() const;
352 blpapi_Event_t *impl() const;
353
354 iterator begin() const;
355 iterator end() const;
356};
357
358// FREE OPERATORS
359bool operator==(const Event::iterator& lhs, const Event::iterator& rhs);
365bool operator!=(const Event::iterator& lhs, const Event::iterator& rhs);
387
388 blpapi_EventQueue_t *d_handle_p;
389
390 public:
391 EventQueue();
396 EventQueue(const EventQueue&) = delete;
397 EventQueue& operator=(const EventQueue&) = delete;
398
399 virtual ~EventQueue();
405 virtual Event nextEvent(int timeout = 0);
414 virtual int tryNextEvent(Event *event);
422 virtual void purge();
430 blpapi_EventQueue_t *handle() const;
431};
432
449
450 blpapi_MessageIterator_t *d_impl_p;
451 blpapi_Message_t *d_current_p;
452
453 public:
456
457 explicit MessageIterator(const Event& event);
470 bool next();
479 bool isValid() const;
485 Message message(bool createClonable = false) const;
495};
496
497void swap(Event::iterator& lhs, Event::iterator& rhs);
499
503//=============================================================================
504// INLINE FUNCTION DEFINITIONS
505//=============================================================================
506
507// -----------
508// class Event
509// -----------
510
512 : d_impl_p(0)
513{
514}
515
517 : d_impl_p(handle)
518{
519}
520
521inline Event::Event(const Event& original)
522 : d_impl_p(original.d_impl_p)
523{
524 if (d_impl_p) {
525 blpapi_Event_addRef(d_impl_p);
526 }
527}
528
530{
531 if (d_impl_p) {
532 blpapi_Event_release(d_impl_p);
533 }
534}
535
536inline Event& Event::operator=(const Event& rhs)
537{
538 using std::swap;
539
540 Event tmp(rhs);
541 swap(tmp.d_impl_p, d_impl_p);
542
543 return *this;
544}
545
547{
548 return (EventType)blpapi_Event_eventType(d_impl_p);
549}
550
551inline bool Event::isValid() const { return d_impl_p ? true : false; }
552
553inline blpapi_Event_t *Event::impl() const { return d_impl_p; }
554
555inline Event::iterator Event::begin() const { return iterator(*this); }
556
557inline Event::iterator Event::end() const { return iterator(); }
558
559// ----------------
560// class EventQueue
561// ----------------
562
564
566
567inline Event EventQueue::nextEvent(int timeout)
568{
569 return Event(blpapi_EventQueue_nextEvent(d_handle_p, timeout));
570}
571
573{
574 assert(event);
575
576 blpapi_Event_t *impl = 0;
577 int ret = blpapi_EventQueue_tryNextEvent(d_handle_p, &impl);
578 if (0 == ret) {
579 *event = Event(impl);
580 }
581 return ret;
582}
583
584inline void EventQueue::purge() { blpapi_EventQueue_purge(d_handle_p); }
585
586inline blpapi_EventQueue_t *EventQueue::handle() const { return d_handle_p; }
587
588// ---------------------
589// class MessageIterator
590// ---------------------
591
593 : d_impl_p(nullptr)
594 , d_current_p(nullptr)
595{
596 d_impl_p = blpapi_MessageIterator_create(event.impl());
597}
598
603
605{
606 return !blpapi_MessageIterator_next(d_impl_p, &d_current_p);
607}
608
609inline bool MessageIterator::isValid() const
610{
611 return d_current_p ? true : false;
612}
613
614inline Message MessageIterator::message(bool createClonable) const
615{
616 if (createClonable) {
617 BLPAPI_CALL_MESSAGE_ADDREF(d_current_p);
618 }
619 return Message(d_current_p, createClonable);
620}
621
622// --------------------------
623// class Event::iterator
624// --------------------------
625
627 : d_impl_p(nullptr)
628 , d_currentMessage(nullptr)
629{
630}
631
633 : iterator()
634{
635 if (event.impl()) {
636 d_impl_p = blpapi_MessageIterator_create(event.impl());
637 ++(*this);
638 }
639}
640
641inline Event::iterator::iterator(const iterator& original)
642 : d_impl_p(original.d_impl_p)
643 , d_currentMessage(original.d_currentMessage)
644{
645 if (d_impl_p) {
647 }
648}
649
654
656{
657 auto copy(original);
658 copy.swap(*this);
659 return *this;
660}
661
662inline const Message& Event::iterator::operator*() const noexcept
663{
664 return d_currentMessage;
665}
666
667inline const Message *Event::iterator::operator->() const noexcept
668{
669 return &d_currentMessage;
670}
671
673{
674 d_currentMessage = Message(nullptr);
675
676 blpapi_Message_t *nextMessage = nullptr;
677 blpapi_MessageIterator_next(d_impl_p, &nextMessage);
678 d_currentMessage = Message(nextMessage);
679
680 return *this;
681}
682
684{
685 auto copy = *this;
686 ++(*this);
687 return copy;
688}
689
691{
692 using std::swap;
693 swap(d_impl_p, other.d_impl_p);
694 swap(d_currentMessage, other.d_currentMessage);
695}
696
697} // close namespace blpapi
698
700 Event::iterator const& lhs, Event::iterator const& rhs)
701{
702 if (&lhs == &rhs) {
703 return true;
704 }
705
706 if (lhs.d_impl_p == rhs.d_impl_p
707 && lhs.d_currentMessage.impl() == rhs.d_currentMessage.impl()) {
708 return true;
709 }
710
711 const bool lend = !lhs.d_impl_p || !lhs.d_currentMessage.impl();
712 const bool rend = !rhs.d_impl_p || !rhs.d_currentMessage.impl();
713
714 return lend && rend;
715}
716
718 Event::iterator const& lhs, Event::iterator const& rhs)
719{
720 return !(lhs == rhs);
721}
722
724{
725 lhs.swap(rhs);
726}
727
728} // close namespace BloombergLP
729
730#endif // #ifdef __cplusplus
731#endif // #ifndef INCLUDED_BLPAPI_EVENT
Provide functions for dispatchtbl.
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition blpapi_call.h:360
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:353
Common definitions used by the library.
#define BLPAPI_EVENTTYPE_AUTHORIZATION_STATUS
Definition blpapi_defs.h:90
#define BLPAPI_EVENTTYPE_SESSION_STATUS
Definition blpapi_defs.h:82
#define BLPAPI_EVENTTYPE_ADMIN
Definition blpapi_defs.h:81
#define BLPAPI_EVENTTYPE_PARTIAL_RESPONSE
Definition blpapi_defs.h:86
#define BLPAPI_EVENTTYPE_SUBSCRIPTION_DATA
Definition blpapi_defs.h:87
#define BLPAPI_EVENTTYPE_REQUEST
Definition blpapi_defs.h:94
#define BLPAPI_EVENTTYPE_RESOLUTION_STATUS
Definition blpapi_defs.h:91
#define BLPAPI_EVENTTYPE_REQUEST_STATUS
Definition blpapi_defs.h:84
#define BLPAPI_EVENTTYPE_RESPONSE
Definition blpapi_defs.h:85
#define BLPAPI_EXPORT
Definition blpapi_defs.h:171
#define BLPAPI_EVENTTYPE_TOKEN_STATUS
Definition blpapi_defs.h:93
#define BLPAPI_EVENTTYPE_SUBSCRIPTION_STATUS
Definition blpapi_defs.h:83
#define BLPAPI_EVENTTYPE_TOPIC_STATUS
Definition blpapi_defs.h:92
#define BLPAPI_EVENTTYPE_SERVICE_STATUS
Definition blpapi_defs.h:88
#define BLPAPI_EVENTTYPE_TIMEOUT
Definition blpapi_defs.h:89
struct blpapi_Message blpapi_Message_t
Definition blpapi_dispatchtbl.h:78
BLPAPI_EXPORT void blpapi_MessageIterator_destroy(blpapi_MessageIterator_t *iterator)
BLPAPI_EXPORT blpapi_EventQueue_t * blpapi_EventQueue_create(void)
BLPAPI_EXPORT blpapi_Event_t * blpapi_EventQueue_nextEvent(blpapi_EventQueue_t *eventQueue, int timeout)
BLPAPI_EXPORT int blpapi_Event_release(const blpapi_Event_t *event)
BLPAPI_EXPORT blpapi_MessageIterator_t * blpapi_MessageIterator_create(const blpapi_Event_t *event)
BLPAPI_EXPORT int blpapi_EventQueue_tryNextEvent(blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer)
BLPAPI_EXPORT int blpapi_MessageIterator_addRef(const blpapi_MessageIterator_t *iterator)
BLPAPI_EXPORT int blpapi_MessageIterator_next(blpapi_MessageIterator_t *iterator, blpapi_Message_t **result)
BLPAPI_EXPORT int blpapi_Event_addRef(const blpapi_Event_t *event)
BLPAPI_EXPORT int blpapi_Event_eventType(const blpapi_Event_t *event)
BLPAPI_EXPORT int blpapi_EventQueue_destroy(blpapi_EventQueue_t *eventQueue)
BLPAPI_EXPORT int blpapi_EventQueue_purge(blpapi_EventQueue_t *eventQueue)
Defines a message containing elements.
Definition blpapi_event.h:386
EventQueue(const EventQueue &)=delete
EventQueue & operator=(const EventQueue &)=delete
virtual int tryNextEvent(Event *event)
Definition blpapi_event.h:572
EventQueue()
Definition blpapi_event.h:563
virtual ~EventQueue()
Definition blpapi_event.h:565
virtual Event nextEvent(int timeout=0)
Definition blpapi_event.h:567
virtual void purge()
Definition blpapi_event.h:584
blpapi_EventQueue_t * handle() const
Definition blpapi_event.h:586
Definition blpapi_event.h:243
const Message & operator*() const noexcept
Definition blpapi_event.h:662
const Message * operator->() const noexcept
Definition blpapi_event.h:667
~iterator()
Definition blpapi_event.h:650
void swap(iterator &other)
Definition blpapi_event.h:690
iterator()
Definition blpapi_event.h:626
iterator & operator=(const iterator &original)
Definition blpapi_event.h:655
std::input_iterator_tag iterator_category
Definition blpapi_event.h:254
std::ptrdiff_t difference_type
Definition blpapi_event.h:250
iterator & operator++()
Definition blpapi_event.h:672
Definition blpapi_event.h:196
iterator end() const
Definition blpapi_event.h:557
EventType
The possible types of event.
Definition blpapi_event.h:202
@ AUTHORIZATION_STATUS
Status updates for user authorization.
Definition blpapi_event.h:221
@ SESSION_STATUS
Status updates for a session.
Definition blpapi_event.h:205
@ ADMIN
Admin event.
Definition blpapi_event.h:203
@ PARTIAL_RESPONSE
A partial response to a request.
Definition blpapi_event.h:213
@ SERVICE_STATUS
Status updates for a service.
Definition blpapi_event.h:217
@ UNKNOWN
Definition blpapi_event.h:231
@ REQUEST_STATUS
Status updates for a request.
Definition blpapi_event.h:209
@ TOKEN_STATUS
Status updates for a generate token request.
Definition blpapi_event.h:227
@ RESOLUTION_STATUS
Status updates for a resolution operation.
Definition blpapi_event.h:223
@ TIMEOUT
An Event returned from Session::nextEvent() if it timed out.
Definition blpapi_event.h:219
@ REQUEST
Request event. Provided to ProviderSession only.
Definition blpapi_event.h:229
@ SUBSCRIPTION_DATA
Data updates resulting from a subscription.
Definition blpapi_event.h:215
@ TOPIC_STATUS
Status updates about topics for service providers.
Definition blpapi_event.h:225
@ SUBSCRIPTION_STATUS
Status updates for a subscription.
Definition blpapi_event.h:207
@ RESPONSE
The final (possibly only) response to a request.
Definition blpapi_event.h:211
EventType eventType() const
Definition blpapi_event.h:546
Event & operator=(const Event &rhs)
Definition blpapi_event.h:536
blpapi_Event_t * impl() const
Definition blpapi_event.h:553
bool isValid() const
Definition blpapi_event.h:551
Event()
Definition blpapi_event.h:511
~Event()
Definition blpapi_event.h:529
iterator begin() const
Definition blpapi_event.h:555
Definition blpapi_event.h:448
MessageIterator(const MessageIterator &)=delete
MessageIterator & operator=(const MessageIterator &)=delete
bool isValid() const
Definition blpapi_event.h:609
~MessageIterator()
Definition blpapi_event.h:599
bool next()
Definition blpapi_event.h:604
Message message(bool createClonable=false) const
Definition blpapi_event.h:614
Definition blpapi_message.h:161
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:723
struct blpapi_EventQueue blpapi_EventQueue_t
Definition blpapi_types.h:148
struct blpapi_Event blpapi_Event_t
Definition blpapi_types.h:139
struct blpapi_MessageIterator blpapi_MessageIterator_t
Definition blpapi_types.h:151
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:562
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:582
Definition blpapi_abstractsession.h:195