BLPAPI C++  3.24.9
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_deprecate.h>
65 #include <blpapi_element.h>
66 #include <blpapi_name.h>
67 #include <blpapi_service.h>
68 #include <blpapi_streamproxy.h>
69 #include <blpapi_timepoint.h>
70 
71 struct blpapi_Message;
72 typedef struct blpapi_Message blpapi_Message_t;
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
80 
82 const char *blpapi_Message_typeString(const blpapi_Message_t *message);
83 
85 const char *blpapi_Message_topicName(const blpapi_Message_t *message);
86 
89 
92 
94 blpapi_CorrelationId_t blpapi_Message_correlationId(
95  const blpapi_Message_t *message, size_t index);
96 
99  const blpapi_Message_t *message, const char **requestId);
100 
103 
105 const char *blpapi_Message_privateData(
106  const blpapi_Message_t *message, size_t *size);
107 
110 
112 int blpapi_Message_recapType(const blpapi_Message_t *message);
113 
115 int blpapi_Message_print(const blpapi_Message_t *message,
116  blpapi_StreamWriter_t streamWriter,
117  void *stream,
118  int indentLevel,
119  int spacesPerLevel);
120 
122 int blpapi_Message_addRef(const blpapi_Message_t *message);
123 
125 int blpapi_Message_release(const blpapi_Message_t *message);
126 
129  const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
130 
131 #ifdef __cplusplus
132 }
133 
141 namespace BloombergLP {
142 namespace blpapi {
143 
161 class Message {
162 
163  blpapi_Message_t *d_handle;
164  Element d_elements;
165  bool d_isCloned;
166 
167  public:
171  enum Fragment {
172 
181  };
182 
196  struct RecapType {
197  enum Type {
204  };
205  };
206 
207  public:
208  // CREATORS
209 
211  explicit Message(blpapi_Message_t *handle, bool clonable = false);
219 
221  Message(const Message& original);
230  ~Message();
237  // MANIUPLATORS
238  Message& operator=(const Message& rhs);
247  // ACCESSORS
248  Name messageType() const;
253  BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char *topicName() const;
276  Service service() const;
281  int numCorrelationIds() const;
297  CorrelationId correlationId(size_t index = 0) const;
304  RecapType::Type recapType() const;
311  bool hasElement(const Name& name, bool excludeNullElements = false) const;
316  BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
317  const char *name, bool excludeNullElements = false) const;
326  size_t numElements() const;
331  const Element getElement(const Name& name) const;
336  BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
337  const char *name) const;
344  bool getElementAsBool(const Name& name) const;
349  BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
356  char getElementAsChar(const Name& name) const;
361  BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
368  Int32 getElementAsInt32(const Name& name) const;
373  BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
374  const char *name) const;
381  Int64 getElementAsInt64(const Name& name) const;
386  BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
387  const char *name) const;
394  Float32 getElementAsFloat32(const Name& name) const;
399  BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
400  const char *name) const;
407  Float64 getElementAsFloat64(const Name& name) const;
412  BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
413  const char *name) const;
420  Datetime getElementAsDatetime(const Name& name) const;
425  BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
426  const char *name) const;
433  const char *getElementAsString(const Name& name) const;
438  BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
439  const char *name) const;
446  Bytes getElementAsBytes(const Name& name) const;
451  const char *getRequestId() const;
464  const Element asElement() const;
470  BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
471  size_t *size) const;
482  Fragment fragmentType() const;
489  int timeReceived(TimePoint *timestamp) const;
501  std::ostream& print(
502  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
516  const blpapi_Message_t *impl() const;
522  blpapi_Message_t *impl();
526 };
528 
532 // FREE OPERATORS
533 std::ostream& operator<<(std::ostream& stream, const Message& message);
546 // ============================================================================
547 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
548 // ============================================================================
549 
550 // -------------
551 // class Message
552 // -------------
553 // CREATORS
554 inline Message::Message(blpapi_Message_t *handle, bool clonable)
555  : d_handle(handle)
556  , d_isCloned(clonable)
557 {
558  if (handle) {
559  d_elements = Element(blpapi_Message_elements(handle));
560  }
561 }
562 
563 inline Message::Message(const Message& original)
564  : d_handle(original.d_handle)
565  , d_elements(original.d_elements)
566  , d_isCloned(true)
567 {
568  if (d_handle) {
569  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
570  }
571 }
572 
574 {
575  if (d_isCloned && d_handle) {
576  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
577  }
578 }
579 // MANIPULATORS
580 inline Message& Message::operator=(const Message& rhs)
581 {
582 
583  if (this == &rhs) {
584  return *this;
585  }
586 
587  if (d_isCloned && (d_handle == rhs.d_handle)) {
588  return *this;
589  }
590 
591  if (d_isCloned && d_handle) {
592  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
593  }
594  d_handle = rhs.d_handle;
595  d_elements = rhs.d_elements;
596  d_isCloned = true;
597 
598  if (d_handle) {
599  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
600  }
601 
602  return *this;
603 }
604 
605 // ACCESSORS
607 {
608  return Name(blpapi_Message_messageType(d_handle));
609 }
610 
611 inline const char *Message::topicName() const
612 {
613  return blpapi_Message_topicName(d_handle);
614 }
615 
616 inline Service Message::service() const
617 {
618  return Service(blpapi_Message_service(d_handle));
619 }
620 
621 inline int Message::numCorrelationIds() const
622 {
623  return blpapi_Message_numCorrelationIds(d_handle);
624 }
625 
626 inline CorrelationId Message::correlationId(size_t index) const
627 {
628  if (index >= (size_t)numCorrelationIds())
629  throw IndexOutOfRangeException("index >= numCorrelationIds");
630  return CorrelationId(blpapi_Message_correlationId(d_handle, index));
631 }
632 
634  const char *name, bool excludeNullElements) const
635 {
636  return d_elements.hasElement(Name(name), excludeNullElements);
637 }
638 
640  const Name& name, bool excludeNullElements) const
641 {
642  return d_elements.hasElement(name, excludeNullElements);
643 }
644 
645 inline size_t Message::numElements() const { return d_elements.numElements(); }
646 
647 inline const Element Message::getElement(const Name& name) const
648 {
649  return d_elements.getElement(name);
650 }
651 
652 inline const Element Message::getElement(const char *nameString) const
653 {
654  return d_elements.getElement(Name(nameString));
655 }
656 
657 inline bool Message::getElementAsBool(const Name& name) const
658 {
659  return d_elements.getElementAsBool(name);
660 }
661 
662 inline bool Message::getElementAsBool(const char *name) const
663 {
664  return d_elements.getElementAsBool(Name(name));
665 }
666 
667 inline char Message::getElementAsChar(const Name& name) const
668 {
669  return d_elements.getElementAsChar(name);
670 }
671 
672 inline char Message::getElementAsChar(const char *name) const
673 {
674  return d_elements.getElementAsChar(Name(name));
675 }
676 
677 inline Int32 Message::getElementAsInt32(const Name& name) const
678 {
679  return d_elements.getElementAsInt32(name);
680 }
681 
682 inline Int32 Message::getElementAsInt32(const char *name) const
683 {
684  return d_elements.getElementAsInt32(Name(name));
685 }
686 
687 inline Int64 Message::getElementAsInt64(const Name& name) const
688 {
689  return d_elements.getElementAsInt64(name);
690 }
691 
692 inline Int64 Message::getElementAsInt64(const char *name) const
693 {
694  return d_elements.getElementAsInt64(Name(name));
695 }
696 
697 inline Float32 Message::getElementAsFloat32(const Name& name) const
698 {
699  return d_elements.getElementAsFloat32(name);
700 }
701 
702 inline Float32 Message::getElementAsFloat32(const char *name) const
703 {
704  return d_elements.getElementAsFloat32(Name(name));
705 }
706 
707 inline Float64 Message::getElementAsFloat64(const Name& name) const
708 {
709  return d_elements.getElementAsFloat64(name);
710 }
711 
712 inline Float64 Message::getElementAsFloat64(const char *name) const
713 {
714  return d_elements.getElementAsFloat64(Name(name));
715 }
716 
717 inline Datetime Message::getElementAsDatetime(const Name& name) const
718 {
719  return d_elements.getElementAsDatetime(name);
720 }
721 
722 inline Datetime Message::getElementAsDatetime(const char *name) const
723 {
724  return d_elements.getElementAsDatetime(Name(name));
725 }
726 
727 inline const char *Message::getElementAsString(const Name& name) const
728 {
729  return d_elements.getElementAsString(name);
730 }
731 
732 inline const char *Message::getElementAsString(const char *name) const
733 {
734  return d_elements.getElementAsString(Name(name));
735 }
736 
737 inline Bytes Message::getElementAsBytes(const Name& name) const
738 {
739  return d_elements.getElementAsBytes(name);
740 }
741 
742 inline const char *Message::getRequestId() const
743 {
744  const char *requestId = 0;
745  BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
746  return requestId;
747 }
748 
749 inline const Element Message::asElement() const { return d_elements; }
750 
751 inline const char *Message::getPrivateData(size_t *size) const
752 {
753  return blpapi_Message_privateData(d_handle, size);
754 }
755 
757 {
759 }
760 
762 {
763  return static_cast<Message::RecapType::Type>(
765 }
766 
767 inline int Message::timeReceived(TimePoint *timestamp) const
768 {
769  return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
770 }
771 
772 inline std::ostream& Message::print(
773  std::ostream& stream, int level, int spacesPerLevel) const
774 {
777  (d_handle,
779  &stream,
780  level,
781  spacesPerLevel);
782  return stream;
783  } else {
784  return d_elements.print(stream, level, spacesPerLevel);
785  }
786 }
787 
788 inline std::ostream& operator<<(std::ostream& stream, const Message& message)
789 {
790  return message.print(stream, 0, -1);
791 }
792 
793 inline const blpapi_Message_t *Message::impl() const { return d_handle; }
794 
795 inline blpapi_Message_t *Message::impl() { return d_handle; }
796 
797 } // close namespace blpapi
798 } // close namespace BloombergLP
799 
800 #endif // #ifdef __cplusplus
801 #endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Int64 getElementAsInt64(const Name &name) const
Definition: blpapi_message.h:687
int blpapi_Message_recapType(const blpapi_Message_t *message)
struct blpapi_Message blpapi_Message_t
Definition: blpapi_dispatchtbl.h:78
the first fragmented message
Definition: blpapi_message.h:175
Definition: blpapi_timepoint.h:104
Definition: blpapi_message.h:161
#define BLPAPI_MESSAGE_FRAGMENT_END
Definition: blpapi_defs.h:147
message is not fragmented
Definition: blpapi_message.h:173
Float32 getElementAsFloat32(const Name &name) const
Definition: blpapi_message.h:697
BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const
Definition: blpapi_element.h:2230
int timeReceived(TimePoint *timestamp) const
Definition: blpapi_message.h:767
#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:616
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:197
#define BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE
Definition: blpapi_defs.h:146
BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(const char *name) const
Definition: blpapi_element.h:2270
BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2280
Definition: blpapi_abstractsession.h:187
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:772
#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:626
Message & operator=(const Message &rhs)
Definition: blpapi_message.h:580
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.
BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(const char *name) const
Definition: blpapi_element.h:2290
Definition: blpapi_element.h:465
bool getElementAsBool(const Name &name) const
Definition: blpapi_message.h:657
BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(const char *name) const
Definition: blpapi_element.h:2250
Fragment fragmentType() const
Definition: blpapi_message.h:756
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:727
Int32 getElementAsInt32(const Name &name) const
Definition: blpapi_message.h:677
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)
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition: blpapi_element.h:1910
BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2260
BLPAPI_DEPRECATE_STRING_NAME const char * getPrivateData(size_t *size) const
Definition: blpapi_message.h:751
size_t numElements() const
Definition: blpapi_element.h:1985
A signature for callback on print and default C++ implementation.
Fragment
Definition: blpapi_message.h:171
int numCorrelationIds() const
Definition: blpapi_message.h:621
BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char * topicName() const
Definition: blpapi_message.h:611
const char * getRequestId() const
Definition: blpapi_message.h:742
BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const
Definition: blpapi_element.h:2240
RecapType::Type recapType() const
Definition: blpapi_message.h:761
const Element getElement(const Name &name) const
Definition: blpapi_message.h:647
blpapi_Element_t * blpapi_Message_elements(const blpapi_Message_t *message)
Message(const Message &original)
Definition: blpapi_message.h:554
Float64 getElementAsFloat64(const Name &name) const
Definition: blpapi_message.h:707
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition: blpapi_message.h:639
BLPAPI_DEPRECATE_STRING_NAME bool hasElement(const char *name, bool excludeNullElements=false) const
Definition: blpapi_element.h:2001
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2310
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2327
Definition: blpapi_message.h:196
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:606
normal data tick; not a recap
Definition: blpapi_message.h:198
Datetime getElementAsDatetime(const Name &name) const
Definition: blpapi_message.h:717
const Element asElement() const
Definition: blpapi_message.h:749
#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:177
Provide functions for dispatchtbl.
generated on request by subscriber
Definition: blpapi_message.h:200
#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:667
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_message.h:737
the last fragmented message
Definition: blpapi_message.h:179
Provide a representation of an item in a message.
BLPAPI_DEPRECATE_STRING_NAME const char * getElementAsString(const char *name) const
Definition: blpapi_element.h:2300
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:645
~Message()
Definition: blpapi_message.h:573
generated at discretion of the service
Definition: blpapi_message.h:202
#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)