BLPAPI C++ 3.26.6
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
738// ============================================================================
739// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
740// ============================================================================
741
742// -------------
743// class Message
744// -------------
745// CREATORS
746inline Message::Message(blpapi_Message_t *handle, bool clonable)
747 : d_handle(handle)
748 , d_isCloned(clonable)
749{
750 if (handle) {
751 d_elements = Element(blpapi_Message_elements(handle));
752 }
753}
754
755inline Message::Message(const Message& original)
756 : d_handle(original.d_handle)
757 , d_elements(original.d_elements)
758 , d_isCloned(true)
759{
760 if (d_handle) {
761 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
762 }
763}
764
766{
767 if (d_isCloned && d_handle) {
768 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
769 }
770}
771// MANIPULATORS
773{
774
775 if (this == &rhs) {
776 return *this;
777 }
778
779 if (d_isCloned && (d_handle == rhs.d_handle)) {
780 return *this;
781 }
782
783 if (d_isCloned && d_handle) {
784 BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
785 }
786 d_handle = rhs.d_handle;
787 d_elements = rhs.d_elements;
788 d_isCloned = true;
789
790 if (d_handle) {
791 BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
792 }
793
794 return *this;
795}
796
797// ACCESSORS
799{
800 return Name(blpapi_Message_messageType(d_handle));
801}
802
803inline const char *Message::topicName() const
804{
805 return blpapi_Message_topicName(d_handle);
806}
807
809{
810 return Service(blpapi_Message_service(d_handle));
811}
812
814{
815 return blpapi_Message_numCorrelationIds(d_handle);
816}
817
818inline CorrelationId Message::correlationId(size_t index) const
819{
820 if (index >= (size_t)numCorrelationIds())
821 throw IndexOutOfRangeException("index >= numCorrelationIds");
822 return CorrelationId(blpapi_Message_correlationId(d_handle, index));
823}
824
826 const char *name, bool excludeNullElements) const
827{
828 return d_elements.hasElement(Name(name), excludeNullElements);
829}
830
832 const Name& name, bool excludeNullElements) const
833{
834 return d_elements.hasElement(name, excludeNullElements);
835}
836
837inline size_t Message::numElements() const { return d_elements.numElements(); }
838
839inline const Element Message::getElement(const Name& name) const
840{
841 return d_elements.getElement(name);
842}
843
844inline const Element Message::getElement(const char *nameString) const
845{
846 return d_elements.getElement(Name(nameString));
847}
848
849inline bool Message::getElementAsBool(const Name& name) const
850{
851 return d_elements.getElementAsBool(name);
852}
853
854inline bool Message::getElementAsBool(const char *name) const
855{
856 return d_elements.getElementAsBool(Name(name));
857}
858
859inline char Message::getElementAsChar(const Name& name) const
860{
861 return d_elements.getElementAsChar(name);
862}
863
864inline char Message::getElementAsChar(const char *name) const
865{
866 return d_elements.getElementAsChar(Name(name));
867}
868
869inline Int32 Message::getElementAsInt32(const Name& name) const
870{
871 return d_elements.getElementAsInt32(name);
872}
873
874inline Int32 Message::getElementAsInt32(const char *name) const
875{
876 return d_elements.getElementAsInt32(Name(name));
877}
878
879inline Int64 Message::getElementAsInt64(const Name& name) const
880{
881 return d_elements.getElementAsInt64(name);
882}
883
884inline Int64 Message::getElementAsInt64(const char *name) const
885{
886 return d_elements.getElementAsInt64(Name(name));
887}
888
890{
891 return d_elements.getElementAsFloat32(name);
892}
893
894inline Float32 Message::getElementAsFloat32(const char *name) const
895{
896 return d_elements.getElementAsFloat32(Name(name));
897}
898
900{
901 return d_elements.getElementAsFloat64(name);
902}
903
904inline Float64 Message::getElementAsFloat64(const char *name) const
905{
906 return d_elements.getElementAsFloat64(Name(name));
907}
908
910{
911 return d_elements.getElementAsDatetime(name);
912}
913
914inline Datetime Message::getElementAsDatetime(const char *name) const
915{
916 return d_elements.getElementAsDatetime(Name(name));
917}
918
919inline const char *Message::getElementAsString(const Name& name) const
920{
921 return d_elements.getElementAsString(name);
922}
923
924inline const char *Message::getElementAsString(const char *name) const
925{
926 return d_elements.getElementAsString(Name(name));
927}
928
929inline Bytes Message::getElementAsBytes(const Name& name) const
930{
931 return d_elements.getElementAsBytes(name);
932}
933
934inline const char *Message::getRequestId() const
935{
936 const char *requestId = 0;
937 BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
938 return requestId;
939}
940
941inline const Element Message::asElement() const { return d_elements; }
942
943inline std::string Message::toJson() const { return d_elements.toJson(); }
944
945inline const char *Message::getPrivateData(size_t *size) const
946{
947 return blpapi_Message_privateData(d_handle, size);
948}
949
951{
952 return (Message::Fragment)BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(d_handle);
953}
954
956{
957 return static_cast<Message::RecapType::Type>(
958 BLPAPI_CALL(blpapi_Message_recapType)(d_handle));
959}
960
961inline int Message::timeReceived(TimePoint *timestamp) const
962{
963 return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
964}
965
966inline std::ostream& Message::print(
967 std::ostream& stream, int level, int spacesPerLevel) const
968{
969 if (BLPAPI_CALL_AVAILABLE(blpapi_Message_print)) {
970 BLPAPI_CALL(blpapi_Message_print)
971 (d_handle,
973 &stream,
974 level,
975 spacesPerLevel);
976 return stream;
977 } else {
978 return d_elements.print(stream, level, spacesPerLevel);
979 }
980}
981
982inline std::ostream& operator<<(std::ostream& stream, const Message& message)
983{
984 return message.print(stream, 0, -1);
985}
986
988inline const blpapi_Message_t *Message::impl() const { return d_handle; }
989
990inline blpapi_Message_t *Message::impl() { return d_handle; }
992
993} // close namespace blpapi
994} // close namespace BloombergLP
995
996#endif // #ifdef __cplusplus
997#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:306
Definition blpapi_datetime.h:312
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:808
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:929
Message & operator=(const Message &rhs)
Definition blpapi_message.h:772
const char * getElementAsString(const Name &name) const
Definition blpapi_message.h:919
const Element getElement(const Name &name) const
Definition blpapi_message.h:839
const Element asElement() const
Definition blpapi_message.h:941
int timeReceived(TimePoint *timestamp) const
Definition blpapi_message.h:961
const char * topicName() const
Definition blpapi_message.h:803
CorrelationId correlationId(size_t index=0) const
Definition blpapi_message.h:818
const char * getPrivateData(size_t *size) const
Definition blpapi_message.h:945
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_message.h:966
int numCorrelationIds() const
Definition blpapi_message.h:813
~Message()
Definition blpapi_message.h:765
Message(const Message &original)
Definition blpapi_message.h:746
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition blpapi_message.h:831
Name messageType() const
Definition blpapi_message.h:798
std::string toJson() const
Definition blpapi_message.h:943
Fragment fragmentType() const
Definition blpapi_message.h:950
Int64 getElementAsInt64(const Name &name) const
Definition blpapi_message.h:879
RecapType::Type recapType() const
Definition blpapi_message.h:955
char getElementAsChar(const Name &name) const
Definition blpapi_message.h:859
const char * getRequestId() const
Definition blpapi_message.h:934
Float32 getElementAsFloat32(const Name &name) const
Definition blpapi_message.h:889
Datetime getElementAsDatetime(const Name &name) const
Definition blpapi_message.h:909
bool getElementAsBool(const Name &name) const
Definition blpapi_message.h:849
Int32 getElementAsInt32(const Name &name) const
Definition blpapi_message.h:869
Float64 getElementAsFloat64(const Name &name) const
Definition blpapi_message.h:899
size_t numElements() const
Definition blpapi_message.h:837
Definition blpapi_name.h:228
Definition blpapi_service.h:619
blpapi_TimePoint_t TimePoint
Time point type alias.
Definition blpapi_timepoint.h:162
Definition blpapi_abstractsession.h:452
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:761
blpapi_Int32_t Int32
32-bit signed integer type alias.
Definition blpapi_types.h:554
Definition blpapi_abstractsession.h:451
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