BLPAPI C++  3.24.8
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;
324  size_t numElements() const;
329  const Element getElement(const Name& name) const;
334  BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
335  const char *name) const;
342  bool getElementAsBool(const Name& name) const;
347  BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
354  char getElementAsChar(const Name& name) const;
359  BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
366  Int32 getElementAsInt32(const Name& name) const;
371  BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
372  const char *name) const;
379  Int64 getElementAsInt64(const Name& name) const;
384  BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
385  const char *name) const;
392  Float32 getElementAsFloat32(const Name& name) const;
397  BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
398  const char *name) const;
405  Float64 getElementAsFloat64(const Name& name) const;
410  BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
411  const char *name) const;
418  Datetime getElementAsDatetime(const Name& name) const;
423  BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
424  const char *name) const;
431  const char *getElementAsString(const Name& name) const;
436  BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
437  const char *name) const;
444  Bytes getElementAsBytes(const Name& name) const;
449  const char *getRequestId() const;
462  const Element asElement() const;
468  BLPAPI_DEPRECATE_STRING_NAME const char *getPrivateData(
469  size_t *size) const;
480  Fragment fragmentType() const;
487  int timeReceived(TimePoint *timestamp) const;
499  std::ostream& print(
500  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
514  const blpapi_Message_t *impl() const;
520  blpapi_Message_t *impl();
524 };
526 
530 // FREE OPERATORS
531 std::ostream& operator<<(std::ostream& stream, const Message& message);
544 // ============================================================================
545 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
546 // ============================================================================
547 
548 // -------------
549 // class Message
550 // -------------
551 // CREATORS
552 inline Message::Message(blpapi_Message_t *handle, bool clonable)
553  : d_handle(handle)
554  , d_isCloned(clonable)
555 {
556  if (handle) {
557  d_elements = Element(blpapi_Message_elements(handle));
558  }
559 }
560 
561 inline Message::Message(const Message& original)
562  : d_handle(original.d_handle)
563  , d_elements(original.d_elements)
564  , d_isCloned(true)
565 {
566  if (d_handle) {
567  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
568  }
569 }
570 
572 {
573  if (d_isCloned && d_handle) {
574  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
575  }
576 }
577 // MANIPULATORS
578 inline Message& Message::operator=(const Message& rhs)
579 {
580 
581  if (this == &rhs) {
582  return *this;
583  }
584 
585  if (d_isCloned && (d_handle == rhs.d_handle)) {
586  return *this;
587  }
588 
589  if (d_isCloned && d_handle) {
590  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
591  }
592  d_handle = rhs.d_handle;
593  d_elements = rhs.d_elements;
594  d_isCloned = true;
595 
596  if (d_handle) {
597  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
598  }
599 
600  return *this;
601 }
602 
603 // ACCESSORS
605 {
606  return Name(blpapi_Message_messageType(d_handle));
607 }
608 
609 inline const char *Message::topicName() const
610 {
611  return blpapi_Message_topicName(d_handle);
612 }
613 
614 inline Service Message::service() const
615 {
616  return Service(blpapi_Message_service(d_handle));
617 }
618 
619 inline int Message::numCorrelationIds() const
620 {
621  return blpapi_Message_numCorrelationIds(d_handle);
622 }
623 
624 inline CorrelationId Message::correlationId(size_t index) const
625 {
626  if (index >= (size_t)numCorrelationIds())
627  throw IndexOutOfRangeException("index >= numCorrelationIds");
628  return CorrelationId(blpapi_Message_correlationId(d_handle, index));
629 }
630 
632  const char *name, bool excludeNullElements) const
633 {
634  return d_elements.hasElement(Name(name), excludeNullElements);
635 }
636 
638  const Name& name, bool excludeNullElements) const
639 {
640  return d_elements.hasElement(name, excludeNullElements);
641 }
642 
643 inline size_t Message::numElements() const { return d_elements.numElements(); }
644 
645 inline const Element Message::getElement(const Name& name) const
646 {
647  return d_elements.getElement(name);
648 }
649 
650 inline const Element Message::getElement(const char *nameString) const
651 {
652  return d_elements.getElement(Name(nameString));
653 }
654 
655 inline bool Message::getElementAsBool(const Name& name) const
656 {
657  return d_elements.getElementAsBool(name);
658 }
659 
660 inline bool Message::getElementAsBool(const char *name) const
661 {
662  return d_elements.getElementAsBool(Name(name));
663 }
664 
665 inline char Message::getElementAsChar(const Name& name) const
666 {
667  return d_elements.getElementAsChar(name);
668 }
669 
670 inline char Message::getElementAsChar(const char *name) const
671 {
672  return d_elements.getElementAsChar(Name(name));
673 }
674 
675 inline Int32 Message::getElementAsInt32(const Name& name) const
676 {
677  return d_elements.getElementAsInt32(name);
678 }
679 
680 inline Int32 Message::getElementAsInt32(const char *name) const
681 {
682  return d_elements.getElementAsInt32(Name(name));
683 }
684 
685 inline Int64 Message::getElementAsInt64(const Name& name) const
686 {
687  return d_elements.getElementAsInt64(name);
688 }
689 
690 inline Int64 Message::getElementAsInt64(const char *name) const
691 {
692  return d_elements.getElementAsInt64(Name(name));
693 }
694 
695 inline Float32 Message::getElementAsFloat32(const Name& name) const
696 {
697  return d_elements.getElementAsFloat32(name);
698 }
699 
700 inline Float32 Message::getElementAsFloat32(const char *name) const
701 {
702  return d_elements.getElementAsFloat32(Name(name));
703 }
704 
705 inline Float64 Message::getElementAsFloat64(const Name& name) const
706 {
707  return d_elements.getElementAsFloat64(name);
708 }
709 
710 inline Float64 Message::getElementAsFloat64(const char *name) const
711 {
712  return d_elements.getElementAsFloat64(Name(name));
713 }
714 
715 inline Datetime Message::getElementAsDatetime(const Name& name) const
716 {
717  return d_elements.getElementAsDatetime(name);
718 }
719 
720 inline Datetime Message::getElementAsDatetime(const char *name) const
721 {
722  return d_elements.getElementAsDatetime(Name(name));
723 }
724 
725 inline const char *Message::getElementAsString(const Name& name) const
726 {
727  return d_elements.getElementAsString(name);
728 }
729 
730 inline const char *Message::getElementAsString(const char *name) const
731 {
732  return d_elements.getElementAsString(Name(name));
733 }
734 
735 inline Bytes Message::getElementAsBytes(const Name& name) const
736 {
737  return d_elements.getElementAsBytes(name);
738 }
739 
740 inline const char *Message::getRequestId() const
741 {
742  const char *requestId = 0;
743  BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
744  return requestId;
745 }
746 
747 inline const Element Message::asElement() const { return d_elements; }
748 
749 inline const char *Message::getPrivateData(size_t *size) const
750 {
751  return blpapi_Message_privateData(d_handle, size);
752 }
753 
755 {
757 }
758 
760 {
761  return static_cast<Message::RecapType::Type>(
763 }
764 
765 inline int Message::timeReceived(TimePoint *timestamp) const
766 {
767  return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
768 }
769 
770 inline std::ostream& Message::print(
771  std::ostream& stream, int level, int spacesPerLevel) const
772 {
775  (d_handle,
777  &stream,
778  level,
779  spacesPerLevel);
780  return stream;
781  } else {
782  return d_elements.print(stream, level, spacesPerLevel);
783  }
784 }
785 
786 inline std::ostream& operator<<(std::ostream& stream, const Message& message)
787 {
788  return message.print(stream, 0, -1);
789 }
790 
791 inline const blpapi_Message_t *Message::impl() const { return d_handle; }
792 
793 inline blpapi_Message_t *Message::impl() { return d_handle; }
794 
795 } // close namespace blpapi
796 } // close namespace BloombergLP
797 
798 #endif // #ifdef __cplusplus
799 #endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Int64 getElementAsInt64(const Name &name) const
Definition: blpapi_message.h:685
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:695
BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const
Definition: blpapi_element.h:2230
int timeReceived(TimePoint *timestamp) const
Definition: blpapi_message.h:765
#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:614
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:770
#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:624
Message & operator=(const Message &rhs)
Definition: blpapi_message.h:578
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:655
BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(const char *name) const
Definition: blpapi_element.h:2250
Fragment fragmentType() const
Definition: blpapi_message.h:754
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:725
Int32 getElementAsInt32(const Name &name) const
Definition: blpapi_message.h:675
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:749
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:619
BLPAPI_DEPRECATE_MESSAGE_TOPIC_NAME const char * topicName() const
Definition: blpapi_message.h:609
const char * getRequestId() const
Definition: blpapi_message.h:740
BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const
Definition: blpapi_element.h:2240
RecapType::Type recapType() const
Definition: blpapi_message.h:759
const Element getElement(const Name &name) const
Definition: blpapi_message.h:645
blpapi_Element_t * blpapi_Message_elements(const blpapi_Message_t *message)
Message(const Message &original)
Definition: blpapi_message.h:552
Float64 getElementAsFloat64(const Name &name) const
Definition: blpapi_message.h:705
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition: blpapi_message.h:637
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:604
normal data tick; not a recap
Definition: blpapi_message.h:198
Datetime getElementAsDatetime(const Name &name) const
Definition: blpapi_message.h:715
const Element asElement() const
Definition: blpapi_message.h:747
#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:665
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_message.h:735
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:643
~Message()
Definition: blpapi_message.h:571
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)