BLPAPI C++ 3.26.9
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
37
38#ifndef INCLUDED_BLPAPI_MESSAGE
39#define INCLUDED_BLPAPI_MESSAGE
40
69
70#include <blpapi_call.h>
72#include <blpapi_defs.h>
73#include <blpapi_deprecate.h>
74#include <blpapi_element.h>
75#include <blpapi_name.h>
76#include <blpapi_service.h>
77#include <blpapi_streamproxy.h>
78#include <blpapi_timepoint.h>
79
80struct blpapi_Message;
81#ifdef __cplusplus
82extern "C" {
83#endif
84
86typedef struct blpapi_Message blpapi_Message_t;
87
91
100BLPAPI_EXPORT
101blpapi_Name_t *blpapi_Message_messageType(const blpapi_Message_t *message);
102
113BLPAPI_EXPORT
114const char *blpapi_Message_typeString(const blpapi_Message_t *message);
115
130BLPAPI_EXPORT
131const char *blpapi_Message_topicName(const blpapi_Message_t *message);
132
141BLPAPI_EXPORT
142blpapi_Service_t *blpapi_Message_service(const blpapi_Message_t *message);
143
157BLPAPI_EXPORT
158blpapi_Name_t *blpapi_Message_operationName(const blpapi_Message_t *message);
159
167BLPAPI_EXPORT
168int blpapi_Message_numCorrelationIds(const blpapi_Message_t *message);
169
180BLPAPI_EXPORT
181blpapi_CorrelationId_t blpapi_Message_correlationId(
182 const blpapi_Message_t *message, size_t index);
183
196BLPAPI_EXPORT
197int blpapi_Message_getRequestId(
198 const blpapi_Message_t *message, const char **requestId);
199
208BLPAPI_EXPORT
209blpapi_Element_t *blpapi_Message_elements(const blpapi_Message_t *message);
210
224BLPAPI_EXPORT
225const char *blpapi_Message_privateData(
226 const blpapi_Message_t *message, size_t *size);
227
239BLPAPI_EXPORT
240int blpapi_Message_fragmentType(const blpapi_Message_t *message);
241
253BLPAPI_EXPORT
254int blpapi_Message_recapType(const blpapi_Message_t *message);
255
273BLPAPI_EXPORT
274int blpapi_Message_print(const blpapi_Message_t *message,
275 blpapi_StreamWriter_t streamWriter,
276 void *stream,
277 int indentLevel,
278 int spacesPerLevel);
279
292BLPAPI_EXPORT
293int blpapi_Message_addRef(const blpapi_Message_t *message);
294
307BLPAPI_EXPORT
308int blpapi_Message_release(const blpapi_Message_t *message);
309
324BLPAPI_EXPORT
325int blpapi_Message_timeReceived(
326 const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
327
330
331#ifdef __cplusplus
332}
333
334namespace BloombergLP {
335namespace blpapi {
342
360class Message {
361
362 blpapi_Message_t *d_handle;
363 Element d_elements;
364 bool d_isCloned;
365
366 public:
370 enum Fragment {
371
372 FRAGMENT_NONE = BLPAPI_MESSAGE_FRAGMENT_NONE,
374 FRAGMENT_START = BLPAPI_MESSAGE_FRAGMENT_START,
376 FRAGMENT_INTERMEDIATE = BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE,
378 FRAGMENT_END = BLPAPI_MESSAGE_FRAGMENT_END
380 };
381
395 struct RecapType {
396 enum Type {
397 e_none = BLPAPI_MESSAGE_RECAPTYPE_NONE,
399 e_solicited = BLPAPI_MESSAGE_RECAPTYPE_SOLICITED,
401 e_unsolicited = BLPAPI_MESSAGE_RECAPTYPE_UNSOLICITED
403 };
404 };
405
406 public:
407 // CREATORS
408
410 explicit Message(blpapi_Message_t *handle, bool clonable = false);
419
420 Message(const Message& original);
428
429 ~Message();
435
436 // MANIUPLATORS
437 Message& operator=(const Message& rhs);
445
446 // ACCESSORS
447 Name messageType() const;
451
452 BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char *topicName() const;
474
475 Service service() const;
479
480 Name operationName() const;
492
493 int numCorrelationIds() const;
508
509 CorrelationId correlationId(size_t index = 0) const;
515
522
523 bool hasElement(const Name& name, bool excludeNullElements = false) const;
527
528 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
529 const char *name, bool excludeNullElements = false) const;
537
538 size_t numElements() const;
542
543 const Element getElement(const Name& name) const;
547
548 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
549 const char *name) const;
555
556 bool getElementAsBool(const Name& name) const;
560
561 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
567
568 char getElementAsChar(const Name& name) const;
572
573 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
579
580 Int32 getElementAsInt32(const Name& name) const;
584
585 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
586 const char *name) const;
592
593 Int64 getElementAsInt64(const Name& name) const;
597
598 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
599 const char *name) const;
605
606 Float32 getElementAsFloat32(const Name& name) const;
610
611 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
612 const char *name) const;
618
619 Float64 getElementAsFloat64(const Name& name) const;
623
624 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
625 const char *name) const;
631
632 Datetime getElementAsDatetime(const Name& name) const;
636
637 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
638 const char *name) const;
644
645 const char *getElementAsString(const Name& name) const;
649
650 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
651 const char *name) const;
657
658 Bytes getElementAsBytes(const Name& name) const;
662
663 const char *getRequestId() const;
675
676 const Element asElement() const;
681
682 std::string toJson() const;
690
691 BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
692 size_t *size) const;
702
703 Fragment fragmentType() const;
709
710 int timeReceived(TimePoint *timestamp) const;
721
722 std::ostream& print(
723 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
736
738 const blpapi_Message_t *impl() const;
742
743 blpapi_Message_t *impl();
748};
749
752
753// FREE OPERATORS
754std::ostream& operator<<(std::ostream& stream, const Message& message);
766
767namespace util {
768
772
773constexpr const char *to_string(Message::Fragment fragment);
777
778constexpr const char *to_string(Message::RecapType::Type recapType);
782
784
785} // close namespace util
786
787// ============================================================================
788// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
789// ============================================================================
790
791// -------------
792// class Message
793// -------------
794// CREATORS
795inline Message::Message(blpapi_Message_t *handle, bool clonable)
796 : d_handle(handle)
797 , d_isCloned(clonable)
798{
799 if (handle) {
800 d_elements = Element(blpapi_Message_elements(handle));
801 }
802}
803
804inline Message::Message(const Message& original)
805 : d_handle(original.d_handle)
806 , d_elements(original.d_elements)
807 , d_isCloned(true)
808{
809 if (d_handle) {
810 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
811 }
812}
813
815{
816 if (d_isCloned && d_handle) {
817 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
818 }
819}
820// MANIPULATORS
822{
823
824 if (this == &rhs) {
825 return *this;
826 }
827
828 if (d_isCloned && (d_handle == rhs.d_handle)) {
829 return *this;
830 }
831
832 if (d_isCloned && d_handle) {
833 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
834 }
835 d_handle = rhs.d_handle;
836 d_elements = rhs.d_elements;
837 d_isCloned = true;
838
839 if (d_handle) {
840 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
841 }
842
843 return *this;
844}
845
846// ACCESSORS
848{
849 return Name(blpapi_Message_messageType(d_handle));
850}
851
852inline const char *Message::topicName() const
853{
854 return blpapi_Message_topicName(d_handle);
855}
856
858{
859 return Service(blpapi_Message_service(d_handle));
860}
861
863{
864 blpapi_Name_t *name = BLPAPI_CALL(blpapi_Message_operationName)(d_handle);
865 return Name(name);
866}
867
869{
870 return blpapi_Message_numCorrelationIds(d_handle);
871}
872
873inline CorrelationId Message::correlationId(size_t index) const
874{
875 if (index >= (size_t)numCorrelationIds())
876 throw IndexOutOfRangeException("index >= numCorrelationIds");
877 return CorrelationId(blpapi_Message_correlationId(d_handle, index));
878}
879
881 const char *name, bool excludeNullElements) const
882{
883 return d_elements.hasElement(Name(name), excludeNullElements);
884}
885
887 const Name& name, bool excludeNullElements) const
888{
889 return d_elements.hasElement(name, excludeNullElements);
890}
891
892inline size_t Message::numElements() const { return d_elements.numElements(); }
893
894inline const Element Message::getElement(const Name& name) const
895{
896 return d_elements.getElement(name);
897}
898
899inline const Element Message::getElement(const char *nameString) const
900{
901 return d_elements.getElement(Name(nameString));
902}
903
904inline bool Message::getElementAsBool(const Name& name) const
905{
906 return d_elements.getElementAsBool(name);
907}
908
909inline bool Message::getElementAsBool(const char *name) const
910{
911 return d_elements.getElementAsBool(Name(name));
912}
913
914inline char Message::getElementAsChar(const Name& name) const
915{
916 return d_elements.getElementAsChar(name);
917}
918
919inline char Message::getElementAsChar(const char *name) const
920{
921 return d_elements.getElementAsChar(Name(name));
922}
923
924inline Int32 Message::getElementAsInt32(const Name& name) const
925{
926 return d_elements.getElementAsInt32(name);
927}
928
929inline Int32 Message::getElementAsInt32(const char *name) const
930{
931 return d_elements.getElementAsInt32(Name(name));
932}
933
934inline Int64 Message::getElementAsInt64(const Name& name) const
935{
936 return d_elements.getElementAsInt64(name);
937}
938
939inline Int64 Message::getElementAsInt64(const char *name) const
940{
941 return d_elements.getElementAsInt64(Name(name));
942}
943
945{
946 return d_elements.getElementAsFloat32(name);
947}
948
949inline Float32 Message::getElementAsFloat32(const char *name) const
950{
951 return d_elements.getElementAsFloat32(Name(name));
952}
953
955{
956 return d_elements.getElementAsFloat64(name);
957}
958
959inline Float64 Message::getElementAsFloat64(const char *name) const
960{
961 return d_elements.getElementAsFloat64(Name(name));
962}
963
965{
966 return d_elements.getElementAsDatetime(name);
967}
968
969inline Datetime Message::getElementAsDatetime(const char *name) const
970{
971 return d_elements.getElementAsDatetime(Name(name));
972}
973
974inline const char *Message::getElementAsString(const Name& name) const
975{
976 return d_elements.getElementAsString(name);
977}
978
979inline const char *Message::getElementAsString(const char *name) const
980{
981 return d_elements.getElementAsString(Name(name));
982}
983
984inline Bytes Message::getElementAsBytes(const Name& name) const
985{
986 return d_elements.getElementAsBytes(name);
987}
988
989inline const char *Message::getRequestId() const
990{
991 const char *requestId = 0;
992 BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
993 return requestId;
994}
995
996inline const Element Message::asElement() const { return d_elements; }
997
998inline std::string Message::toJson() const { return d_elements.toJson(); }
999
1000inline const char *Message::getPrivateData(size_t *size) const
1001{
1002 return blpapi_Message_privateData(d_handle, size);
1003}
1004
1006{
1007 return (Message::Fragment)BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(d_handle);
1008}
1009
1011{
1012 return static_cast<Message::RecapType::Type>(
1013 BLPAPI_CALL(blpapi_Message_recapType)(d_handle));
1014}
1015
1016inline int Message::timeReceived(TimePoint *timestamp) const
1017{
1018 return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
1019}
1020
1021inline std::ostream& Message::print(
1022 std::ostream& stream, int level, int spacesPerLevel) const
1023{
1024 if (BLPAPI_CALL_AVAILABLE(blpapi_Message_print)) {
1025 BLPAPI_CALL(blpapi_Message_print)
1026 (d_handle,
1028 &stream,
1029 level,
1030 spacesPerLevel);
1031 return stream;
1032 } else {
1033 return d_elements.print(stream, level, spacesPerLevel);
1034 }
1035}
1036
1037inline std::ostream& operator<<(std::ostream& stream, const Message& message)
1038{
1039 return message.print(stream, 0, -1);
1040}
1041
1043inline const blpapi_Message_t *Message::impl() const { return d_handle; }
1044
1045inline blpapi_Message_t *Message::impl() { return d_handle; }
1047
1048// --------------
1049// namespace util
1050// --------------
1051constexpr const char *util::to_string(Message::Fragment fragment)
1052{
1053 switch (fragment) {
1055 return "FRAGMENT_NONE";
1057 return "FRAGMENT_START";
1059 return "FRAGMENT_INTERMEDIATE";
1061 return "FRAGMENT_END";
1062 }
1063 // Silence warnings on some compilers
1064 return "UNDEFINED";
1065}
1066
1067// --------------
1068// namespace util
1069// --------------
1070constexpr const char *util::to_string(Message::RecapType::Type recapType)
1071{
1072 switch (recapType) {
1074 return "e_none";
1076 return "e_solicited";
1078 return "e_unsolicited";
1079 }
1080 // Silence warnings on some compilers
1081 return "UNDEFINED";
1082}
1083
1084} // close namespace blpapi
1085} // close namespace BloombergLP
1086
1087#endif // #ifdef __cplusplus
1088#endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Provide functions for dispatchtbl.
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
Provide a representation of an item in a message.
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.
Provide a time point with respect to an epoch.
Definition blpapi_types.h:395
Definition blpapi_correlationid.h:322
Definition blpapi_datetime.h:315
Definition blpapi_element.h:1098
int getElement(Element *result, const char *name) const
Definition blpapi_element.h:2565
std::string toJson() const
Definition blpapi_element.h:2995
Definition blpapi_exception.h:301
Definition blpapi_message.h:360
Service service() const
Definition blpapi_message.h:857
Fragment
Definition blpapi_message.h:370
@ FRAGMENT_END
the last fragmented message
Definition blpapi_message.h:378
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:372
@ FRAGMENT_INTERMEDIATE
intermediate fragmented messages
Definition blpapi_message.h:376
@ FRAGMENT_START
the first fragmented message
Definition blpapi_message.h:374
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_message.h:984
Message & operator=(const Message &rhs)
Definition blpapi_message.h:821
const char * getElementAsString(const Name &name) const
Definition blpapi_message.h:974
const Element getElement(const Name &name) const
Definition blpapi_message.h:894
const Element asElement() const
Definition blpapi_message.h:996
int timeReceived(TimePoint *timestamp) const
Definition blpapi_message.h:1016
const char * topicName() const
Definition blpapi_message.h:852
CorrelationId correlationId(size_t index=0) const
Definition blpapi_message.h:873
const char * getPrivateData(size_t *size) const
Definition blpapi_message.h:1000
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_message.h:1021
int numCorrelationIds() const
Definition blpapi_message.h:868
~Message()
Definition blpapi_message.h:814
Message(const Message &original)
Definition blpapi_message.h:795
Name operationName() const
Definition blpapi_message.h:862
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition blpapi_message.h:886
Name messageType() const
Definition blpapi_message.h:847
std::string toJson() const
Definition blpapi_message.h:998
Fragment fragmentType() const
Definition blpapi_message.h:1005
Int64 getElementAsInt64(const Name &name) const
Definition blpapi_message.h:934
RecapType::Type recapType() const
Definition blpapi_message.h:1010
char getElementAsChar(const Name &name) const
Definition blpapi_message.h:914
const char * getRequestId() const
Definition blpapi_message.h:989
Float32 getElementAsFloat32(const Name &name) const
Definition blpapi_message.h:944
Datetime getElementAsDatetime(const Name &name) const
Definition blpapi_message.h:964
bool getElementAsBool(const Name &name) const
Definition blpapi_message.h:904
Int32 getElementAsInt32(const Name &name) const
Definition blpapi_message.h:924
Float64 getElementAsFloat64(const Name &name) const
Definition blpapi_message.h:954
size_t numElements() const
Definition blpapi_message.h:892
Definition blpapi_name.h:228
Definition blpapi_service.h:616
constexpr const char * to_string(CorrelationId::ValueType valueType)
Definition blpapi_correlationid.h:830
blpapi_TimePoint_t TimePoint
Time point type alias.
Definition blpapi_timepoint.h:162
Definition blpapi_abstractsession.h:448
blpapi_Float64_t Float64
64-bit IEEE 754 float type alias.
Definition blpapi_types.h:559
blpapi_Float32_t Float32
32-bit IEEE 754 float type alias.
Definition blpapi_types.h:558
blpapi_Int64_t Int64
64-bit signed integer type alias.
Definition blpapi_types.h:556
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:792
blpapi_Int32_t Int32
32-bit signed integer type alias.
Definition blpapi_types.h:554
Definition blpapi_abstractsession.h:447
Definition blpapi_message.h:395
Type
Definition blpapi_message.h:396
@ e_unsolicited
generated at discretion of the service
Definition blpapi_message.h:401
@ e_solicited
generated on request by subscriber
Definition blpapi_message.h:399
@ e_none
normal data tick; not a recap
Definition blpapi_message.h:397
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108