BLPAPI C++ 3.26.7
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
151BLPAPI_EXPORT
152int blpapi_Message_numCorrelationIds(const blpapi_Message_t *message);
153
164BLPAPI_EXPORT
165blpapi_CorrelationId_t blpapi_Message_correlationId(
166 const blpapi_Message_t *message, size_t index);
167
180BLPAPI_EXPORT
181int blpapi_Message_getRequestId(
182 const blpapi_Message_t *message, const char **requestId);
183
192BLPAPI_EXPORT
193blpapi_Element_t *blpapi_Message_elements(const blpapi_Message_t *message);
194
208BLPAPI_EXPORT
209const char *blpapi_Message_privateData(
210 const blpapi_Message_t *message, size_t *size);
211
223BLPAPI_EXPORT
224int blpapi_Message_fragmentType(const blpapi_Message_t *message);
225
237BLPAPI_EXPORT
238int blpapi_Message_recapType(const blpapi_Message_t *message);
239
257BLPAPI_EXPORT
258int blpapi_Message_print(const blpapi_Message_t *message,
259 blpapi_StreamWriter_t streamWriter,
260 void *stream,
261 int indentLevel,
262 int spacesPerLevel);
263
276BLPAPI_EXPORT
277int blpapi_Message_addRef(const blpapi_Message_t *message);
278
291BLPAPI_EXPORT
292int blpapi_Message_release(const blpapi_Message_t *message);
293
308BLPAPI_EXPORT
309int blpapi_Message_timeReceived(
310 const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
311
314
315#ifdef __cplusplus
316}
317
318namespace BloombergLP {
319namespace blpapi {
326
344class Message {
345
346 blpapi_Message_t *d_handle;
347 Element d_elements;
348 bool d_isCloned;
349
350 public:
354 enum Fragment {
355
356 FRAGMENT_NONE = BLPAPI_MESSAGE_FRAGMENT_NONE,
358 FRAGMENT_START = BLPAPI_MESSAGE_FRAGMENT_START,
360 FRAGMENT_INTERMEDIATE = BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE,
362 FRAGMENT_END = BLPAPI_MESSAGE_FRAGMENT_END
364 };
365
379 struct RecapType {
380 enum Type {
381 e_none = BLPAPI_MESSAGE_RECAPTYPE_NONE,
383 e_solicited = BLPAPI_MESSAGE_RECAPTYPE_SOLICITED,
385 e_unsolicited = BLPAPI_MESSAGE_RECAPTYPE_UNSOLICITED
387 };
388 };
389
390 public:
391 // CREATORS
392
394 explicit Message(blpapi_Message_t *handle, bool clonable = false);
403
404 Message(const Message& original);
412
413 ~Message();
419
420 // MANIUPLATORS
421 Message& operator=(const Message& rhs);
429
430 // ACCESSORS
431 Name messageType() const;
435
436 BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char *topicName() const;
458
459 Service service() const;
463
464 int numCorrelationIds() const;
479
480 CorrelationId correlationId(size_t index = 0) const;
486
493
494 bool hasElement(const Name& name, bool excludeNullElements = false) const;
498
499 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
500 const char *name, bool excludeNullElements = false) const;
508
509 size_t numElements() const;
513
514 const Element getElement(const Name& name) const;
518
519 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
520 const char *name) const;
526
527 bool getElementAsBool(const Name& name) const;
531
532 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
538
539 char getElementAsChar(const Name& name) const;
543
544 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
550
551 Int32 getElementAsInt32(const Name& name) const;
555
556 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
557 const char *name) const;
563
564 Int64 getElementAsInt64(const Name& name) const;
568
569 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
570 const char *name) const;
576
577 Float32 getElementAsFloat32(const Name& name) const;
581
582 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
583 const char *name) const;
589
590 Float64 getElementAsFloat64(const Name& name) const;
594
595 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
596 const char *name) const;
602
603 Datetime getElementAsDatetime(const Name& name) const;
607
608 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
609 const char *name) const;
615
616 const char *getElementAsString(const Name& name) const;
620
621 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
622 const char *name) const;
628
629 Bytes getElementAsBytes(const Name& name) const;
633
634 const char *getRequestId() const;
646
647 const Element asElement() const;
652
653 std::string toJson() const;
661
662 BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
663 size_t *size) const;
673
674 Fragment fragmentType() const;
680
681 int timeReceived(TimePoint *timestamp) const;
692
693 std::ostream& print(
694 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
707
709 const blpapi_Message_t *impl() const;
713
714 blpapi_Message_t *impl();
719};
720
723
724// FREE OPERATORS
725std::ostream& operator<<(std::ostream& stream, const Message& message);
737
738namespace util {
739
743
744constexpr const char *to_string(Message::Fragment fragment);
748
749constexpr const char *to_string(Message::RecapType::Type recapType);
753
755
756} // close namespace util
757
758// ============================================================================
759// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
760// ============================================================================
761
762// -------------
763// class Message
764// -------------
765// CREATORS
766inline Message::Message(blpapi_Message_t *handle, bool clonable)
767 : d_handle(handle)
768 , d_isCloned(clonable)
769{
770 if (handle) {
771 d_elements = Element(blpapi_Message_elements(handle));
772 }
773}
774
775inline Message::Message(const Message& original)
776 : d_handle(original.d_handle)
777 , d_elements(original.d_elements)
778 , d_isCloned(true)
779{
780 if (d_handle) {
781 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
782 }
783}
784
786{
787 if (d_isCloned && d_handle) {
788 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
789 }
790}
791// MANIPULATORS
793{
794
795 if (this == &rhs) {
796 return *this;
797 }
798
799 if (d_isCloned && (d_handle == rhs.d_handle)) {
800 return *this;
801 }
802
803 if (d_isCloned && d_handle) {
804 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
805 }
806 d_handle = rhs.d_handle;
807 d_elements = rhs.d_elements;
808 d_isCloned = true;
809
810 if (d_handle) {
811 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
812 }
813
814 return *this;
815}
816
817// ACCESSORS
819{
820 return Name(blpapi_Message_messageType(d_handle));
821}
822
823inline const char *Message::topicName() const
824{
825 return blpapi_Message_topicName(d_handle);
826}
827
829{
830 return Service(blpapi_Message_service(d_handle));
831}
832
834{
835 return blpapi_Message_numCorrelationIds(d_handle);
836}
837
838inline CorrelationId Message::correlationId(size_t index) const
839{
840 if (index >= (size_t)numCorrelationIds())
841 throw IndexOutOfRangeException("index >= numCorrelationIds");
842 return CorrelationId(blpapi_Message_correlationId(d_handle, index));
843}
844
846 const char *name, bool excludeNullElements) const
847{
848 return d_elements.hasElement(Name(name), excludeNullElements);
849}
850
852 const Name& name, bool excludeNullElements) const
853{
854 return d_elements.hasElement(name, excludeNullElements);
855}
856
857inline size_t Message::numElements() const { return d_elements.numElements(); }
858
859inline const Element Message::getElement(const Name& name) const
860{
861 return d_elements.getElement(name);
862}
863
864inline const Element Message::getElement(const char *nameString) const
865{
866 return d_elements.getElement(Name(nameString));
867}
868
869inline bool Message::getElementAsBool(const Name& name) const
870{
871 return d_elements.getElementAsBool(name);
872}
873
874inline bool Message::getElementAsBool(const char *name) const
875{
876 return d_elements.getElementAsBool(Name(name));
877}
878
879inline char Message::getElementAsChar(const Name& name) const
880{
881 return d_elements.getElementAsChar(name);
882}
883
884inline char Message::getElementAsChar(const char *name) const
885{
886 return d_elements.getElementAsChar(Name(name));
887}
888
889inline Int32 Message::getElementAsInt32(const Name& name) const
890{
891 return d_elements.getElementAsInt32(name);
892}
893
894inline Int32 Message::getElementAsInt32(const char *name) const
895{
896 return d_elements.getElementAsInt32(Name(name));
897}
898
899inline Int64 Message::getElementAsInt64(const Name& name) const
900{
901 return d_elements.getElementAsInt64(name);
902}
903
904inline Int64 Message::getElementAsInt64(const char *name) const
905{
906 return d_elements.getElementAsInt64(Name(name));
907}
908
910{
911 return d_elements.getElementAsFloat32(name);
912}
913
914inline Float32 Message::getElementAsFloat32(const char *name) const
915{
916 return d_elements.getElementAsFloat32(Name(name));
917}
918
920{
921 return d_elements.getElementAsFloat64(name);
922}
923
924inline Float64 Message::getElementAsFloat64(const char *name) const
925{
926 return d_elements.getElementAsFloat64(Name(name));
927}
928
930{
931 return d_elements.getElementAsDatetime(name);
932}
933
934inline Datetime Message::getElementAsDatetime(const char *name) const
935{
936 return d_elements.getElementAsDatetime(Name(name));
937}
938
939inline const char *Message::getElementAsString(const Name& name) const
940{
941 return d_elements.getElementAsString(name);
942}
943
944inline const char *Message::getElementAsString(const char *name) const
945{
946 return d_elements.getElementAsString(Name(name));
947}
948
949inline Bytes Message::getElementAsBytes(const Name& name) const
950{
951 return d_elements.getElementAsBytes(name);
952}
953
954inline const char *Message::getRequestId() const
955{
956 const char *requestId = 0;
957 BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
958 return requestId;
959}
960
961inline const Element Message::asElement() const { return d_elements; }
962
963inline std::string Message::toJson() const { return d_elements.toJson(); }
964
965inline const char *Message::getPrivateData(size_t *size) const
966{
967 return blpapi_Message_privateData(d_handle, size);
968}
969
971{
972 return (Message::Fragment)BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(d_handle);
973}
974
976{
977 return static_cast<Message::RecapType::Type>(
978 BLPAPI_CALL(blpapi_Message_recapType)(d_handle));
979}
980
981inline int Message::timeReceived(TimePoint *timestamp) const
982{
983 return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
984}
985
986inline std::ostream& Message::print(
987 std::ostream& stream, int level, int spacesPerLevel) const
988{
989 if (BLPAPI_CALL_AVAILABLE(blpapi_Message_print)) {
990 BLPAPI_CALL(blpapi_Message_print)
991 (d_handle,
993 &stream,
994 level,
995 spacesPerLevel);
996 return stream;
997 } else {
998 return d_elements.print(stream, level, spacesPerLevel);
999 }
1000}
1001
1002inline std::ostream& operator<<(std::ostream& stream, const Message& message)
1003{
1004 return message.print(stream, 0, -1);
1005}
1006
1008inline const blpapi_Message_t *Message::impl() const { return d_handle; }
1009
1010inline blpapi_Message_t *Message::impl() { return d_handle; }
1012
1013// --------------
1014// namespace util
1015// --------------
1016constexpr const char *util::to_string(Message::Fragment fragment)
1017{
1018 switch (fragment) {
1020 return "FRAGMENT_NONE";
1022 return "FRAGMENT_START";
1024 return "FRAGMENT_INTERMEDIATE";
1026 return "FRAGMENT_END";
1027 }
1028 // Silence warnings on some compilers
1029 return "UNDEFINED";
1030}
1031
1032// --------------
1033// namespace util
1034// --------------
1035constexpr const char *util::to_string(Message::RecapType::Type recapType)
1036{
1037 switch (recapType) {
1039 return "e_none";
1041 return "e_solicited";
1043 return "e_unsolicited";
1044 }
1045 // Silence warnings on some compilers
1046 return "UNDEFINED";
1047}
1048
1049} // close namespace blpapi
1050} // close namespace BloombergLP
1051
1052#endif // #ifdef __cplusplus
1053#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:344
Service service() const
Definition blpapi_message.h:828
Fragment
Definition blpapi_message.h:354
@ FRAGMENT_END
the last fragmented message
Definition blpapi_message.h:362
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:356
@ FRAGMENT_INTERMEDIATE
intermediate fragmented messages
Definition blpapi_message.h:360
@ FRAGMENT_START
the first fragmented message
Definition blpapi_message.h:358
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_message.h:949
Message & operator=(const Message &rhs)
Definition blpapi_message.h:792
const char * getElementAsString(const Name &name) const
Definition blpapi_message.h:939
const Element getElement(const Name &name) const
Definition blpapi_message.h:859
const Element asElement() const
Definition blpapi_message.h:961
int timeReceived(TimePoint *timestamp) const
Definition blpapi_message.h:981
const char * topicName() const
Definition blpapi_message.h:823
CorrelationId correlationId(size_t index=0) const
Definition blpapi_message.h:838
const char * getPrivateData(size_t *size) const
Definition blpapi_message.h:965
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_message.h:986
int numCorrelationIds() const
Definition blpapi_message.h:833
~Message()
Definition blpapi_message.h:785
Message(const Message &original)
Definition blpapi_message.h:766
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition blpapi_message.h:851
Name messageType() const
Definition blpapi_message.h:818
std::string toJson() const
Definition blpapi_message.h:963
Fragment fragmentType() const
Definition blpapi_message.h:970
Int64 getElementAsInt64(const Name &name) const
Definition blpapi_message.h:899
RecapType::Type recapType() const
Definition blpapi_message.h:975
char getElementAsChar(const Name &name) const
Definition blpapi_message.h:879
const char * getRequestId() const
Definition blpapi_message.h:954
Float32 getElementAsFloat32(const Name &name) const
Definition blpapi_message.h:909
Datetime getElementAsDatetime(const Name &name) const
Definition blpapi_message.h:929
bool getElementAsBool(const Name &name) const
Definition blpapi_message.h:869
Int32 getElementAsInt32(const Name &name) const
Definition blpapi_message.h:889
Float64 getElementAsFloat64(const Name &name) const
Definition blpapi_message.h:919
size_t numElements() const
Definition blpapi_message.h:857
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:379
Type
Definition blpapi_message.h:380
@ e_unsolicited
generated at discretion of the service
Definition blpapi_message.h:385
@ e_solicited
generated on request by subscriber
Definition blpapi_message.h:383
@ e_none
normal data tick; not a recap
Definition blpapi_message.h:381
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108