BLPAPI C++  3.24.5
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>
62 #include <blpapi_correlationid.h>
63 #include <blpapi_defs.h>
64 #include <blpapi_element.h>
65 #include <blpapi_name.h>
66 #include <blpapi_service.h>
67 #include <blpapi_streamproxy.h>
68 #include <blpapi_timepoint.h>
69 
70 struct blpapi_Message;
71 typedef struct blpapi_Message blpapi_Message_t;
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
79 
81 const char *blpapi_Message_typeString(const blpapi_Message_t *message);
82 
84 const char *blpapi_Message_topicName(const blpapi_Message_t *message);
85 
88 
91 
93 blpapi_CorrelationId_t blpapi_Message_correlationId(
94  const blpapi_Message_t *message, size_t index);
95 
98  const blpapi_Message_t *message, const char **requestId);
99 
102 
104 const char *blpapi_Message_privateData(
105  const blpapi_Message_t *message, size_t *size);
106 
109 
111 int blpapi_Message_recapType(const blpapi_Message_t *message);
112 
114 int blpapi_Message_print(const blpapi_Message_t *message,
115  blpapi_StreamWriter_t streamWriter,
116  void *stream,
117  int indentLevel,
118  int spacesPerLevel);
119 
121 int blpapi_Message_addRef(const blpapi_Message_t *message);
122 
124 int blpapi_Message_release(const blpapi_Message_t *message);
125 
128  const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
129 
130 #ifdef __cplusplus
131 }
132 
140 namespace BloombergLP {
141 namespace blpapi {
142 
160 class Message {
161 
162  blpapi_Message_t *d_handle;
163  Element d_elements;
164  bool d_isCloned;
165 
166  public:
170  enum Fragment {
171 
180  };
181 
195  struct RecapType {
196  enum Type {
203  };
204  };
205 
206  public:
207  // CREATORS
208 
210  explicit Message(blpapi_Message_t *handle, bool clonable = false);
218 
220  Message(const Message& original);
229  ~Message();
236  // MANIUPLATORS
237  Message& operator=(const Message& rhs);
246  // ACCESSORS
247  Name messageType() const;
252  const char *topicName() const;
275  Service service() const;
280  int numCorrelationIds() const;
296  CorrelationId correlationId(size_t index = 0) const;
303  RecapType::Type recapType() const;
310  bool hasElement(const Name& name, bool excludeNullElements = false) const;
315  [[deprecated("Use the form that takes Name instead of const char*")]] bool
316  hasElement(const char *name, bool excludeNullElements = false) const;
323  size_t numElements() const;
328  const Element getElement(const Name& name) const;
333  [[deprecated("Use the form that takes Name instead of const "
334  "char*")]] const Element
335  getElement(const char *name) const;
342  bool getElementAsBool(const Name& name) const;
347  [[deprecated("Use the form that takes Name instead of const char*")]] bool
348  getElementAsBool(const char *name) const;
355  char getElementAsChar(const Name& name) const;
360  [[deprecated("Use the form that takes Name instead of const char*")]] char
361  getElementAsChar(const char *name) const;
368  Int32 getElementAsInt32(const Name& name) const;
373  [[deprecated("Use the form that takes Name instead of const char*")]] Int32
374  getElementAsInt32(const char *name) const;
381  Int64 getElementAsInt64(const Name& name) const;
386  [[deprecated("Use the form that takes Name instead of const char*")]] Int64
387  getElementAsInt64(const char *name) const;
394  Float32 getElementAsFloat32(const Name& name) const;
399  [[deprecated(
400  "Use the form that takes Name instead of const char*")]] Float32
401  getElementAsFloat32(const char *name) const;
408  Float64 getElementAsFloat64(const Name& name) const;
413  [[deprecated(
414  "Use the form that takes Name instead of const char*")]] Float64
415  getElementAsFloat64(const char *name) const;
422  Datetime getElementAsDatetime(const Name& name) const;
427  [[deprecated(
428  "Use the form that takes Name instead of const char*")]] Datetime
429  getElementAsDatetime(const char *name) const;
436  const char *getElementAsString(const Name& name) const;
441  [[deprecated("Use the form that takes Name instead of const "
442  "char*")]] const char *
443  getElementAsString(const char *name) const;
450  Bytes getElementAsBytes(const Name& name) const;
455  const char *getRequestId() const;
468  const Element asElement() const;
474  [[deprecated("This method is no longer supported")]] const char *
475  getPrivateData(size_t *size) const;
486  Fragment fragmentType() const;
493  int timeReceived(TimePoint *timestamp) const;
505  std::ostream& print(
506  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
520  const blpapi_Message_t *impl() const;
526  blpapi_Message_t *impl();
530 };
532 
536 // FREE OPERATORS
537 std::ostream& operator<<(std::ostream& stream, const Message& message);
550 // ============================================================================
551 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
552 // ============================================================================
553 
554 // -------------
555 // class Message
556 // -------------
557 // CREATORS
558 inline Message::Message(blpapi_Message_t *handle, bool clonable)
559  : d_handle(handle)
560  , d_isCloned(clonable)
561 {
562  if (handle) {
563  d_elements = Element(blpapi_Message_elements(handle));
564  }
565 }
566 
567 inline Message::Message(const Message& original)
568  : d_handle(original.d_handle)
569  , d_elements(original.d_elements)
570  , d_isCloned(true)
571 {
572  if (d_handle) {
573  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
574  }
575 }
576 
578 {
579  if (d_isCloned && d_handle) {
580  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
581  }
582 }
583 // MANIPULATORS
584 inline Message& Message::operator=(const Message& rhs)
585 {
586 
587  if (this == &rhs) {
588  return *this;
589  }
590 
591  if (d_isCloned && (d_handle == rhs.d_handle)) {
592  return *this;
593  }
594 
595  if (d_isCloned && d_handle) {
596  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
597  }
598  d_handle = rhs.d_handle;
599  d_elements = rhs.d_elements;
600  d_isCloned = true;
601 
602  if (d_handle) {
603  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
604  }
605 
606  return *this;
607 }
608 
609 // ACCESSORS
611 {
612  return Name(blpapi_Message_messageType(d_handle));
613 }
614 
615 inline const char *Message::topicName() const
616 {
617  return blpapi_Message_topicName(d_handle);
618 }
619 
620 inline Service Message::service() const
621 {
622  return Service(blpapi_Message_service(d_handle));
623 }
624 
625 inline int Message::numCorrelationIds() const
626 {
627  return blpapi_Message_numCorrelationIds(d_handle);
628 }
629 
630 inline CorrelationId Message::correlationId(size_t index) const
631 {
632  if (index >= (size_t)numCorrelationIds())
633  throw IndexOutOfRangeException("index >= numCorrelationIds");
634  return CorrelationId(blpapi_Message_correlationId(d_handle, index));
635 }
636 
638  const char *name, bool excludeNullElements) const
639 {
640  return d_elements.hasElement(Name(name), excludeNullElements);
641 }
642 
644  const Name& name, bool excludeNullElements) const
645 {
646  return d_elements.hasElement(name, excludeNullElements);
647 }
648 
649 inline size_t Message::numElements() const { return d_elements.numElements(); }
650 
651 inline const Element Message::getElement(const Name& name) const
652 {
653  return d_elements.getElement(name);
654 }
655 
656 inline const Element Message::getElement(const char *nameString) const
657 {
658  return d_elements.getElement(Name(nameString));
659 }
660 
661 inline bool Message::getElementAsBool(const Name& name) const
662 {
663  return d_elements.getElementAsBool(name);
664 }
665 
666 inline bool Message::getElementAsBool(const char *name) const
667 {
668  return d_elements.getElementAsBool(Name(name));
669 }
670 
671 inline char Message::getElementAsChar(const Name& name) const
672 {
673  return d_elements.getElementAsChar(name);
674 }
675 
676 inline char Message::getElementAsChar(const char *name) const
677 {
678  return d_elements.getElementAsChar(Name(name));
679 }
680 
681 inline Int32 Message::getElementAsInt32(const Name& name) const
682 {
683  return d_elements.getElementAsInt32(name);
684 }
685 
686 inline Int32 Message::getElementAsInt32(const char *name) const
687 {
688  return d_elements.getElementAsInt32(Name(name));
689 }
690 
691 inline Int64 Message::getElementAsInt64(const Name& name) const
692 {
693  return d_elements.getElementAsInt64(name);
694 }
695 
696 inline Int64 Message::getElementAsInt64(const char *name) const
697 {
698  return d_elements.getElementAsInt64(Name(name));
699 }
700 
701 inline Float32 Message::getElementAsFloat32(const Name& name) const
702 {
703  return d_elements.getElementAsFloat32(name);
704 }
705 
706 inline Float32 Message::getElementAsFloat32(const char *name) const
707 {
708  return d_elements.getElementAsFloat32(Name(name));
709 }
710 
711 inline Float64 Message::getElementAsFloat64(const Name& name) const
712 {
713  return d_elements.getElementAsFloat64(name);
714 }
715 
716 inline Float64 Message::getElementAsFloat64(const char *name) const
717 {
718  return d_elements.getElementAsFloat64(Name(name));
719 }
720 
721 inline Datetime Message::getElementAsDatetime(const Name& name) const
722 {
723  return d_elements.getElementAsDatetime(name);
724 }
725 
726 inline Datetime Message::getElementAsDatetime(const char *name) const
727 {
728  return d_elements.getElementAsDatetime(Name(name));
729 }
730 
731 inline const char *Message::getElementAsString(const Name& name) const
732 {
733  return d_elements.getElementAsString(name);
734 }
735 
736 inline const char *Message::getElementAsString(const char *name) const
737 {
738  return d_elements.getElementAsString(Name(name));
739 }
740 
741 inline Bytes Message::getElementAsBytes(const Name& name) const
742 {
743  return d_elements.getElementAsBytes(name);
744 }
745 
746 inline const char *Message::getRequestId() const
747 {
748  const char *requestId = 0;
749  BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
750  return requestId;
751 }
752 
753 inline const Element Message::asElement() const { return d_elements; }
754 
755 inline const char *Message::getPrivateData(size_t *size) const
756 {
757  return blpapi_Message_privateData(d_handle, size);
758 }
759 
761 {
763 }
764 
766 {
767  return static_cast<Message::RecapType::Type>(
769 }
770 
771 inline int Message::timeReceived(TimePoint *timestamp) const
772 {
773  return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
774 }
775 
776 inline std::ostream& Message::print(
777  std::ostream& stream, int level, int spacesPerLevel) const
778 {
781  (d_handle,
783  &stream,
784  level,
785  spacesPerLevel);
786  return stream;
787  } else {
788  return d_elements.print(stream, level, spacesPerLevel);
789  }
790 }
791 
792 inline std::ostream& operator<<(std::ostream& stream, const Message& message)
793 {
794  return message.print(stream, 0, -1);
795 }
796 
797 inline const blpapi_Message_t *Message::impl() const { return d_handle; }
798 
799 inline blpapi_Message_t *Message::impl() { return d_handle; }
800 
801 } // close namespace blpapi
802 } // close namespace BloombergLP
803 
804 #endif // #ifdef __cplusplus
805 #endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Int64 getElementAsInt64(const Name &name) const
Definition: blpapi_message.h:691
int blpapi_Message_recapType(const blpapi_Message_t *message)
the first fragmented message
Definition: blpapi_message.h:174
Definition: blpapi_timepoint.h:104
Definition: blpapi_message.h:160
#define BLPAPI_MESSAGE_FRAGMENT_END
Definition: blpapi_defs.h:147
message is not fragmented
Definition: blpapi_message.h:172
Float32 getElementAsFloat32(const Name &name) const
Definition: blpapi_message.h:701
bool getElementAsBool(const char *name) const
Definition: blpapi_element.h:2242
int timeReceived(TimePoint *timestamp) const
Definition: blpapi_message.h:771
#define BLPAPI_MESSAGE_RECAPTYPE_SOLICITED
Definition: blpapi_defs.h:150
const char * blpapi_Message_topicName(const blpapi_Message_t *message)
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
Service service() const
Definition: blpapi_message.h:620
Common definitions used by the library.
Definition: blpapi_exception.h:271
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
const char * blpapi_Message_privateData(const blpapi_Message_t *message, size_t *size)
Type
Definition: blpapi_message.h:196
#define BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE
Definition: blpapi_defs.h:146
Float32 getElementAsFloat32(const char *name) const
Definition: blpapi_element.h:2282
Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2292
Definition: blpapi_abstractsession.h:220
Definition: blpapi_name.h:150
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
blpapi_Float64_t Float64
Definition: blpapi_types.h:474
Definition: blpapi_service.h:304
int blpapi_Message_fragmentType(const blpapi_Message_t *message)
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_message.h:776
#define BLPAPI_CALL_MESSAGE_TIMERECEIVED(a1, a2)
Definition: blpapi_call.h:453
int blpapi_Message_numCorrelationIds(const blpapi_Message_t *message)
CorrelationId correlationId(size_t index=0) const
Definition: blpapi_message.h:630
Message & operator=(const Message &rhs)
Definition: blpapi_message.h:584
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
#define BLPAPI_MESSAGE_RECAPTYPE_NONE
Definition: blpapi_defs.h:149
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:53
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
A service which provides access to API data (provide or consume).
Provide a time point with respect to an epoch.
Provide a key to identify individual subscriptions or requests.
struct blpapi_Message blpapi_Message_t
Definition: blpapi_message.h:71
Datetime getElementAsDatetime(const char *name) const
Definition: blpapi_element.h:2302
Definition: blpapi_element.h:464
bool getElementAsBool(const Name &name) const
Definition: blpapi_message.h:661
Int32 getElementAsInt32(const char *name) const
Definition: blpapi_element.h:2262
Fragment fragmentType() const
Definition: blpapi_message.h:760
int blpapi_Message_print(const blpapi_Message_t *message, blpapi_StreamWriter_t streamWriter, void *stream, int indentLevel, int spacesPerLevel)
#define BLPAPI_CALL_MESSAGE_FRAGMENTTYPE(a1)
Definition: blpapi_call.h:370
const char * getElementAsString(const Name &name) const
Definition: blpapi_message.h:731
Int32 getElementAsInt32(const Name &name) const
Definition: blpapi_message.h:681
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition: blpapi_correlationid.h:592
Definition: blpapi_correlationid.h:201
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
const char * blpapi_Message_typeString(const blpapi_Message_t *message)
int blpapi_Message_timeReceived(const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived)
blpapi_Name_t * blpapi_Message_messageType(const blpapi_Message_t *message)
blpapi_CorrelationId_t blpapi_Message_correlationId(const blpapi_Message_t *message, size_t index)
int getElement(Element *result, const char *name) const
Definition: blpapi_element.h:1922
Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2272
const char * getPrivateData(size_t *size) const
Definition: blpapi_message.h:755
size_t numElements() const
Definition: blpapi_element.h:1997
A signature for callback on print and default C++ implementation.
Fragment
Definition: blpapi_message.h:170
int numCorrelationIds() const
Definition: blpapi_message.h:625
const char * topicName() const
Definition: blpapi_message.h:615
const char * getRequestId() const
Definition: blpapi_message.h:746
char getElementAsChar(const char *name) const
Definition: blpapi_element.h:2252
RecapType::Type recapType() const
Definition: blpapi_message.h:765
const Element getElement(const Name &name) const
Definition: blpapi_message.h:651
blpapi_Element_t * blpapi_Message_elements(const blpapi_Message_t *message)
Message(const Message &original)
Definition: blpapi_message.h:558
Float64 getElementAsFloat64(const Name &name) const
Definition: blpapi_message.h:711
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition: blpapi_message.h:643
bool hasElement(const char *name, bool excludeNullElements=false) const
Definition: blpapi_element.h:2013
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2322
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2339
Definition: blpapi_message.h:195
static int writeToStream(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:93
blpapi_Service_t * blpapi_Message_service(const blpapi_Message_t *message)
Name messageType() const
Definition: blpapi_message.h:610
normal data tick; not a recap
Definition: blpapi_message.h:197
Datetime getElementAsDatetime(const Name &name) const
Definition: blpapi_message.h:721
const Element asElement() const
Definition: blpapi_message.h:753
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
struct blpapi_Service blpapi_Service_t
Definition: blpapi_types.h:166
#define BLPAPI_CALL_AVAILABLE(FUNCNAME)
Definition: blpapi_call.h:352
Definition: blpapi_datetime.h:245
intermediate fragmented messages
Definition: blpapi_message.h:176
Provide functions for dispatchtbl.
generated on request by subscriber
Definition: blpapi_message.h:199
#define BLPAPI_MESSAGE_RECAPTYPE_UNSOLICITED
Definition: blpapi_defs.h:151
#define BLPAPI_CALL_MESSAGE_ADDREF(a1)
Definition: blpapi_call.h:360
#define BLPAPI_MESSAGE_FRAGMENT_START
Definition: blpapi_defs.h:145
#define BLPAPI_MESSAGE_FRAGMENT_NONE
Definition: blpapi_defs.h:144
char getElementAsChar(const Name &name) const
Definition: blpapi_message.h:671
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_message.h:741
the last fragmented message
Definition: blpapi_message.h:178
Provide a representation of an item in a message.
const char * getElementAsString(const char *name) const
Definition: blpapi_element.h:2312
int blpapi_Message_release(const blpapi_Message_t *message)
Provide a representation of strings for use as container keys.
Definition: blpapi_types.h:312
size_t numElements() const
Definition: blpapi_message.h:649
~Message()
Definition: blpapi_message.h:577
generated at discretion of the service
Definition: blpapi_message.h:201
#define BLPAPI_CALL_MESSAGE_RELEASE(a1)
Definition: blpapi_call.h:361
int blpapi_Message_addRef(const blpapi_Message_t *message)
int blpapi_Message_getRequestId(const blpapi_Message_t *message, const char **requestId)