BLPAPI C++  3.22.1
blpapi_service.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_SERVICE
29 #define INCLUDED_BLPAPI_SERVICE
30 
66 #ifndef INCLUDED_BLPAPI_DEFS
67 #include <blpapi_defs.h>
68 #endif
69 
70 #ifndef INCLUDED_BLPAPI_TYPES
71 #include <blpapi_types.h>
72 #endif
73 
74 #ifndef INCLUDED_BLPAPI_SCHEMA
75 #include <blpapi_schema.h>
76 #endif
77 
78 #ifndef INCLUDED_BLPAPI_REQUEST
79 #include <blpapi_request.h>
80 #endif
81 
82 #ifndef INCLUDED_BLPAPI_CORRELATIONID
83 #include <blpapi_correlationid.h>
84 #endif
85 
86 #ifndef INCLUDED_BLPAPI_STREAMPROXY
87 #include <blpapi_streamproxy.h>
88 #endif
89 
90 #include <stddef.h>
91 
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95 
97 const char *blpapi_Operation_name(blpapi_Operation_t *operation);
98 
100 const char *blpapi_Operation_description(blpapi_Operation_t *operation);
101 
104  blpapi_SchemaElementDefinition_t **requestDefinition);
105 
108 
111  blpapi_SchemaElementDefinition_t **responseDefinition,
112  size_t index);
113 
116  blpapi_SchemaElementDefinition_t **responseDefinition,
117  const blpapi_Name_t *name);
118 
120 const char *blpapi_Service_name(blpapi_Service_t *service);
121 
123 const char *blpapi_Service_description(blpapi_Service_t *service);
124 
127 
130 
133 
136 
139 
142  blpapi_Operation_t **operation,
143  const char *nameString,
144  const blpapi_Name_t *name);
145 
148  blpapi_Operation_t **operation,
149  size_t index);
150 
154  const char *nameString,
155  const blpapi_Name_t *name);
156 
160  size_t index);
161 
164  blpapi_Request_t **request,
165  const char *operation);
166 
169  blpapi_Request_t **request,
170  const char *operation);
171 
174  blpapi_Service_t *service, blpapi_Event_t **event);
175 
178  blpapi_Service_t *service, blpapi_Event_t **event);
179 
182  const blpapi_CorrelationId_t *correlationId,
183  blpapi_Event_t **event);
184 
186  blpapi_StreamWriter_t streamWriter,
187  void *stream,
188  int level,
189  int spacesPerLevel);
190 
191 #ifdef __cplusplus
192 }
193 
194 #ifndef INCLUDED_BLPAPI_EXCEPTION
195 #include <blpapi_exception.h>
196 #endif
197 
198 #include <utility>
199 
207 namespace BloombergLP {
208 namespace blpapi {
209 
220 class Operation {
221 
222  blpapi_Operation_t *d_handle;
223 
224  public:
226 
227  ~Operation();
232  const char *name() const;
239  const char *description() const;
252  int numResponseDefinitions() const;
258  SchemaElementDefinition responseDefinition(size_t index) const;
270  blpapi_Operation_t *handle() const;
275  bool isValid() const;
280 };
281 
304 class Service {
305 
306  blpapi_Service_t *d_handle;
307 
308  void addRef();
309  void release();
310 
311  public:
312  // PUBLIC TYPES
313  struct TestService { }; // tag type
314 
315  // CREATORS
316  Service();
332  Service(const Service& original);
337  ~Service();
343  // MANIPULATORS
344 
345  Service& operator=(const Service& rhs);
350  // ACCESSORS
351 
352  Request createRequest(const char *operation) const;
363  const char *authorizationOperation = 0) const;
391  const CorrelationId& correlationId) const;
397  const char *name() const;
404  const char *description() const;
411  size_t numOperations() const;
416  bool hasOperation(const char *name) const;
422  bool hasOperation(const Name& name) const;
428  Operation getOperation(size_t index) const;
434  Operation getOperation(const char *name) const;
441  Operation getOperation(const Name& name) const;
448  int numEventDefinitions() const;
453  bool hasEventDefinition(const char *name) const;
459  bool hasEventDefinition(const Name& name) const;
465  SchemaElementDefinition getEventDefinition(size_t index) const;
488  const char *authorizationServiceName() const;
496  bool isValid() const;
502  blpapi_Service_t *handle() const;
503 
504  std::ostream& print(
505  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
518 };
519 
523 // FREE OPERATORS
524 std::ostream& operator<<(std::ostream& stream, const Service& service);
537 // ============================================================================
538 // INLINE FUNCTION DEFINITIONS
539 // ============================================================================
540 
541 // ---------------
542 // class Operation
543 // ---------------
545  : d_handle(newHandle)
546 {
547 }
548 
550 
551 inline const char *Operation::name() const
552 {
553  if (!isValid()) {
555  }
556 
557  return blpapi_Operation_name(d_handle);
558 }
559 
560 inline const char *Operation::description() const
561 {
562  if (!isValid()) {
564  }
565 
566  return blpapi_Operation_description(d_handle);
567 }
568 
570 {
571  blpapi_SchemaElementDefinition_t *definition = 0;
572 
574  blpapi_Operation_requestDefinition(d_handle, &definition));
575  return SchemaElementDefinition(definition);
576 }
577 
579 {
580  if (!isValid()) {
582  }
583 
585 }
586 
588  size_t index) const
589 {
590  blpapi_SchemaElementDefinition_t *definition = 0;
591 
593  blpapi_Operation_responseDefinition(d_handle, &definition, index));
594  return SchemaElementDefinition(definition);
595 }
596 
598  const Name& name) const
599 {
600  blpapi_SchemaElementDefinition_t *definition = 0;
601 
604  d_handle, &definition, name.impl()));
605  return SchemaElementDefinition(definition);
606 }
607 
608 inline blpapi_Operation_t *Operation::handle() const { return d_handle; }
609 
610 inline bool Operation::isValid() const { return d_handle != 0; }
611 // -------------
612 // class Service
613 // -------------
614 
616  : d_handle(0)
617 {
618 }
619 
620 inline Service::Service(const Service& original)
621  : d_handle(original.d_handle)
622 {
623  addRef();
624 }
625 
627  : d_handle(newHandle)
628 {
629  addRef();
630 }
631 
633  : d_handle(handle)
634 {
635  // test service de-serialise releases the handle to us
636 }
637 
638 inline Service::~Service() { release(); }
639 
640 inline Service& Service::operator=(const Service& rhs)
641 {
642  using std::swap;
643 
644  Service tmp(rhs);
645  swap(tmp.d_handle, d_handle);
646 
647  return *this;
648 }
649 
650 inline void Service::addRef()
651 {
652  if (d_handle) {
653  blpapi_Service_addRef(d_handle);
654  }
655 }
656 
657 inline void Service::release()
658 {
659  if (d_handle) {
660  blpapi_Service_release(d_handle);
661  }
662 }
663 
664 inline Request Service::createRequest(const char *operation) const
665 {
666  blpapi_Request_t *request = 0;
668  blpapi_Service_createRequest(d_handle, &request, operation));
669  return Request(request);
670 }
671 
673  const char *authorizationOperation) const
674 {
675  blpapi_Request_t *request = 0;
677  d_handle, &request, authorizationOperation));
678  return Request(request);
679 }
680 
682 {
683  blpapi_Event_t *event = 0;
685  blpapi_Service_createPublishEvent(d_handle, &event));
686  return event;
687 }
688 
690 {
691  blpapi_Event_t *event = 0;
693  blpapi_Service_createAdminEvent(d_handle, &event));
694  return event;
695 }
696 
698  const CorrelationId& correlationId) const
699 {
700  blpapi_Event_t *event = 0;
702  d_handle, &correlationId.impl(), &event));
703  return event;
704 }
705 
706 inline blpapi_Service_t *Service::handle() const { return d_handle; }
707 
708 inline bool Service::isValid() const { return (d_handle != 0); }
709 
710 inline const char *Service::name() const
711 {
712  if (!isValid()) {
714  }
715 
716  return blpapi_Service_name(d_handle);
717 }
718 
719 inline const char *Service::description() const
720 {
721  if (!isValid()) {
723  }
724 
725  return blpapi_Service_description(d_handle);
726 }
727 
728 inline size_t Service::numOperations() const
729 {
730  if (!isValid()) {
732  }
733 
734  return static_cast<size_t>(blpapi_Service_numOperations(d_handle));
735 }
736 
737 inline bool Service::hasOperation(const char *operationName) const
738 {
739  blpapi_Operation_t *operation = 0;
740  return blpapi_Service_getOperation(d_handle, &operation, operationName, 0)
741  == 0;
742 }
743 
744 inline bool Service::hasOperation(const Name& operationName) const
745 {
746  blpapi_Operation_t *operation = 0;
748  d_handle, &operation, 0, operationName.impl())
749  == 0;
750 }
751 
752 inline Operation Service::getOperation(size_t index) const
753 {
754  blpapi_Operation_t *operation = 0;
756  blpapi_Service_getOperationAt(d_handle, &operation, index));
757  return operation;
758 }
759 
760 inline Operation Service::getOperation(const char *operationName) const
761 {
762  blpapi_Operation_t *operation = 0;
764  d_handle, &operation, operationName, 0));
765  return operation;
766 }
767 
768 inline Operation Service::getOperation(const Name& operationName) const
769 {
770  blpapi_Operation_t *operation = 0;
772  d_handle, &operation, 0, operationName.impl()));
773  return operation;
774 }
775 
777 {
778  if (!isValid()) {
780  }
781 
782  return blpapi_Service_numEventDefinitions(d_handle);
783 }
784 
785 inline bool Service::hasEventDefinition(const char *definitionName) const
786 {
787  blpapi_SchemaElementDefinition_t *eventDefinition = 0;
788 
790  d_handle, &eventDefinition, definitionName, 0)
791  == 0
792  ? true
793  : false;
794 }
795 
796 inline bool Service::hasEventDefinition(const Name& definitionName) const
797 {
798  blpapi_SchemaElementDefinition_t *eventDefinition = 0;
799 
801  d_handle, &eventDefinition, 0, definitionName.impl())
802  == 0
803  ? true
804  : false;
805 }
806 
808 {
809  blpapi_SchemaElementDefinition_t *eventDefinition = 0;
810 
812  d_handle, &eventDefinition, index));
813  return SchemaElementDefinition(eventDefinition);
814 }
815 
817  const char *definitionName) const
818 {
819  blpapi_SchemaElementDefinition_t *eventDefinition = 0;
821  d_handle, &eventDefinition, definitionName, 0));
822  return SchemaElementDefinition(eventDefinition);
823 }
824 
826  const Name& definitionName) const
827 {
828  blpapi_SchemaElementDefinition_t *eventDefinition = 0;
830  d_handle, &eventDefinition, 0, definitionName.impl()));
831  return SchemaElementDefinition(eventDefinition);
832 }
833 
834 inline const char *Service::authorizationServiceName() const
835 {
836  if (!isValid()) {
838  }
839 
841 }
842 
843 inline std::ostream& Service::print(
844  std::ostream& stream, int level, int spacesPerLevel) const
845 {
846  blpapi_Service_print(d_handle,
848  &stream,
849  level,
850  spacesPerLevel);
851  return stream;
852 }
853 
854 inline std::ostream& operator<<(std::ostream& stream, const Service& service)
855 {
856  return service.print(stream, 0, -1);
857 }
858 
859 } // close namespace blpapi
860 } // close namespace BloombergLP
861 
862 #endif // #ifdef __cplusplus
863 #endif // #ifndef INCLUDED_BLPAPI_SERVICE
int blpapi_Service_getEventDefinitionAt(blpapi_Service_t *service, blpapi_SchemaElementDefinition_t **result, size_t index)
const char * description() const
Definition: blpapi_service.h:560
bool hasEventDefinition(const char *name) const
Definition: blpapi_service.h:785
Request createRequest(const char *operation) const
Definition: blpapi_service.h:664
Request createAuthorizationRequest(const char *authorizationOperation=0) const
Definition: blpapi_service.h:672
const char * authorizationServiceName() const
Definition: blpapi_service.h:834
struct blpapi_Request blpapi_Request_t
Definition: blpapi_request.h:67
bool isValid() const
Definition: blpapi_service.h:708
const char * blpapi_Service_name(blpapi_Service_t *service)
struct blpapi_Operation blpapi_Operation_t
Definition: blpapi_types.h:157
Common definitions used by the library.
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition: blpapi_event.h:720
struct blpapi_Event blpapi_Event_t
Definition: blpapi_types.h:139
int blpapi_Operation_numResponseDefinitions(blpapi_Operation_t *operation)
size_t numOperations() const
Definition: blpapi_service.h:728
void blpapi_Service_release(blpapi_Service_t *service)
Definition: blpapi_abstractsession.h:220
int blpapi_Service_createAuthorizationRequest(blpapi_Service_t *service, blpapi_Request_t **request, const char *operation)
Definition: blpapi_name.h:150
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
int blpapi_Operation_responseDefinition(blpapi_Operation_t *operation, blpapi_SchemaElementDefinition_t **responseDefinition, size_t index)
Definition: blpapi_service.h:304
int blpapi_Service_createAdminEvent(blpapi_Service_t *service, blpapi_Event_t **event)
int blpapi_Service_getEventDefinition(blpapi_Service_t *service, blpapi_SchemaElementDefinition_t **result, const char *nameString, const blpapi_Name_t *name)
Definition: blpapi_service.h:313
const char * blpapi_Service_authorizationServiceName(blpapi_Service_t *service)
blpapi_Name_t * impl() const
Definition: blpapi_name.h:403
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
Operation(blpapi_Operation_t *handle)
Definition: blpapi_service.h:544
blpapi_Service_t * handle() const
Definition: blpapi_service.h:706
Definition: blpapi_schema.h:327
blpapi_Operation_t * handle() const
Definition: blpapi_service.h:608
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:53
int blpapi_Service_createPublishEvent(blpapi_Service_t *service, blpapi_Event_t **event)
int blpapi_Service_print(const blpapi_Service_t *service, blpapi_StreamWriter_t streamWriter, void *stream, int level, int spacesPerLevel)
int blpapi_Service_getOperationAt(blpapi_Service_t *service, blpapi_Operation_t **operation, size_t index)
int blpapi_Service_numOperations(blpapi_Service_t *service)
Provide a key to identify individual subscriptions or requests.
Definition: blpapi_request.h:145
struct blpapi_SchemaElementDefinition blpapi_SchemaElementDefinition_t
Definition: blpapi_types.h:191
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
Provide a representation of a schema describing structured messages.
int numResponseDefinitions() const
Definition: blpapi_service.h:578
Defines a request which can be sent for a service.
SchemaElementDefinition getEventDefinition(size_t index) const
Definition: blpapi_service.h:807
SchemaElementDefinition requestDefinition() const
Definition: blpapi_service.h:569
int blpapi_Service_addRef(blpapi_Service_t *service)
Operation getOperation(size_t index) const
Definition: blpapi_service.h:752
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition: blpapi_correlationid.h:592
SchemaElementDefinition responseDefinition(size_t index) const
Definition: blpapi_service.h:587
Definition: blpapi_correlationid.h:201
blpapi_Event_t * createAdminEvent() const
Definition: blpapi_service.h:689
int blpapi_Service_createRequest(blpapi_Service_t *service, blpapi_Request_t **request, const char *operation)
blpapi_Event_t * createPublishEvent() const
Definition: blpapi_service.h:681
Service()
Definition: blpapi_service.h:615
Definition: blpapi_service.h:220
A signature for callback on print and default C++ implementation.
bool isValid() const
Definition: blpapi_service.h:610
const char * blpapi_Service_description(blpapi_Service_t *service)
const char * blpapi_Operation_name(blpapi_Operation_t *operation)
int blpapi_Operation_responseDefinitionFromName(blpapi_Operation_t *operation, blpapi_SchemaElementDefinition_t **responseDefinition, const blpapi_Name_t *name)
Defines Exceptions that can be thrown by the blpapi library.
~Service()
Definition: blpapi_service.h:638
~Operation()
Definition: blpapi_service.h:549
static int writeToStream(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:93
int blpapi_Operation_requestDefinition(blpapi_Operation_t *operation, blpapi_SchemaElementDefinition_t **requestDefinition)
const char * description() const
Definition: blpapi_service.h:719
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
struct blpapi_Service blpapi_Service_t
Definition: blpapi_types.h:166
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_service.h:843
const char * name() const
Definition: blpapi_service.h:551
blpapi_Event_t * createResponseEvent(const CorrelationId &correlationId) const
Definition: blpapi_service.h:697
int blpapi_Service_numEventDefinitions(blpapi_Service_t *service)
int blpapi_Service_createResponseEvent(blpapi_Service_t *service, const blpapi_CorrelationId_t *correlationId, blpapi_Event_t **event)
int blpapi_Service_getOperation(blpapi_Service_t *service, blpapi_Operation_t **operation, const char *nameString, const blpapi_Name_t *name)
Provide BLPAPI types.
#define BLPAPI_ERROR_ILLEGAL_ARG
Definition: blpapi_error.h:67
Service & operator=(const Service &rhs)
Definition: blpapi_service.h:640
const char * name() const
Definition: blpapi_service.h:710
bool hasOperation(const char *name) const
Definition: blpapi_service.h:737
const char * blpapi_Operation_description(blpapi_Operation_t *operation)
int numEventDefinitions() const
Definition: blpapi_service.h:776