BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_EVENT
37#define INCLUDED_BLPAPI_EVENT
38
120
121#include <blpapi_call.h>
122#include <blpapi_defs.h>
123#include <blpapi_message.h>
124
125#ifdef __cplusplus
126extern "C" {
127#endif
128
130
133
134BLPAPI_EXPORT
135int blpapi_Event_eventType(const blpapi_Event_t *event);
136
137BLPAPI_EXPORT
138int blpapi_Event_addRef(const blpapi_Event_t *event);
139
140BLPAPI_EXPORT
141int blpapi_Event_release(const blpapi_Event_t *event);
142
143BLPAPI_EXPORT
144blpapi_EventQueue_t *blpapi_EventQueue_create(void);
145
146BLPAPI_EXPORT
147int blpapi_EventQueue_destroy(blpapi_EventQueue_t *eventQueue);
148
149BLPAPI_EXPORT
150blpapi_Event_t *blpapi_EventQueue_nextEvent(
151 blpapi_EventQueue_t *eventQueue, int timeout);
152
153BLPAPI_EXPORT
154int blpapi_EventQueue_purge(blpapi_EventQueue_t *eventQueue);
155
156BLPAPI_EXPORT
157int blpapi_EventQueue_tryNextEvent(
158 blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer);
159
160BLPAPI_EXPORT
161blpapi_MessageIterator_t *blpapi_MessageIterator_create(
162 const blpapi_Event_t *event);
163
164BLPAPI_EXPORT
165void blpapi_MessageIterator_destroy(blpapi_MessageIterator_t *iterator);
166
167BLPAPI_EXPORT
168int blpapi_MessageIterator_next(
169 blpapi_MessageIterator_t *iterator, blpapi_Message_t **result);
170
171BLPAPI_EXPORT
172int blpapi_MessageIterator_addRef(const blpapi_MessageIterator_t *iterator);
173
176
177#ifdef __cplusplus
178}
179
180#include <cassert>
181#include <utility>
182
189
190namespace BloombergLP {
191namespace blpapi {
192
212class Event {
213
214 blpapi_Event_t *d_impl_p;
215
216 public:
219 ADMIN = BLPAPI_EVENTTYPE_ADMIN,
221 SESSION_STATUS = BLPAPI_EVENTTYPE_SESSION_STATUS,
223 SUBSCRIPTION_STATUS = BLPAPI_EVENTTYPE_SUBSCRIPTION_STATUS,
225 REQUEST_STATUS = BLPAPI_EVENTTYPE_REQUEST_STATUS,
227 RESPONSE = BLPAPI_EVENTTYPE_RESPONSE,
229 PARTIAL_RESPONSE = BLPAPI_EVENTTYPE_PARTIAL_RESPONSE,
231 SUBSCRIPTION_DATA = BLPAPI_EVENTTYPE_SUBSCRIPTION_DATA,
233 SERVICE_STATUS = BLPAPI_EVENTTYPE_SERVICE_STATUS,
235 TIMEOUT = BLPAPI_EVENTTYPE_TIMEOUT,
237 AUTHORIZATION_STATUS = BLPAPI_EVENTTYPE_AUTHORIZATION_STATUS,
239 RESOLUTION_STATUS = BLPAPI_EVENTTYPE_RESOLUTION_STATUS,
241 TOPIC_STATUS = BLPAPI_EVENTTYPE_TOPIC_STATUS,
243 TOKEN_STATUS = BLPAPI_EVENTTYPE_TOKEN_STATUS,
245 REQUEST = BLPAPI_EVENTTYPE_REQUEST,
248 };
249
259 class iterator {
260 // DATA
261 blpapi_MessageIterator_t *d_impl_p;
262 Message d_currentMessage;
263
264 public:
265 // TYPES
266 using difference_type = std::ptrdiff_t;
268 using pointer = Message *;
270 using iterator_category = std::input_iterator_tag;
271
272 // CREATORS
273 iterator();
275
276 explicit iterator(const Event& event);
281
282 iterator(const iterator& original);
288
289 ~iterator();
290
291 // MANIPULATORS
292 iterator& operator=(const iterator& original);
298
305
306 iterator operator++(int);
314
315 void swap(iterator& other);
319
320 // ACCESSORS
321 const Message& operator*() const noexcept;
322 const Message *operator->() const noexcept;
323
324 // FRIENDS
325 friend bool operator==(const iterator& lhs, const iterator& rhs);
326 };
327
328 Event();
334
335 Event(blpapi_Event_t *handle);
336
337 Event(const Event& original);
343
344 ~Event();
350
351 Event& operator=(const Event& rhs);
357
358 EventType eventType() const;
362
363 bool isValid() const;
367
368 blpapi_Event_t *impl() const;
369
370 iterator begin() const;
371 iterator end() const;
372};
373
374// FREE OPERATORS
375bool operator==(const Event::iterator& lhs, const Event::iterator& rhs);
380
381bool operator!=(const Event::iterator& lhs, const Event::iterator& rhs);
386
403
404 blpapi_EventQueue_t *d_handle_p;
405
406 public:
407 EventQueue();
411
412 EventQueue(const EventQueue&) = delete;
413 EventQueue& operator=(const EventQueue&) = delete;
414
415 virtual ~EventQueue();
420
421 virtual Event nextEvent(int timeout = 0);
429
430 virtual int tryNextEvent(Event *event);
437
438 virtual void purge();
445
446 blpapi_EventQueue_t *handle() const;
447};
448
465
466 blpapi_MessageIterator_t *d_impl_p;
467 blpapi_Message_t *d_current_p;
468
469 public:
472
473 explicit MessageIterator(const Event& event);
480
485
486 bool next();
494
495 bool isValid() const;
500
501 Message message(bool createClonable = false) const;
511};
512
513void swap(Event::iterator& lhs, Event::iterator& rhs);
515
518
519//=============================================================================
520// INLINE FUNCTION DEFINITIONS
521//=============================================================================
522
523// -----------
524// class Event
525// -----------
526
528 : d_impl_p(0)
529{
530}
531
532inline Event::Event(blpapi_Event_t *handle)
533 : d_impl_p(handle)
534{
535}
536
537inline Event::Event(const Event& original)
538 : d_impl_p(original.d_impl_p)
539{
540 if (d_impl_p) {
541 blpapi_Event_addRef(d_impl_p);
542 }
543}
544
546{
547 if (d_impl_p) {
548 blpapi_Event_release(d_impl_p);
549 }
550}
551
552inline Event& Event::operator=(const Event& rhs)
553{
554 using std::swap;
555
556 Event tmp(rhs);
557 swap(tmp.d_impl_p, d_impl_p);
558
559 return *this;
560}
561
563{
564 return (EventType)blpapi_Event_eventType(d_impl_p);
565}
566
567inline bool Event::isValid() const { return d_impl_p ? true : false; }
568
569inline blpapi_Event_t *Event::impl() const { return d_impl_p; }
570
571inline Event::iterator Event::begin() const { return iterator(*this); }
572
573inline Event::iterator Event::end() const { return iterator(); }
574
575// ----------------
576// class EventQueue
577// ----------------
578
579inline EventQueue::EventQueue() { d_handle_p = blpapi_EventQueue_create(); }
580
581inline EventQueue::~EventQueue() { blpapi_EventQueue_destroy(d_handle_p); }
582
583inline Event EventQueue::nextEvent(int timeout)
584{
585 return Event(blpapi_EventQueue_nextEvent(d_handle_p, timeout));
586}
587
589{
590 assert(event);
591
592 blpapi_Event_t *impl = 0;
593 int ret = blpapi_EventQueue_tryNextEvent(d_handle_p, &impl);
594 if (0 == ret) {
595 *event = Event(impl);
596 }
597 return ret;
598}
599
600inline void EventQueue::purge() { blpapi_EventQueue_purge(d_handle_p); }
601
602inline blpapi_EventQueue_t *EventQueue::handle() const { return d_handle_p; }
603
604// ---------------------
605// class MessageIterator
606// ---------------------
607
609 : d_impl_p(nullptr)
610 , d_current_p(nullptr)
611{
612 d_impl_p = blpapi_MessageIterator_create(event.impl());
613}
614
616{
617 blpapi_MessageIterator_destroy(d_impl_p);
618}
619
621{
622 return !blpapi_MessageIterator_next(d_impl_p, &d_current_p);
623}
624
625inline bool MessageIterator::isValid() const
626{
627 return d_current_p ? true : false;
628}
629
630inline Message MessageIterator::message(bool createClonable) const
631{
632 if (createClonable) {
633 BLPAPI_CALL_MESSAGE_ADDREF(d_current_p);
634 }
635 return Message(d_current_p, createClonable);
636}
637
638// --------------------------
639// class Event::iterator
640// --------------------------
641
643 : d_impl_p(nullptr)
644 , d_currentMessage(nullptr)
645{
646}
647
649 : iterator()
650{
651 if (event.impl()) {
652 d_impl_p = blpapi_MessageIterator_create(event.impl());
653 ++(*this);
654 }
655}
656
657inline Event::iterator::iterator(const iterator& original)
658 : d_impl_p(original.d_impl_p)
659 , d_currentMessage(original.d_currentMessage)
660{
661 if (d_impl_p) {
662 BLPAPI_CALL(blpapi_MessageIterator_addRef)(d_impl_p);
663 }
664}
665
667{
668 blpapi_MessageIterator_destroy(d_impl_p);
669}
670
672{
673 auto copy(original);
674 copy.swap(*this);
675 return *this;
676}
677
678inline const Message& Event::iterator::operator*() const noexcept
679{
680 return d_currentMessage;
681}
682
683inline const Message *Event::iterator::operator->() const noexcept
684{
685 return &d_currentMessage;
686}
687
689{
690 d_currentMessage = Message(nullptr);
691
692 blpapi_Message_t *nextMessage = nullptr;
693 blpapi_MessageIterator_next(d_impl_p, &nextMessage);
694 d_currentMessage = Message(nextMessage);
695
696 return *this;
697}
698
700{
701 auto copy = *this;
702 ++(*this);
703 return copy;
704}
705
707{
708 using std::swap;
709 swap(d_impl_p, other.d_impl_p);
710 swap(d_currentMessage, other.d_currentMessage);
711}
712
713} // close namespace blpapi
714
716 Event::iterator const& lhs, Event::iterator const& rhs)
717{
718 if (&lhs == &rhs) {
719 return true;
720 }
721
722 if (lhs.d_impl_p == rhs.d_impl_p
723 && lhs.d_currentMessage.impl() == rhs.d_currentMessage.impl()) {
724 return true;
725 }
726
727 const bool lend = !lhs.d_impl_p || !lhs.d_currentMessage.impl();
728 const bool rend = !rhs.d_impl_p || !rhs.d_currentMessage.impl();
729
730 return lend && rend;
731}
732
734 Event::iterator const& lhs, Event::iterator const& rhs)
735{
736 return !(lhs == rhs);
737}
738
740{
741 lhs.swap(rhs);
742}
743
744} // close namespace BloombergLP
745
746#endif // #ifdef __cplusplus
747#endif // #ifndef INCLUDED_BLPAPI_EVENT
Provide functions for dispatchtbl.
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition blpapi_call.h:368
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
Common definitions used by the library.
Defines a message containing elements.
EventQueue(const EventQueue &)=delete
EventQueue & operator=(const EventQueue &)=delete
virtual int tryNextEvent(Event *event)
Definition blpapi_event.h:588
EventQueue()
Definition blpapi_event.h:579
virtual ~EventQueue()
Definition blpapi_event.h:581
virtual Event nextEvent(int timeout=0)
Definition blpapi_event.h:583
virtual void purge()
Definition blpapi_event.h:600
blpapi_EventQueue_t * handle() const
Definition blpapi_event.h:602
Definition blpapi_event.h:259
const Message & operator*() const noexcept
Definition blpapi_event.h:678
Message value_type
Definition blpapi_event.h:267
const Message * operator->() const noexcept
Definition blpapi_event.h:683
~iterator()
Definition blpapi_event.h:666
void swap(iterator &other)
Definition blpapi_event.h:706
iterator()
Definition blpapi_event.h:642
iterator & operator=(const iterator &original)
Definition blpapi_event.h:671
Message & reference
Definition blpapi_event.h:269
std::input_iterator_tag iterator_category
Definition blpapi_event.h:270
Message * pointer
Definition blpapi_event.h:268
std::ptrdiff_t difference_type
Definition blpapi_event.h:266
iterator & operator++()
Definition blpapi_event.h:688
Definition blpapi_event.h:212
iterator end() const
Definition blpapi_event.h:573
EventType
The possible types of event.
Definition blpapi_event.h:218
@ AUTHORIZATION_STATUS
Status updates for user authorization.
Definition blpapi_event.h:237
@ SESSION_STATUS
Status updates for a session.
Definition blpapi_event.h:221
@ ADMIN
Admin event.
Definition blpapi_event.h:219
@ PARTIAL_RESPONSE
A partial response to a request.
Definition blpapi_event.h:229
@ SERVICE_STATUS
Status updates for a service.
Definition blpapi_event.h:233
@ UNKNOWN
Definition blpapi_event.h:247
@ REQUEST_STATUS
Status updates for a request.
Definition blpapi_event.h:225
@ TOKEN_STATUS
Status updates for a generate token request.
Definition blpapi_event.h:243
@ RESOLUTION_STATUS
Status updates for a resolution operation.
Definition blpapi_event.h:239
@ TIMEOUT
An Event returned from Session::nextEvent() if it timed out.
Definition blpapi_event.h:235
@ REQUEST
Request event. Provided to ProviderSession only.
Definition blpapi_event.h:245
@ SUBSCRIPTION_DATA
Data updates resulting from a subscription.
Definition blpapi_event.h:231
@ TOPIC_STATUS
Status updates about topics for service providers.
Definition blpapi_event.h:241
@ SUBSCRIPTION_STATUS
Status updates for a subscription.
Definition blpapi_event.h:223
@ RESPONSE
The final (possibly only) response to a request.
Definition blpapi_event.h:227
EventType eventType() const
Definition blpapi_event.h:562
Event & operator=(const Event &rhs)
Definition blpapi_event.h:552
blpapi_Event_t * impl() const
Definition blpapi_event.h:569
bool isValid() const
Definition blpapi_event.h:567
Event()
Definition blpapi_event.h:527
~Event()
Definition blpapi_event.h:545
iterator begin() const
Definition blpapi_event.h:571
MessageIterator(const MessageIterator &)=delete
MessageIterator & operator=(const MessageIterator &)=delete
bool isValid() const
Definition blpapi_event.h:625
~MessageIterator()
Definition blpapi_event.h:615
bool next()
Definition blpapi_event.h:620
Message message(bool createClonable=false) const
Definition blpapi_event.h:630
Definition blpapi_message.h:177
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:739
Definition blpapi_abstractsession.h:212
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:637
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:660
Definition blpapi_abstractsession.h:211