BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_MESSAGE
37#define INCLUDED_BLPAPI_MESSAGE
38
68
69#include <blpapi_call.h>
71#include <blpapi_defs.h>
72#include <blpapi_deprecate.h>
73#include <blpapi_element.h>
74#include <blpapi_name.h>
75#include <blpapi_service.h>
76#include <blpapi_streamproxy.h>
77#include <blpapi_timepoint.h>
78
79struct blpapi_Message;
80#ifdef __cplusplus
81extern "C" {
82#endif
83
85typedef struct blpapi_Message blpapi_Message_t;
86
90
91BLPAPI_EXPORT
92blpapi_Name_t *blpapi_Message_messageType(const blpapi_Message_t *message);
93
94BLPAPI_EXPORT
95const char *blpapi_Message_typeString(const blpapi_Message_t *message);
96
97BLPAPI_EXPORT
98const char *blpapi_Message_topicName(const blpapi_Message_t *message);
99
100BLPAPI_EXPORT
101blpapi_Service_t *blpapi_Message_service(const blpapi_Message_t *message);
102
103BLPAPI_EXPORT
104int blpapi_Message_numCorrelationIds(const blpapi_Message_t *message);
105
106BLPAPI_EXPORT
107blpapi_CorrelationId_t blpapi_Message_correlationId(
108 const blpapi_Message_t *message, size_t index);
109
110BLPAPI_EXPORT
111int blpapi_Message_getRequestId(
112 const blpapi_Message_t *message, const char **requestId);
113
114BLPAPI_EXPORT
115blpapi_Element_t *blpapi_Message_elements(const blpapi_Message_t *message);
116
117BLPAPI_EXPORT
118const char *blpapi_Message_privateData(
119 const blpapi_Message_t *message, size_t *size);
120
121BLPAPI_EXPORT
122int blpapi_Message_fragmentType(const blpapi_Message_t *message);
123
124BLPAPI_EXPORT
125int blpapi_Message_recapType(const blpapi_Message_t *message);
126
127BLPAPI_EXPORT
128int blpapi_Message_print(const blpapi_Message_t *message,
129 blpapi_StreamWriter_t streamWriter,
130 void *stream,
131 int indentLevel,
132 int spacesPerLevel);
133
134BLPAPI_EXPORT
135int blpapi_Message_addRef(const blpapi_Message_t *message);
136
137BLPAPI_EXPORT
138int blpapi_Message_release(const blpapi_Message_t *message);
139
140BLPAPI_EXPORT
141int blpapi_Message_timeReceived(
142 const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
143
146
147#ifdef __cplusplus
148}
149
156
157namespace BloombergLP {
158namespace blpapi {
159
177class Message {
178
179 blpapi_Message_t *d_handle;
180 Element d_elements;
181 bool d_isCloned;
182
183 public:
187 enum Fragment {
188
189 FRAGMENT_NONE = BLPAPI_MESSAGE_FRAGMENT_NONE,
191 FRAGMENT_START = BLPAPI_MESSAGE_FRAGMENT_START,
193 FRAGMENT_INTERMEDIATE = BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE,
195 FRAGMENT_END = BLPAPI_MESSAGE_FRAGMENT_END
197 };
198
212 struct RecapType {
213 enum Type {
214 e_none = BLPAPI_MESSAGE_RECAPTYPE_NONE,
216 e_solicited = BLPAPI_MESSAGE_RECAPTYPE_SOLICITED,
218 e_unsolicited = BLPAPI_MESSAGE_RECAPTYPE_UNSOLICITED
220 };
221 };
222
223 public:
224 // CREATORS
225
227 explicit Message(blpapi_Message_t *handle, bool clonable = false);
236
237 Message(const Message& original);
245
246 ~Message();
252
253 // MANIUPLATORS
254 Message& operator=(const Message& rhs);
262
263 // ACCESSORS
264 Name messageType() const;
268
269 BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char *topicName() const;
291
292 Service service() const;
296
297 int numCorrelationIds() const;
312
313 CorrelationId correlationId(size_t index = 0) const;
319
326
327 bool hasElement(const Name& name, bool excludeNullElements = false) const;
331
332 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
333 const char *name, bool excludeNullElements = false) const;
341
342 size_t numElements() const;
346
347 const Element getElement(const Name& name) const;
351
352 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
353 const char *name) const;
359
360 bool getElementAsBool(const Name& name) const;
364
365 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
371
372 char getElementAsChar(const Name& name) const;
376
377 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
383
384 Int32 getElementAsInt32(const Name& name) const;
388
389 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
390 const char *name) const;
396
397 Int64 getElementAsInt64(const Name& name) const;
401
402 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
403 const char *name) const;
409
410 Float32 getElementAsFloat32(const Name& name) const;
414
415 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
416 const char *name) const;
422
423 Float64 getElementAsFloat64(const Name& name) const;
427
428 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
429 const char *name) const;
435
436 Datetime getElementAsDatetime(const Name& name) const;
440
441 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
442 const char *name) const;
448
449 const char *getElementAsString(const Name& name) const;
453
454 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
455 const char *name) const;
461
462 Bytes getElementAsBytes(const Name& name) const;
466
467 const char *getRequestId() const;
479
480 const Element asElement() const;
485
486 std::string toJson() const;
494
495 BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
496 size_t *size) const;
506
507 Fragment fragmentType() const;
513
514 int timeReceived(TimePoint *timestamp) const;
525
526 std::ostream& print(
527 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
540
542 const blpapi_Message_t *impl() const;
546
547 blpapi_Message_t *impl();
552};
553
556
557// FREE OPERATORS
558std::ostream& operator<<(std::ostream& stream, const Message& message);
570
571// ============================================================================
572// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
573// ============================================================================
574
575// -------------
576// class Message
577// -------------
578// CREATORS
579inline Message::Message(blpapi_Message_t *handle, bool clonable)
580 : d_handle(handle)
581 , d_isCloned(clonable)
582{
583 if (handle) {
584 d_elements = Element(blpapi_Message_elements(handle));
585 }
586}
587
588inline Message::Message(const Message& original)
589 : d_handle(original.d_handle)
590 , d_elements(original.d_elements)
591 , d_isCloned(true)
592{
593 if (d_handle) {
595 }
596}
597
599{
600 if (d_isCloned && d_handle) {
602 }
603}
604// MANIPULATORS
606{
607
608 if (this == &rhs) {
609 return *this;
610 }
611
612 if (d_isCloned && (d_handle == rhs.d_handle)) {
613 return *this;
614 }
615
616 if (d_isCloned && d_handle) {
618 }
619 d_handle = rhs.d_handle;
620 d_elements = rhs.d_elements;
621 d_isCloned = true;
622
623 if (d_handle) {
625 }
626
627 return *this;
628}
629
630// ACCESSORS
632{
633 return Name(blpapi_Message_messageType(d_handle));
634}
635
636inline const char *Message::topicName() const
637{
638 return blpapi_Message_topicName(d_handle);
639}
640
642{
643 return Service(blpapi_Message_service(d_handle));
644}
645
647{
648 return blpapi_Message_numCorrelationIds(d_handle);
649}
650
651inline CorrelationId Message::correlationId(size_t index) const
652{
653 if (index >= (size_t)numCorrelationIds())
654 throw IndexOutOfRangeException("index >= numCorrelationIds");
655 return CorrelationId(blpapi_Message_correlationId(d_handle, index));
656}
657
659 const char *name, bool excludeNullElements) const
660{
661 return d_elements.hasElement(Name(name), excludeNullElements);
662}
663
665 const Name& name, bool excludeNullElements) const
666{
667 return d_elements.hasElement(name, excludeNullElements);
668}
669
670inline size_t Message::numElements() const { return d_elements.numElements(); }
671
672inline const Element Message::getElement(const Name& name) const
673{
674 return d_elements.getElement(name);
675}
676
677inline const Element Message::getElement(const char *nameString) const
678{
679 return d_elements.getElement(Name(nameString));
680}
681
682inline bool Message::getElementAsBool(const Name& name) const
683{
684 return d_elements.getElementAsBool(name);
685}
686
687inline bool Message::getElementAsBool(const char *name) const
688{
689 return d_elements.getElementAsBool(Name(name));
690}
691
692inline char Message::getElementAsChar(const Name& name) const
693{
694 return d_elements.getElementAsChar(name);
695}
696
697inline char Message::getElementAsChar(const char *name) const
698{
699 return d_elements.getElementAsChar(Name(name));
700}
701
702inline Int32 Message::getElementAsInt32(const Name& name) const
703{
704 return d_elements.getElementAsInt32(name);
705}
706
707inline Int32 Message::getElementAsInt32(const char *name) const
708{
709 return d_elements.getElementAsInt32(Name(name));
710}
711
712inline Int64 Message::getElementAsInt64(const Name& name) const
713{
714 return d_elements.getElementAsInt64(name);
715}
716
717inline Int64 Message::getElementAsInt64(const char *name) const
718{
719 return d_elements.getElementAsInt64(Name(name));
720}
721
723{
724 return d_elements.getElementAsFloat32(name);
725}
726
727inline Float32 Message::getElementAsFloat32(const char *name) const
728{
729 return d_elements.getElementAsFloat32(Name(name));
730}
731
733{
734 return d_elements.getElementAsFloat64(name);
735}
736
737inline Float64 Message::getElementAsFloat64(const char *name) const
738{
739 return d_elements.getElementAsFloat64(Name(name));
740}
741
743{
744 return d_elements.getElementAsDatetime(name);
745}
746
747inline Datetime Message::getElementAsDatetime(const char *name) const
748{
749 return d_elements.getElementAsDatetime(Name(name));
750}
751
752inline const char *Message::getElementAsString(const Name& name) const
753{
754 return d_elements.getElementAsString(name);
755}
756
757inline const char *Message::getElementAsString(const char *name) const
758{
759 return d_elements.getElementAsString(Name(name));
760}
761
762inline Bytes Message::getElementAsBytes(const Name& name) const
763{
764 return d_elements.getElementAsBytes(name);
765}
766
767inline const char *Message::getRequestId() const
768{
769 const char *requestId = 0;
770 BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
771 return requestId;
772}
773
774inline const Element Message::asElement() const { return d_elements; }
775
776inline std::string Message::toJson() const { return d_elements.toJson(); }
777
778inline const char *Message::getPrivateData(size_t *size) const
779{
780 return blpapi_Message_privateData(d_handle, size);
781}
782
787
789{
790 return static_cast<Message::RecapType::Type>(
791 BLPAPI_CALL(blpapi_Message_recapType)(d_handle));
792}
793
794inline int Message::timeReceived(TimePoint *timestamp) const
795{
796 return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
797}
798
799inline std::ostream& Message::print(
800 std::ostream& stream, int level, int spacesPerLevel) const
801{
802 if (BLPAPI_CALL_AVAILABLE(blpapi_Message_print)) {
803 BLPAPI_CALL(blpapi_Message_print)
804 (d_handle,
806 &stream,
807 level,
808 spacesPerLevel);
809 return stream;
810 } else {
811 return d_elements.print(stream, level, spacesPerLevel);
812 }
813}
814
815inline std::ostream& operator<<(std::ostream& stream, const Message& message)
816{
817 return message.print(stream, 0, -1);
818}
819
820inline const blpapi_Message_t *Message::impl() const { return d_handle; }
821
822inline blpapi_Message_t *Message::impl() { return d_handle; }
823
824} // close namespace blpapi
825} // close namespace BloombergLP
826
827#endif // #ifdef __cplusplus
828#endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Provide functions for dispatchtbl.
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition blpapi_call.h:368
#define BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(a1)
Definition blpapi_call.h:378
#define BLPAPI_CALL_AVAILABLE(FUNCNAME)
Definition blpapi_call.h:360
#define BLPAPI_CALL_MESSAGE_TIMERECEIVED(a1, a2)
Definition blpapi_call.h:461
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
#define BLPAPI_CALL_MESSAGE_RELEASE(a1)
Definition blpapi_call.h:369
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:323
Definition blpapi_correlationid.h:225
Definition blpapi_datetime.h:273
Definition blpapi_element.h:1167
int getElement(Element *result, const char *name) const
Definition blpapi_element.h:2642
std::string toJson() const
Definition blpapi_element.h:3070
Definition blpapi_exception.h:286
Definition blpapi_message.h:177
Service service() const
Definition blpapi_message.h:641
Fragment
Definition blpapi_message.h:187
@ FRAGMENT_END
the last fragmented message
Definition blpapi_message.h:195
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:189
@ FRAGMENT_INTERMEDIATE
intermediate fragmented messages
Definition blpapi_message.h:193
@ FRAGMENT_START
the first fragmented message
Definition blpapi_message.h:191
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_message.h:762
Message & operator=(const Message &rhs)
Definition blpapi_message.h:605
const char * getElementAsString(const Name &name) const
Definition blpapi_message.h:752
const Element getElement(const Name &name) const
Definition blpapi_message.h:672
const Element asElement() const
Definition blpapi_message.h:774
int timeReceived(TimePoint *timestamp) const
Definition blpapi_message.h:794
const char * topicName() const
Definition blpapi_message.h:636
CorrelationId correlationId(size_t index=0) const
Definition blpapi_message.h:651
const char * getPrivateData(size_t *size) const
Definition blpapi_message.h:778
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_message.h:799
int numCorrelationIds() const
Definition blpapi_message.h:646
~Message()
Definition blpapi_message.h:598
Message(const Message &original)
Definition blpapi_message.h:579
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition blpapi_message.h:664
Name messageType() const
Definition blpapi_message.h:631
std::string toJson() const
Definition blpapi_message.h:776
Fragment fragmentType() const
Definition blpapi_message.h:783
Int64 getElementAsInt64(const Name &name) const
Definition blpapi_message.h:712
RecapType::Type recapType() const
Definition blpapi_message.h:788
char getElementAsChar(const Name &name) const
Definition blpapi_message.h:692
const char * getRequestId() const
Definition blpapi_message.h:767
Float32 getElementAsFloat32(const Name &name) const
Definition blpapi_message.h:722
Datetime getElementAsDatetime(const Name &name) const
Definition blpapi_message.h:742
bool getElementAsBool(const Name &name) const
Definition blpapi_message.h:682
Int32 getElementAsInt32(const Name &name) const
Definition blpapi_message.h:702
Float64 getElementAsFloat64(const Name &name) const
Definition blpapi_message.h:732
size_t numElements() const
Definition blpapi_message.h:670
Definition blpapi_name.h:242
Definition blpapi_service.h:320
Definition blpapi_abstractsession.h:212
blpapi_TimePoint_t TimePoint
Definition blpapi_timepoint.h:147
blpapi_Float64_t Float64
Definition blpapi_types.h:485
blpapi_Float32_t Float32
Definition blpapi_types.h:484
blpapi_Int64_t Int64
Definition blpapi_types.h:482
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:680
blpapi_Int32_t Int32
Definition blpapi_types.h:480
Definition blpapi_abstractsession.h:211
Definition blpapi_message.h:212
Type
Definition blpapi_message.h:213
@ e_unsolicited
generated at discretion of the service
Definition blpapi_message.h:218
@ e_solicited
generated on request by subscriber
Definition blpapi_message.h:216
@ e_none
normal data tick; not a recap
Definition blpapi_message.h:214
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:109