BLPAPI C++ 3.25.12
Loading...
Searching...
No Matches
blpapi_message.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_MESSAGE
29#define INCLUDED_BLPAPI_MESSAGE
30
61#include <blpapi_call.h>
63#include <blpapi_defs.h>
64#include <blpapi_deprecate.h>
65#include <blpapi_element.h>
66#include <blpapi_name.h>
67#include <blpapi_service.h>
68#include <blpapi_streamproxy.h>
69#include <blpapi_timepoint.h>
70
71struct blpapi_Message;
72typedef struct blpapi_Message blpapi_Message_t;
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
80
82const char *blpapi_Message_typeString(const blpapi_Message_t *message);
83
85const char *blpapi_Message_topicName(const blpapi_Message_t *message);
86
89
92
95 const blpapi_Message_t *message, size_t index);
96
99 const blpapi_Message_t *message, const char **requestId);
100
103
106 const blpapi_Message_t *message, size_t *size);
107
110
113
116 blpapi_StreamWriter_t streamWriter,
117 void *stream,
118 int indentLevel,
119 int spacesPerLevel);
120
123
126
129 const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
130
131#ifdef __cplusplus
132}
133
141namespace BloombergLP {
142namespace blpapi {
143
161class Message {
162
163 blpapi_Message_t *d_handle;
164 Element d_elements;
165 bool d_isCloned;
166
167 public:
182
206
207 public:
208 // CREATORS
209
211 explicit Message(blpapi_Message_t *handle, bool clonable = false);
220
221 Message(const Message& original);
230 ~Message();
237 // MANIUPLATORS
238 Message& operator=(const Message& rhs);
247 // ACCESSORS
248 Name messageType() const;
253 BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char *topicName() const;
276 Service service() const;
281 int numCorrelationIds() const;
297 CorrelationId correlationId(size_t index = 0) const;
311 bool hasElement(const Name& name, bool excludeNullElements = false) const;
316 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
317 const char *name, bool excludeNullElements = false) const;
326 size_t numElements() const;
331 const Element getElement(const Name& name) const;
336 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
337 const char *name) const;
344 bool getElementAsBool(const Name& name) const;
349 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
356 char getElementAsChar(const Name& name) const;
361 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
368 Int32 getElementAsInt32(const Name& name) const;
373 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
374 const char *name) const;
381 Int64 getElementAsInt64(const Name& name) const;
386 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
387 const char *name) const;
394 Float32 getElementAsFloat32(const Name& name) const;
399 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
400 const char *name) const;
407 Float64 getElementAsFloat64(const Name& name) const;
412 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
413 const char *name) const;
420 Datetime getElementAsDatetime(const Name& name) const;
425 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
426 const char *name) const;
433 const char *getElementAsString(const Name& name) const;
438 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
439 const char *name) const;
446 Bytes getElementAsBytes(const Name& name) const;
451 const char *getRequestId() const;
464 const Element asElement() const;
470 std::string toJson() const;
479 BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
480 size_t *size) const;
491 Fragment fragmentType() const;
498 int timeReceived(TimePoint *timestamp) const;
510 std::ostream& print(
511 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
526 const blpapi_Message_t *impl() const;
531 blpapi_Message_t *impl();
536};
537
541// FREE OPERATORS
542std::ostream& operator<<(std::ostream& stream, const Message& message);
555// ============================================================================
556// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
557// ============================================================================
558
559// -------------
560// class Message
561// -------------
562// CREATORS
563inline Message::Message(blpapi_Message_t *handle, bool clonable)
564 : d_handle(handle)
565 , d_isCloned(clonable)
566{
567 if (handle) {
568 d_elements = Element(blpapi_Message_elements(handle));
569 }
570}
571
572inline Message::Message(const Message& original)
573 : d_handle(original.d_handle)
574 , d_elements(original.d_elements)
575 , d_isCloned(true)
576{
577 if (d_handle) {
579 }
580}
581
583{
584 if (d_isCloned && d_handle) {
586 }
587}
588// MANIPULATORS
590{
591
592 if (this == &rhs) {
593 return *this;
594 }
595
596 if (d_isCloned && (d_handle == rhs.d_handle)) {
597 return *this;
598 }
599
600 if (d_isCloned && d_handle) {
602 }
603 d_handle = rhs.d_handle;
604 d_elements = rhs.d_elements;
605 d_isCloned = true;
606
607 if (d_handle) {
609 }
610
611 return *this;
612}
613
614// ACCESSORS
616{
617 return Name(blpapi_Message_messageType(d_handle));
618}
619
620inline const char *Message::topicName() const
621{
622 return blpapi_Message_topicName(d_handle);
623}
624
626{
627 return Service(blpapi_Message_service(d_handle));
628}
629
631{
632 return blpapi_Message_numCorrelationIds(d_handle);
633}
634
635inline CorrelationId Message::correlationId(size_t index) const
636{
637 if (index >= (size_t)numCorrelationIds())
638 throw IndexOutOfRangeException("index >= numCorrelationIds");
639 return CorrelationId(blpapi_Message_correlationId(d_handle, index));
640}
641
643 const char *name, bool excludeNullElements) const
644{
645 return d_elements.hasElement(Name(name), excludeNullElements);
646}
647
649 const Name& name, bool excludeNullElements) const
650{
651 return d_elements.hasElement(name, excludeNullElements);
652}
653
654inline size_t Message::numElements() const { return d_elements.numElements(); }
655
656inline const Element Message::getElement(const Name& name) const
657{
658 return d_elements.getElement(name);
659}
660
661inline const Element Message::getElement(const char *nameString) const
662{
663 return d_elements.getElement(Name(nameString));
664}
665
666inline bool Message::getElementAsBool(const Name& name) const
667{
668 return d_elements.getElementAsBool(name);
669}
670
671inline bool Message::getElementAsBool(const char *name) const
672{
673 return d_elements.getElementAsBool(Name(name));
674}
675
676inline char Message::getElementAsChar(const Name& name) const
677{
678 return d_elements.getElementAsChar(name);
679}
680
681inline char Message::getElementAsChar(const char *name) const
682{
683 return d_elements.getElementAsChar(Name(name));
684}
685
686inline Int32 Message::getElementAsInt32(const Name& name) const
687{
688 return d_elements.getElementAsInt32(name);
689}
690
691inline Int32 Message::getElementAsInt32(const char *name) const
692{
693 return d_elements.getElementAsInt32(Name(name));
694}
695
696inline Int64 Message::getElementAsInt64(const Name& name) const
697{
698 return d_elements.getElementAsInt64(name);
699}
700
701inline Int64 Message::getElementAsInt64(const char *name) const
702{
703 return d_elements.getElementAsInt64(Name(name));
704}
705
707{
708 return d_elements.getElementAsFloat32(name);
709}
710
711inline Float32 Message::getElementAsFloat32(const char *name) const
712{
713 return d_elements.getElementAsFloat32(Name(name));
714}
715
717{
718 return d_elements.getElementAsFloat64(name);
719}
720
721inline Float64 Message::getElementAsFloat64(const char *name) const
722{
723 return d_elements.getElementAsFloat64(Name(name));
724}
725
727{
728 return d_elements.getElementAsDatetime(name);
729}
730
731inline Datetime Message::getElementAsDatetime(const char *name) const
732{
733 return d_elements.getElementAsDatetime(Name(name));
734}
735
736inline const char *Message::getElementAsString(const Name& name) const
737{
738 return d_elements.getElementAsString(name);
739}
740
741inline const char *Message::getElementAsString(const char *name) const
742{
743 return d_elements.getElementAsString(Name(name));
744}
745
746inline Bytes Message::getElementAsBytes(const Name& name) const
747{
748 return d_elements.getElementAsBytes(name);
749}
750
751inline const char *Message::getRequestId() const
752{
753 const char *requestId = 0;
754 BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
755 return requestId;
756}
757
758inline const Element Message::asElement() const { return d_elements; }
759
760inline std::string Message::toJson() const { return d_elements.toJson(); }
761
762inline const char *Message::getPrivateData(size_t *size) const
763{
764 return blpapi_Message_privateData(d_handle, size);
765}
766
771
773{
774 return static_cast<Message::RecapType::Type>(
776}
777
778inline int Message::timeReceived(TimePoint *timestamp) const
779{
780 return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
781}
782
783inline std::ostream& Message::print(
784 std::ostream& stream, int level, int spacesPerLevel) const
785{
788 (d_handle,
790 &stream,
791 level,
792 spacesPerLevel);
793 return stream;
794 } else {
795 return d_elements.print(stream, level, spacesPerLevel);
796 }
797}
798
799inline std::ostream& operator<<(std::ostream& stream, const Message& message)
800{
801 return message.print(stream, 0, -1);
802}
803
804inline const blpapi_Message_t *Message::impl() const { return d_handle; }
805
806inline blpapi_Message_t *Message::impl() { return d_handle; }
807
808} // close namespace blpapi
809} // close namespace BloombergLP
810
811#endif // #ifdef __cplusplus
812#endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Provide functions for dispatchtbl.
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition blpapi_call.h:360
#define BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(a1)
Definition blpapi_call.h:370
#define BLPAPI_CALL_AVAILABLE(FUNCNAME)
Definition blpapi_call.h:352
#define BLPAPI_CALL_MESSAGE_TIMERECEIVED(a1, a2)
Definition blpapi_call.h:453
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:353
#define BLPAPI_CALL_MESSAGE_RELEASE(a1)
Definition blpapi_call.h:361
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
#define BLPAPI_MESSAGE_RECAPTYPE_NONE
Definition blpapi_defs.h:150
#define BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE
Definition blpapi_defs.h:147
#define BLPAPI_MESSAGE_FRAGMENT_END
Definition blpapi_defs.h:148
#define BLPAPI_MESSAGE_FRAGMENT_NONE
Definition blpapi_defs.h:145
#define BLPAPI_MESSAGE_FRAGMENT_START
Definition blpapi_defs.h:146
#define BLPAPI_MESSAGE_RECAPTYPE_UNSOLICITED
Definition blpapi_defs.h:152
#define BLPAPI_EXPORT
Definition blpapi_defs.h:172
#define BLPAPI_MESSAGE_RECAPTYPE_SOLICITED
Definition blpapi_defs.h:151
struct blpapi_CorrelationId_t_ blpapi_CorrelationId_t
Definition blpapi_dispatchtbl.h:74
struct blpapi_Message blpapi_Message_t
Definition blpapi_dispatchtbl.h:80
Provide a representation of an item in a message.
BLPAPI_EXPORT const char * blpapi_Message_privateData(const blpapi_Message_t *message, size_t *size)
BLPAPI_EXPORT int blpapi_Message_release(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_fragmentType(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_timeReceived(const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived)
BLPAPI_EXPORT const char * blpapi_Message_typeString(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_getRequestId(const blpapi_Message_t *message, const char **requestId)
BLPAPI_EXPORT const char * blpapi_Message_topicName(const blpapi_Message_t *message)
BLPAPI_EXPORT blpapi_Name_t * blpapi_Message_messageType(const blpapi_Message_t *message)
BLPAPI_EXPORT blpapi_Service_t * blpapi_Message_service(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_addRef(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_recapType(const blpapi_Message_t *message)
BLPAPI_EXPORT blpapi_CorrelationId_t blpapi_Message_correlationId(const blpapi_Message_t *message, size_t index)
BLPAPI_EXPORT int blpapi_Message_numCorrelationIds(const blpapi_Message_t *message)
BLPAPI_EXPORT blpapi_Element_t * blpapi_Message_elements(const blpapi_Message_t *message)
BLPAPI_EXPORT int blpapi_Message_print(const blpapi_Message_t *message, blpapi_StreamWriter_t streamWriter, void *stream, int indentLevel, int spacesPerLevel)
Provide a representation of strings for use as container keys.
A service which provides access to API data (provide or consume).
A signature for callback on print and default C++ implementation.
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:53
Provide a time point with respect to an epoch.
Definition blpapi_types.h:312
Definition blpapi_correlationid.h:206
Definition blpapi_datetime.h:245
Definition blpapi_element.h:473
BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(const char *name) const
Definition blpapi_element.h:2326
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_element.h:2346
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition blpapi_element.h:1946
BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(const char *name) const
Definition blpapi_element.h:2316
BLPAPI_DEPRECATE_STRING_NAME bool hasElement(const char *name, bool excludeNullElements=false) const
Definition blpapi_element.h:2037
BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const
Definition blpapi_element.h:2266
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_element.h:2363
BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const
Definition blpapi_element.h:2276
std::string toJson() const
Definition blpapi_element.h:2374
BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(const char *name) const
Definition blpapi_element.h:2296
BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(const char *name) const
Definition blpapi_element.h:2286
BLPAPI_DEPRECATE_STRING_NAME const char * getElementAsString(const char *name) const
Definition blpapi_element.h:2336
BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(const char *name) const
Definition blpapi_element.h:2306
size_t numElements() const
Definition blpapi_element.h:2021
Definition blpapi_exception.h:271
Definition blpapi_message.h:161
Service service() const
Definition blpapi_message.h:625
Fragment
Definition blpapi_message.h:171
@ FRAGMENT_END
the last fragmented message
Definition blpapi_message.h:179
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:173
@ FRAGMENT_INTERMEDIATE
intermediate fragmented messages
Definition blpapi_message.h:177
@ FRAGMENT_START
the first fragmented message
Definition blpapi_message.h:175
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_message.h:746
Message & operator=(const Message &rhs)
Definition blpapi_message.h:589
const char * getElementAsString(const Name &name) const
Definition blpapi_message.h:736
const Element getElement(const Name &name) const
Definition blpapi_message.h:656
const Element asElement() const
Definition blpapi_message.h:758
int timeReceived(TimePoint *timestamp) const
Definition blpapi_message.h:778
BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char * topicName() const
Definition blpapi_message.h:620
CorrelationId correlationId(size_t index=0) const
Definition blpapi_message.h:635
BLPAPI_DEPRECATE_STRING_NAME const char * getPrivateData(size_t *size) const
Definition blpapi_message.h:762
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_message.h:783
int numCorrelationIds() const
Definition blpapi_message.h:630
~Message()
Definition blpapi_message.h:582
Message(const Message &original)
Definition blpapi_message.h:563
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition blpapi_message.h:648
Name messageType() const
Definition blpapi_message.h:615
std::string toJson() const
Definition blpapi_message.h:760
Fragment fragmentType() const
Definition blpapi_message.h:767
Int64 getElementAsInt64(const Name &name) const
Definition blpapi_message.h:696
RecapType::Type recapType() const
Definition blpapi_message.h:772
char getElementAsChar(const Name &name) const
Definition blpapi_message.h:676
const char * getRequestId() const
Definition blpapi_message.h:751
Float32 getElementAsFloat32(const Name &name) const
Definition blpapi_message.h:706
Datetime getElementAsDatetime(const Name &name) const
Definition blpapi_message.h:726
bool getElementAsBool(const Name &name) const
Definition blpapi_message.h:666
Int32 getElementAsInt32(const Name &name) const
Definition blpapi_message.h:686
Float64 getElementAsFloat64(const Name &name) const
Definition blpapi_message.h:716
size_t numElements() const
Definition blpapi_message.h:654
Definition blpapi_name.h:150
Definition blpapi_service.h:304
struct blpapi_Service blpapi_Service_t
Definition blpapi_types.h:166
struct blpapi_Name blpapi_Name_t
Definition blpapi_types.h:154
struct blpapi_Element blpapi_Element_t
Definition blpapi_types.h:136
blpapi_Float64_t Float64
Definition blpapi_types.h:474
blpapi_Float32_t Float32
Definition blpapi_types.h:473
blpapi_Int64_t Int64
Definition blpapi_types.h:471
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:647
blpapi_Int32_t Int32
Definition blpapi_types.h:469
Definition blpapi_abstractsession.h:195
Definition blpapi_message.h:196
Type
Definition blpapi_message.h:197
@ e_unsolicited
generated at discretion of the service
Definition blpapi_message.h:202
@ e_solicited
generated on request by subscriber
Definition blpapi_message.h:200
@ e_none
normal data tick; not a recap
Definition blpapi_message.h:198
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:93
Definition blpapi_timepoint.h:104