BLPAPI C++  3.21.0
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_service.h>
66 #include <blpapi_streamproxy.h>
67 #include <blpapi_timepoint.h>
68 
69 struct blpapi_Message;
70 typedef struct blpapi_Message blpapi_Message_t;
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
78 
80 const char *blpapi_Message_typeString(const blpapi_Message_t *message);
81 
83 const char *blpapi_Message_topicName(const blpapi_Message_t *message);
84 
87 
90 
92 blpapi_CorrelationId_t blpapi_Message_correlationId(
93  const blpapi_Message_t *message, size_t index);
94 
97  const blpapi_Message_t *message, const char **requestId);
98 
101 
103 const char *blpapi_Message_privateData(
104  const blpapi_Message_t *message, size_t *size);
105 
108 
110 int blpapi_Message_recapType(const blpapi_Message_t *message);
111 
113 int blpapi_Message_print(const blpapi_Message_t *message,
114  blpapi_StreamWriter_t streamWriter,
115  void *stream,
116  int indentLevel,
117  int spacesPerLevel);
118 
120 int blpapi_Message_addRef(const blpapi_Message_t *message);
121 
123 int blpapi_Message_release(const blpapi_Message_t *message);
124 
127  const blpapi_Message_t *message, blpapi_TimePoint_t *timeReceived);
128 
129 #ifdef __cplusplus
130 }
131 
139 namespace BloombergLP {
140 namespace blpapi {
141 
159 class Message {
160 
161  blpapi_Message_t *d_handle;
162  Element d_elements;
163  bool d_isCloned;
164 
165  public:
169  enum Fragment {
170 
179  };
180 
194  struct RecapType {
195  enum Type {
202  };
203  };
204 
205  public:
206  // CREATORS
207 
209  Message(blpapi_Message_t *handle, bool clonable = false);
217 
219  Message(const Message& original);
228  ~Message();
235  // MANIUPLATORS
236  Message& operator=(const Message& rhs);
245  // ACCESSORS
246  Name messageType() const;
251  const char *topicName() const;
274  Service service() const;
279  int numCorrelationIds() const;
295  CorrelationId correlationId(size_t index = 0) const;
302  RecapType::Type recapType() const;
309  bool hasElement(const Name& name, bool excludeNullElements = false) const;
314  bool hasElement(const char *name, bool excludeNullElements = false) const;
321  size_t numElements() const;
326  const Element getElement(const Name& name) const;
331  const Element getElement(const char *name) const;
338  bool getElementAsBool(const Name& name) const;
343  bool getElementAsBool(const char *name) const;
350  char getElementAsChar(const Name& name) const;
355  char getElementAsChar(const char *name) const;
362  Int32 getElementAsInt32(const Name& name) const;
367  Int32 getElementAsInt32(const char *name) const;
374  Int64 getElementAsInt64(const Name& name) const;
379  Int64 getElementAsInt64(const char *name) const;
386  Float32 getElementAsFloat32(const Name& name) const;
391  Float32 getElementAsFloat32(const char *name) const;
398  Float64 getElementAsFloat64(const Name& name) const;
403  Float64 getElementAsFloat64(const char *name) const;
410  Datetime getElementAsDatetime(const Name& name) const;
415  Datetime getElementAsDatetime(const char *name) const;
422  const char *getElementAsString(const Name& name) const;
427  const char *getElementAsString(const char *name) const;
434  Bytes getElementAsBytes(const Name& name) const;
439  const char *getRequestId() const;
452  const Element asElement() const;
458  const char *getPrivateData(size_t *size) const;
469  Fragment fragmentType() const;
476  int timeReceived(TimePoint *timestamp) const;
488  std::ostream& print(
489  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
503  const blpapi_Message_t *impl() const;
509  blpapi_Message_t *impl();
513 };
515 
519 // FREE OPERATORS
520 std::ostream& operator<<(std::ostream& stream, const Message& message);
533 // ============================================================================
534 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
535 // ============================================================================
536 
537 // -------------
538 // class Message
539 // -------------
540 // CREATORS
541 inline Message::Message(blpapi_Message_t *handle, bool clonable)
542  : d_handle(handle)
543  , d_isCloned(clonable)
544 {
545  if (handle) {
546  d_elements = Element(blpapi_Message_elements(handle));
547  }
548 }
549 
550 inline Message::Message(const Message& original)
551  : d_handle(original.d_handle)
552  , d_elements(original.d_elements)
553  , d_isCloned(true)
554 {
555  if (d_handle) {
556  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
557  }
558 }
559 
561 {
562  if (d_isCloned && d_handle) {
563  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
564  }
565 }
566 // MANIPULATORS
567 inline Message& Message::operator=(const Message& rhs)
568 {
569 
570  if (this == &rhs) {
571  return *this;
572  }
573 
574  if (d_isCloned && (d_handle == rhs.d_handle)) {
575  return *this;
576  }
577 
578  if (d_isCloned && d_handle) {
579  BLPAPI_CALL_MESSAGE_RELEASE(d_handle);
580  }
581  d_handle = rhs.d_handle;
582  d_elements = rhs.d_elements;
583  d_isCloned = true;
584 
585  if (d_handle) {
586  BLPAPI_CALL_MESSAGE_ADDREF(d_handle);
587  }
588 
589  return *this;
590 }
591 
592 // ACCESSORS
594 {
595  return Name(blpapi_Message_messageType(d_handle));
596 }
597 
598 inline const char *Message::topicName() const
599 {
600  return blpapi_Message_topicName(d_handle);
601 }
602 
603 inline Service Message::service() const
604 {
605  return Service(blpapi_Message_service(d_handle));
606 }
607 
608 inline int Message::numCorrelationIds() const
609 {
610  return blpapi_Message_numCorrelationIds(d_handle);
611 }
612 
613 inline CorrelationId Message::correlationId(size_t index) const
614 {
615  if (index >= (size_t)numCorrelationIds())
616  throw IndexOutOfRangeException("index >= numCorrelationIds");
617  return CorrelationId(blpapi_Message_correlationId(d_handle, index));
618 }
619 
621  const char *name, bool excludeNullElements) const
622 {
623  return d_elements.hasElement(name, excludeNullElements);
624 }
625 
627  const Name& name, bool excludeNullElements) const
628 {
629  return d_elements.hasElement(name, excludeNullElements);
630 }
631 
632 inline size_t Message::numElements() const { return d_elements.numElements(); }
633 
634 inline const Element Message::getElement(const Name& name) const
635 {
636  return d_elements.getElement(name);
637 }
638 
639 inline const Element Message::getElement(const char *nameString) const
640 {
641  return d_elements.getElement(nameString);
642 }
643 
644 inline bool Message::getElementAsBool(const Name& name) const
645 {
646  return d_elements.getElementAsBool(name);
647 }
648 
649 inline bool Message::getElementAsBool(const char *name) const
650 {
651  return d_elements.getElementAsBool(name);
652 }
653 
654 inline char Message::getElementAsChar(const Name& name) const
655 {
656  return d_elements.getElementAsChar(name);
657 }
658 
659 inline char Message::getElementAsChar(const char *name) const
660 {
661  return d_elements.getElementAsChar(name);
662 }
663 
664 inline Int32 Message::getElementAsInt32(const Name& name) const
665 {
666  return d_elements.getElementAsInt32(name);
667 }
668 
669 inline Int32 Message::getElementAsInt32(const char *name) const
670 {
671  return d_elements.getElementAsInt32(name);
672 }
673 
674 inline Int64 Message::getElementAsInt64(const Name& name) const
675 {
676  return d_elements.getElementAsInt64(name);
677 }
678 
679 inline Int64 Message::getElementAsInt64(const char *name) const
680 {
681  return d_elements.getElementAsInt64(name);
682 }
683 
684 inline Float32 Message::getElementAsFloat32(const Name& name) const
685 {
686  return d_elements.getElementAsFloat32(name);
687 }
688 
689 inline Float32 Message::getElementAsFloat32(const char *name) const
690 {
691  return d_elements.getElementAsFloat32(name);
692 }
693 
694 inline Float64 Message::getElementAsFloat64(const Name& name) const
695 {
696  return d_elements.getElementAsFloat64(name);
697 }
698 
699 inline Float64 Message::getElementAsFloat64(const char *name) const
700 {
701  return d_elements.getElementAsFloat64(name);
702 }
703 
704 inline Datetime Message::getElementAsDatetime(const Name& name) const
705 {
706  return d_elements.getElementAsDatetime(name);
707 }
708 
709 inline Datetime Message::getElementAsDatetime(const char *name) const
710 {
711  return d_elements.getElementAsDatetime(name);
712 }
713 
714 inline const char *Message::getElementAsString(const Name& name) const
715 {
716  return d_elements.getElementAsString(name);
717 }
718 
719 inline const char *Message::getElementAsString(const char *name) const
720 {
721  return d_elements.getElementAsString(name);
722 }
723 
724 inline Bytes Message::getElementAsBytes(const Name& name) const
725 {
726  return d_elements.getElementAsBytes(name);
727 }
728 
729 inline const char *Message::getRequestId() const
730 {
731  const char *requestId = 0;
732  BLPAPI_CALL(blpapi_Message_getRequestId)(d_handle, &requestId);
733  return requestId;
734 }
735 
736 inline const Element Message::asElement() const { return d_elements; }
737 
738 inline const char *Message::getPrivateData(size_t *size) const
739 {
740  return blpapi_Message_privateData(d_handle, size);
741 }
742 
744 {
746 }
747 
749 {
750  return static_cast<Message::RecapType::Type>(
752 }
753 
754 inline int Message::timeReceived(TimePoint *timestamp) const
755 {
756  return BLPAPI_CALL_MESSAGE_TIMERECEIVED(d_handle, timestamp);
757 }
758 
759 inline std::ostream& Message::print(
760  std::ostream& stream, int level, int spacesPerLevel) const
761 {
764  (d_handle,
766  &stream,
767  level,
768  spacesPerLevel);
769  return stream;
770  } else {
771  return d_elements.print(stream, level, spacesPerLevel);
772  }
773 }
774 
775 inline std::ostream& operator<<(std::ostream& stream, const Message& message)
776 {
777  return message.print(stream, 0, -1);
778 }
779 
780 inline const blpapi_Message_t *Message::impl() const { return d_handle; }
781 
782 inline blpapi_Message_t *Message::impl() { return d_handle; }
783 
784 } // close namespace blpapi
785 } // close namespace BloombergLP
786 
787 #endif // #ifdef __cplusplus
788 #endif // #ifndef INCLUDED_BLPAPI_MESSAGE
Int64 getElementAsInt64(const Name &name) const
Definition: blpapi_message.h:674
int blpapi_Message_recapType(const blpapi_Message_t *message)
the first fragmented message
Definition: blpapi_message.h:173
Definition: blpapi_timepoint.h:104
Definition: blpapi_message.h:159
#define BLPAPI_MESSAGE_FRAGMENT_END
Definition: blpapi_defs.h:147
message is not fragmented
Definition: blpapi_message.h:171
Float32 getElementAsFloat32(const Name &name) const
Definition: blpapi_message.h:684
bool getElementAsBool(const char *name) const
Definition: blpapi_element.h:2211
int timeReceived(TimePoint *timestamp) const
Definition: blpapi_message.h:754
#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:603
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:195
#define BLPAPI_MESSAGE_FRAGMENT_INTERMEDIATE
Definition: blpapi_defs.h:146
Float32 getElementAsFloat32(const char *name) const
Definition: blpapi_element.h:2251
Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2261
Definition: blpapi_abstractsession.h:215
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:759
#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:613
Message & operator=(const Message &rhs)
Definition: blpapi_message.h:567
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:70
Datetime getElementAsDatetime(const char *name) const
Definition: blpapi_element.h:2271
Definition: blpapi_element.h:464
bool getElementAsBool(const Name &name) const
Definition: blpapi_message.h:644
Int32 getElementAsInt32(const char *name) const
Definition: blpapi_element.h:2231
Fragment fragmentType() const
Definition: blpapi_message.h:743
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:714
Int32 getElementAsInt32(const Name &name) const
Definition: blpapi_message.h:664
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:1891
Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2241
const char * getPrivateData(size_t *size) const
Definition: blpapi_message.h:738
size_t numElements() const
Definition: blpapi_element.h:1966
A signature for callback on print and default C++ implementation.
Fragment
Definition: blpapi_message.h:169
int numCorrelationIds() const
Definition: blpapi_message.h:608
const char * topicName() const
Definition: blpapi_message.h:598
const char * getRequestId() const
Definition: blpapi_message.h:729
char getElementAsChar(const char *name) const
Definition: blpapi_element.h:2221
RecapType::Type recapType() const
Definition: blpapi_message.h:748
const Element getElement(const Name &name) const
Definition: blpapi_message.h:634
blpapi_Element_t * blpapi_Message_elements(const blpapi_Message_t *message)
Message(const Message &original)
Definition: blpapi_message.h:541
Float64 getElementAsFloat64(const Name &name) const
Definition: blpapi_message.h:694
bool hasElement(const Name &name, bool excludeNullElements=false) const
Definition: blpapi_message.h:626
bool hasElement(const char *name, bool excludeNullElements=false) const
Definition: blpapi_element.h:1982
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2291
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2308
Definition: blpapi_message.h:194
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:593
normal data tick; not a recap
Definition: blpapi_message.h:196
Datetime getElementAsDatetime(const Name &name) const
Definition: blpapi_message.h:704
const Element asElement() const
Definition: blpapi_message.h:736
#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:175
Provide functions for dispatchtbl.
generated on request by subscriber
Definition: blpapi_message.h:198
#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:654
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_message.h:724
the last fragmented message
Definition: blpapi_message.h:177
Provide a representation of an item in a message.
const char * getElementAsString(const char *name) const
Definition: blpapi_element.h:2281
int blpapi_Message_release(const blpapi_Message_t *message)
Definition: blpapi_types.h:312
size_t numElements() const
Definition: blpapi_message.h:632
~Message()
Definition: blpapi_message.h:560
generated at discretion of the service
Definition: blpapi_message.h:200
#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)