BLPAPI C++ 3.26.6
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
37
38#ifndef INCLUDED_BLPAPI_EVENT
39#define INCLUDED_BLPAPI_EVENT
40
119
120#include <blpapi_call.h>
121#include <blpapi_defs.h>
122#include <blpapi_message.h>
123
124#ifdef __cplusplus
125extern "C" {
126#endif
127
129
132
142BLPAPI_EXPORT
143int blpapi_Event_eventType(const blpapi_Event_t *event);
144
156BLPAPI_EXPORT
157int blpapi_Event_addRef(const blpapi_Event_t *event);
158
169BLPAPI_EXPORT
170int blpapi_Event_release(const blpapi_Event_t *event);
171
179BLPAPI_EXPORT
180blpapi_EventQueue_t *blpapi_EventQueue_create(void);
181
189BLPAPI_EXPORT
190int blpapi_EventQueue_destroy(blpapi_EventQueue_t *eventQueue);
191
205BLPAPI_EXPORT
206blpapi_Event_t *blpapi_EventQueue_nextEvent(
207 blpapi_EventQueue_t *eventQueue, int timeout);
208
218BLPAPI_EXPORT
219int blpapi_EventQueue_purge(blpapi_EventQueue_t *eventQueue);
220
233BLPAPI_EXPORT
234int blpapi_EventQueue_tryNextEvent(
235 blpapi_EventQueue_t *eventQueue, blpapi_Event_t **eventPointer);
236
248BLPAPI_EXPORT
249blpapi_MessageIterator_t *blpapi_MessageIterator_create(
250 const blpapi_Event_t *event);
251
258BLPAPI_EXPORT
259void blpapi_MessageIterator_destroy(blpapi_MessageIterator_t *iterator);
260
272BLPAPI_EXPORT
273int blpapi_MessageIterator_next(
274 blpapi_MessageIterator_t *iterator, blpapi_Message_t **result);
275
285BLPAPI_EXPORT
286int blpapi_MessageIterator_addRef(const blpapi_MessageIterator_t *iterator);
287
290
291#ifdef __cplusplus
292}
293
294#include <cassert>
295#include <utility>
296
297namespace BloombergLP {
298namespace blpapi {
305
325class Event {
326
327 blpapi_Event_t *d_impl_p;
328
329 public:
332 ADMIN = BLPAPI_EVENTTYPE_ADMIN,
334 SESSION_STATUS = BLPAPI_EVENTTYPE_SESSION_STATUS,
336 SUBSCRIPTION_STATUS = BLPAPI_EVENTTYPE_SUBSCRIPTION_STATUS,
338 REQUEST_STATUS = BLPAPI_EVENTTYPE_REQUEST_STATUS,
340 RESPONSE = BLPAPI_EVENTTYPE_RESPONSE,
342 PARTIAL_RESPONSE = BLPAPI_EVENTTYPE_PARTIAL_RESPONSE,
344 SUBSCRIPTION_DATA = BLPAPI_EVENTTYPE_SUBSCRIPTION_DATA,
346 SERVICE_STATUS = BLPAPI_EVENTTYPE_SERVICE_STATUS,
348 TIMEOUT = BLPAPI_EVENTTYPE_TIMEOUT,
350 AUTHORIZATION_STATUS = BLPAPI_EVENTTYPE_AUTHORIZATION_STATUS,
352 RESOLUTION_STATUS = BLPAPI_EVENTTYPE_RESOLUTION_STATUS,
354 TOPIC_STATUS = BLPAPI_EVENTTYPE_TOPIC_STATUS,
356 TOKEN_STATUS = BLPAPI_EVENTTYPE_TOKEN_STATUS,
358 REQUEST = BLPAPI_EVENTTYPE_REQUEST,
361 };
362
372 class iterator {
373 // DATA
374 blpapi_MessageIterator_t *d_impl_p;
375 Message d_currentMessage;
376
377 public:
378 // TYPES
379 using difference_type = std::ptrdiff_t;
381 using pointer = Message *;
383 using iterator_category = std::input_iterator_tag;
384
385 // CREATORS
386 iterator();
388
389 explicit iterator(const Event& event);
394
395 iterator(const iterator& original);
401
402 ~iterator();
403
404 // MANIPULATORS
405 iterator& operator=(const iterator& original);
411
418
419 iterator operator++(int);
427
428 void swap(iterator& other);
432
433 // ACCESSORS
434 const Message& operator*() const noexcept;
435 const Message *operator->() const noexcept;
436
437 // FRIENDS
438 friend bool operator==(const iterator& lhs, const iterator& rhs);
439 };
440
441 Event();
447
448 Event(blpapi_Event_t *handle);
449
450 Event(const Event& original);
456
457 ~Event();
463
464 Event& operator=(const Event& rhs);
470
471 EventType eventType() const;
475
476 bool isValid() const;
480
482 blpapi_Event_t *impl() const;
484
485 iterator begin() const;
486 iterator end() const;
487};
488
489// FREE OPERATORS
490bool operator==(const Event::iterator& lhs, const Event::iterator& rhs);
495
496bool operator!=(const Event::iterator& lhs, const Event::iterator& rhs);
501
518
519 blpapi_EventQueue_t *d_handle_p;
520
521 public:
522 EventQueue();
526
527 EventQueue(const EventQueue&) = delete;
528 EventQueue& operator=(const EventQueue&) = delete;
529
530 virtual ~EventQueue();
535
536 virtual Event nextEvent(int timeout = 0);
544
545 virtual int tryNextEvent(Event *event);
552
553 virtual void purge();
560
562 blpapi_EventQueue_t *handle() const;
564};
565
582
583 blpapi_MessageIterator_t *d_impl_p;
584 blpapi_Message_t *d_current_p;
585
586 public:
589
590 explicit MessageIterator(const Event& event);
597
602
603 bool next();
611
612 bool isValid() const;
617
618 Message message(bool createClonable = false) const;
628};
629
630void swap(Event::iterator& lhs, Event::iterator& rhs);
632
635
636//=============================================================================
637// INLINE FUNCTION DEFINITIONS
638//=============================================================================
639
640// -----------
641// class Event
642// -----------
643
645 : d_impl_p(0)
646{
647}
648
649inline Event::Event(blpapi_Event_t *handle)
650 : d_impl_p(handle)
651{
652}
653
654inline Event::Event(const Event& original)
655 : d_impl_p(original.d_impl_p)
656{
657 if (d_impl_p) {
658 blpapi_Event_addRef(d_impl_p);
659 }
660}
661
663{
664 if (d_impl_p) {
665 blpapi_Event_release(d_impl_p);
666 }
667}
668
669inline Event& Event::operator=(const Event& rhs)
670{
671 using std::swap;
672
673 Event tmp(rhs);
674 swap(tmp.d_impl_p, d_impl_p);
675
676 return *this;
677}
678
680{
681 return (EventType)blpapi_Event_eventType(d_impl_p);
682}
683
684inline bool Event::isValid() const { return d_impl_p ? true : false; }
685
687inline blpapi_Event_t *Event::impl() const { return d_impl_p; }
689
690inline Event::iterator Event::begin() const { return iterator(*this); }
691
692inline Event::iterator Event::end() const { return iterator(); }
693
694// ----------------
695// class EventQueue
696// ----------------
697
698inline EventQueue::EventQueue() { d_handle_p = blpapi_EventQueue_create(); }
699
700inline EventQueue::~EventQueue() { blpapi_EventQueue_destroy(d_handle_p); }
701
702inline Event EventQueue::nextEvent(int timeout)
703{
704 return Event(blpapi_EventQueue_nextEvent(d_handle_p, timeout));
705}
706
708{
709 assert(event);
710
711 blpapi_Event_t *impl = 0;
712 int ret = blpapi_EventQueue_tryNextEvent(d_handle_p, &impl);
713 if (0 == ret) {
714 *event = Event(impl);
715 }
716 return ret;
717}
718
719inline void EventQueue::purge() { blpapi_EventQueue_purge(d_handle_p); }
720
722inline blpapi_EventQueue_t *EventQueue::handle() const { return d_handle_p; }
724
725// ---------------------
726// class MessageIterator
727// ---------------------
728
730 : d_impl_p(nullptr)
731 , d_current_p(nullptr)
732{
733 d_impl_p = blpapi_MessageIterator_create(event.impl());
734}
735
737{
738 blpapi_MessageIterator_destroy(d_impl_p);
739}
740
742{
743 return !blpapi_MessageIterator_next(d_impl_p, &d_current_p);
744}
745
746inline bool MessageIterator::isValid() const
747{
748 return d_current_p ? true : false;
749}
750
751inline Message MessageIterator::message(bool createClonable) const
752{
753 if (createClonable) {
754 BLPAPI_CALL_MESSAGE_ADDREF(d_current_p);
755 }
756 return Message(d_current_p, createClonable);
757}
758
759// --------------------------
760// class Event::iterator
761// --------------------------
762
764 : d_impl_p(nullptr)
765 , d_currentMessage(nullptr)
766{
767}
768
770 : iterator()
771{
772 if (event.impl()) {
773 d_impl_p = blpapi_MessageIterator_create(event.impl());
774 ++(*this);
775 }
776}
777
778inline Event::iterator::iterator(const iterator& original)
779 : d_impl_p(original.d_impl_p)
780 , d_currentMessage(original.d_currentMessage)
781{
782 if (d_impl_p) {
783 BLPAPI_CALL(blpapi_MessageIterator_addRef)(d_impl_p);
784 }
785}
786
788{
789 blpapi_MessageIterator_destroy(d_impl_p);
790}
791
793{
794 auto copy(original);
795 copy.swap(*this);
796 return *this;
797}
798
799inline const Message& Event::iterator::operator*() const noexcept
800{
801 return d_currentMessage;
802}
803
804inline const Message *Event::iterator::operator->() const noexcept
805{
806 return &d_currentMessage;
807}
808
810{
811 d_currentMessage = Message(nullptr);
812
813 blpapi_Message_t *nextMessage = nullptr;
814 blpapi_MessageIterator_next(d_impl_p, &nextMessage);
815 d_currentMessage = Message(nextMessage);
816
817 return *this;
818}
819
821{
822 auto copy = *this;
823 ++(*this);
824 return copy;
825}
826
828{
829 using std::swap;
830 swap(d_impl_p, other.d_impl_p);
831 swap(d_currentMessage, other.d_currentMessage);
832}
833
834} // close namespace blpapi
835
837 Event::iterator const& lhs, Event::iterator const& rhs)
838{
839 if (&lhs == &rhs) {
840 return true;
841 }
842
843 if (lhs.d_impl_p == rhs.d_impl_p
844 && lhs.d_currentMessage.impl() == rhs.d_currentMessage.impl()) {
845 return true;
846 }
847
848 const bool lend = !lhs.d_impl_p || !lhs.d_currentMessage.impl();
849 const bool rend = !rhs.d_impl_p || !rhs.d_currentMessage.impl();
850
851 return lend && rend;
852}
853
855 Event::iterator const& lhs, Event::iterator const& rhs)
856{
857 return !(lhs == rhs);
858}
859
861{
862 lhs.swap(rhs);
863}
864
865} // close namespace BloombergLP
866
867#endif // #ifdef __cplusplus
868#endif // #ifndef INCLUDED_BLPAPI_EVENT
Provide functions for dispatchtbl.
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:707
EventQueue()
Definition blpapi_event.h:698
virtual ~EventQueue()
Definition blpapi_event.h:700
virtual Event nextEvent(int timeout=0)
Definition blpapi_event.h:702
virtual void purge()
Definition blpapi_event.h:719
Definition blpapi_event.h:372
const Message & operator*() const noexcept
Definition blpapi_event.h:799
Message value_type
Definition blpapi_event.h:380
const Message * operator->() const noexcept
Definition blpapi_event.h:804
~iterator()
Definition blpapi_event.h:787
void swap(iterator &other)
Definition blpapi_event.h:827
iterator()
Definition blpapi_event.h:763
iterator & operator=(const iterator &original)
Definition blpapi_event.h:792
Message & reference
Definition blpapi_event.h:382
std::input_iterator_tag iterator_category
Definition blpapi_event.h:383
Message * pointer
Definition blpapi_event.h:381
std::ptrdiff_t difference_type
Definition blpapi_event.h:379
iterator & operator++()
Definition blpapi_event.h:809
Definition blpapi_event.h:325
iterator end() const
Definition blpapi_event.h:692
EventType
The possible types of event.
Definition blpapi_event.h:331
@ AUTHORIZATION_STATUS
Status updates for user authorization.
Definition blpapi_event.h:350
@ SESSION_STATUS
Status updates for a session.
Definition blpapi_event.h:334
@ ADMIN
Admin event.
Definition blpapi_event.h:332
@ PARTIAL_RESPONSE
A partial response to a request.
Definition blpapi_event.h:342
@ SERVICE_STATUS
Status updates for a service.
Definition blpapi_event.h:346
@ UNKNOWN
Definition blpapi_event.h:360
@ REQUEST_STATUS
Status updates for a request.
Definition blpapi_event.h:338
@ TOKEN_STATUS
Status updates for a generate token request.
Definition blpapi_event.h:356
@ RESOLUTION_STATUS
Status updates for a resolution operation.
Definition blpapi_event.h:352
@ TIMEOUT
An Event returned from Session::nextEvent() if it timed out.
Definition blpapi_event.h:348
@ REQUEST
Request event. Provided to ProviderSession only.
Definition blpapi_event.h:358
@ SUBSCRIPTION_DATA
Data updates resulting from a subscription.
Definition blpapi_event.h:344
@ TOPIC_STATUS
Status updates about topics for service providers.
Definition blpapi_event.h:354
@ SUBSCRIPTION_STATUS
Status updates for a subscription.
Definition blpapi_event.h:336
@ RESPONSE
The final (possibly only) response to a request.
Definition blpapi_event.h:340
EventType eventType() const
Definition blpapi_event.h:679
Event & operator=(const Event &rhs)
Definition blpapi_event.h:669
bool isValid() const
Definition blpapi_event.h:684
Event()
Definition blpapi_event.h:644
~Event()
Definition blpapi_event.h:662
iterator begin() const
Definition blpapi_event.h:690
MessageIterator(const MessageIterator &)=delete
MessageIterator & operator=(const MessageIterator &)=delete
bool isValid() const
Definition blpapi_event.h:746
~MessageIterator()
Definition blpapi_event.h:736
bool next()
Definition blpapi_event.h:741
Message message(bool createClonable=false) const
Definition blpapi_event.h:751
Definition blpapi_message.h:344
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:860
Definition blpapi_abstractsession.h:452
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:718
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:741
Definition blpapi_abstractsession.h:451