BLPAPI C++ 3.26.7
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
502namespace util {
503
507
508constexpr const char *to_string(Event::EventType eventType);
512
514
515} // close namespace util
516
533
534 blpapi_EventQueue_t *d_handle_p;
535
536 public:
537 EventQueue();
541
542 EventQueue(const EventQueue&) = delete;
543 EventQueue& operator=(const EventQueue&) = delete;
544
545 virtual ~EventQueue();
550
551 virtual Event nextEvent(int timeout = 0);
559
560 virtual int tryNextEvent(Event *event);
567
568 virtual void purge();
575
577 blpapi_EventQueue_t *handle() const;
579};
580
597
598 blpapi_MessageIterator_t *d_impl_p;
599 blpapi_Message_t *d_current_p;
600
601 public:
604
605 explicit MessageIterator(const Event& event);
612
617
618 bool next();
626
627 bool isValid() const;
632
633 Message message(bool createClonable = false) const;
643};
644
645void swap(Event::iterator& lhs, Event::iterator& rhs);
647
650
651//=============================================================================
652// INLINE FUNCTION DEFINITIONS
653//=============================================================================
654
655// -----------
656// class Event
657// -----------
658
660 : d_impl_p(0)
661{
662}
663
664inline Event::Event(blpapi_Event_t *handle)
665 : d_impl_p(handle)
666{
667}
668
669inline Event::Event(const Event& original)
670 : d_impl_p(original.d_impl_p)
671{
672 if (d_impl_p) {
673 blpapi_Event_addRef(d_impl_p);
674 }
675}
676
678{
679 if (d_impl_p) {
680 blpapi_Event_release(d_impl_p);
681 }
682}
683
684inline Event& Event::operator=(const Event& rhs)
685{
686 using std::swap;
687
688 Event tmp(rhs);
689 swap(tmp.d_impl_p, d_impl_p);
690
691 return *this;
692}
693
695{
696 return (EventType)blpapi_Event_eventType(d_impl_p);
697}
698
699inline bool Event::isValid() const { return d_impl_p ? true : false; }
700
702inline blpapi_Event_t *Event::impl() const { return d_impl_p; }
704
705inline Event::iterator Event::begin() const { return iterator(*this); }
706
707inline Event::iterator Event::end() const { return iterator(); }
708
709// ----------------
710// class EventQueue
711// ----------------
712
713inline EventQueue::EventQueue() { d_handle_p = blpapi_EventQueue_create(); }
714
715inline EventQueue::~EventQueue() { blpapi_EventQueue_destroy(d_handle_p); }
716
717inline Event EventQueue::nextEvent(int timeout)
718{
719 return Event(blpapi_EventQueue_nextEvent(d_handle_p, timeout));
720}
721
723{
724 assert(event);
725
726 blpapi_Event_t *impl = 0;
727 int ret = blpapi_EventQueue_tryNextEvent(d_handle_p, &impl);
728 if (0 == ret) {
729 *event = Event(impl);
730 }
731 return ret;
732}
733
734inline void EventQueue::purge() { blpapi_EventQueue_purge(d_handle_p); }
735
737inline blpapi_EventQueue_t *EventQueue::handle() const { return d_handle_p; }
739
740// ---------------------
741// class MessageIterator
742// ---------------------
743
745 : d_impl_p(nullptr)
746 , d_current_p(nullptr)
747{
748 d_impl_p = blpapi_MessageIterator_create(event.impl());
749}
750
752{
753 blpapi_MessageIterator_destroy(d_impl_p);
754}
755
757{
758 return !blpapi_MessageIterator_next(d_impl_p, &d_current_p);
759}
760
761inline bool MessageIterator::isValid() const
762{
763 return d_current_p ? true : false;
764}
765
766inline Message MessageIterator::message(bool createClonable) const
767{
768 if (createClonable) {
769 BLPAPI_CALL_MESSAGE_ADDREF(d_current_p);
770 }
771 return Message(d_current_p, createClonable);
772}
773
774// --------------------------
775// class Event::iterator
776// --------------------------
777
779 : d_impl_p(nullptr)
780 , d_currentMessage(nullptr)
781{
782}
783
785 : iterator()
786{
787 if (event.impl()) {
788 d_impl_p = blpapi_MessageIterator_create(event.impl());
789 ++(*this);
790 }
791}
792
793inline Event::iterator::iterator(const iterator& original)
794 : d_impl_p(original.d_impl_p)
795 , d_currentMessage(original.d_currentMessage)
796{
797 if (d_impl_p) {
798 BLPAPI_CALL(blpapi_MessageIterator_addRef)(d_impl_p);
799 }
800}
801
803{
804 blpapi_MessageIterator_destroy(d_impl_p);
805}
806
808{
809 auto copy(original);
810 copy.swap(*this);
811 return *this;
812}
813
814inline const Message& Event::iterator::operator*() const noexcept
815{
816 return d_currentMessage;
817}
818
819inline const Message *Event::iterator::operator->() const noexcept
820{
821 return &d_currentMessage;
822}
823
825{
826 d_currentMessage = Message(nullptr);
827
828 blpapi_Message_t *nextMessage = nullptr;
829 blpapi_MessageIterator_next(d_impl_p, &nextMessage);
830 d_currentMessage = Message(nextMessage);
831
832 return *this;
833}
834
836{
837 auto copy = *this;
838 ++(*this);
839 return copy;
840}
841
843{
844 using std::swap;
845 swap(d_impl_p, other.d_impl_p);
846 swap(d_currentMessage, other.d_currentMessage);
847}
848
849// --------------
850// namespace util
851// --------------
853{
854 switch (eventType) {
855 case Event::ADMIN:
856 return "ADMIN";
858 return "SESSION_STATUS";
860 return "SUBSCRIPTION_STATUS";
862 return "REQUEST_STATUS";
863 case Event::RESPONSE:
864 return "RESPONSE";
866 return "PARTIAL_RESPONSE";
868 return "SUBSCRIPTION_DATA";
870 return "SERVICE_STATUS";
871 case Event::TIMEOUT:
872 return "TIMEOUT";
874 return "AUTHORIZATION_STATUS";
876 return "RESOLUTION_STATUS";
878 return "TOPIC_STATUS";
880 return "TOKEN_STATUS";
881 case Event::REQUEST:
882 return "REQUEST";
883 case Event::UNKNOWN:
884 return "UNKNOWN";
885 }
886 // Silence warnings on some compilers
887 return "UNDEFINED";
888}
889
890} // close namespace blpapi
891
893 Event::iterator const& lhs, Event::iterator const& rhs)
894{
895 if (&lhs == &rhs) {
896 return true;
897 }
898
899 if (lhs.d_impl_p == rhs.d_impl_p
900 && lhs.d_currentMessage.impl() == rhs.d_currentMessage.impl()) {
901 return true;
902 }
903
904 const bool lend = !lhs.d_impl_p || !lhs.d_currentMessage.impl();
905 const bool rend = !rhs.d_impl_p || !rhs.d_currentMessage.impl();
906
907 return lend && rend;
908}
909
911 Event::iterator const& lhs, Event::iterator const& rhs)
912{
913 return !(lhs == rhs);
914}
915
917{
918 lhs.swap(rhs);
919}
920
921} // close namespace BloombergLP
922
923#endif // #ifdef __cplusplus
924#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:722
EventQueue()
Definition blpapi_event.h:713
virtual ~EventQueue()
Definition blpapi_event.h:715
virtual Event nextEvent(int timeout=0)
Definition blpapi_event.h:717
virtual void purge()
Definition blpapi_event.h:734
Definition blpapi_event.h:372
const Message & operator*() const noexcept
Definition blpapi_event.h:814
Message value_type
Definition blpapi_event.h:380
const Message * operator->() const noexcept
Definition blpapi_event.h:819
~iterator()
Definition blpapi_event.h:802
void swap(iterator &other)
Definition blpapi_event.h:842
iterator()
Definition blpapi_event.h:778
iterator & operator=(const iterator &original)
Definition blpapi_event.h:807
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:824
Definition blpapi_event.h:325
iterator end() const
Definition blpapi_event.h:707
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:694
Event & operator=(const Event &rhs)
Definition blpapi_event.h:684
bool isValid() const
Definition blpapi_event.h:699
Event()
Definition blpapi_event.h:659
~Event()
Definition blpapi_event.h:677
iterator begin() const
Definition blpapi_event.h:705
MessageIterator(const MessageIterator &)=delete
MessageIterator & operator=(const MessageIterator &)=delete
bool isValid() const
Definition blpapi_event.h:761
~MessageIterator()
Definition blpapi_event.h:751
bool next()
Definition blpapi_event.h:756
Message message(bool createClonable=false) const
Definition blpapi_event.h:766
Definition blpapi_message.h:344
constexpr const char * to_string(CorrelationId::ValueType valueType)
Definition blpapi_correlationid.h:830
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:916
Definition blpapi_correlationid.h:499
Definition blpapi_abstractsession.h:448
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:749
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:772
Definition blpapi_abstractsession.h:447