BLPAPI C++ 3.26.7
Loading...
Searching...
No Matches
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
37
38#ifndef INCLUDED_BLPAPI_SERVICE
39#define INCLUDED_BLPAPI_SERVICE
40
74
75#ifndef INCLUDED_BLPAPI_DEFS
76#include <blpapi_defs.h>
77#endif
78
79#ifndef INCLUDED_BLPAPI_TYPES
80#include <blpapi_types.h>
81#endif
82
83#ifndef INCLUDED_BLPAPI_SCHEMA
84#include <blpapi_schema.h>
85#endif
86
87#ifndef INCLUDED_BLPAPI_REQUEST
88#include <blpapi_request.h>
89#endif
90
91#ifndef INCLUDED_BLPAPI_CORRELATIONID
93#endif
94
95#ifndef INCLUDED_BLPAPI_STREAMPROXY
96#include <blpapi_streamproxy.h>
97#endif
98
99#include <stddef.h>
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
106
109
118BLPAPI_EXPORT
119const char *blpapi_Operation_name(blpapi_Operation_t *operation);
120
130BLPAPI_EXPORT
131const char *blpapi_Operation_description(blpapi_Operation_t *operation);
132
145BLPAPI_EXPORT
146int blpapi_Operation_requestDefinition(blpapi_Operation_t *operation,
147 blpapi_SchemaElementDefinition_t **requestDefinition);
148
156BLPAPI_EXPORT
157int blpapi_Operation_numResponseDefinitions(blpapi_Operation_t *operation);
158
174BLPAPI_EXPORT
175int blpapi_Operation_responseDefinition(blpapi_Operation_t *operation,
176 blpapi_SchemaElementDefinition_t **responseDefinition,
177 size_t index);
178
195BLPAPI_EXPORT
196int blpapi_Operation_responseDefinitionFromName(blpapi_Operation_t *operation,
197 blpapi_SchemaElementDefinition_t **responseDefinition,
198 const blpapi_Name_t *name);
199
208BLPAPI_EXPORT
209const char *blpapi_Service_name(blpapi_Service_t *service);
210
220BLPAPI_EXPORT
221const char *blpapi_Service_description(blpapi_Service_t *service);
222
232BLPAPI_EXPORT
233int blpapi_Service_numOperations(blpapi_Service_t *service);
234
244BLPAPI_EXPORT
245int blpapi_Service_numEventDefinitions(blpapi_Service_t *service);
246
258BLPAPI_EXPORT
259int blpapi_Service_addRef(blpapi_Service_t *service);
260
271BLPAPI_EXPORT
272void blpapi_Service_release(blpapi_Service_t *service);
273
284BLPAPI_EXPORT
285const char *blpapi_Service_authorizationServiceName(blpapi_Service_t *service);
286
309BLPAPI_EXPORT
310int blpapi_Service_getOperation(blpapi_Service_t *service,
311 blpapi_Operation_t **operation,
312 const char *nameString,
313 const blpapi_Name_t *name);
314
328BLPAPI_EXPORT
329int blpapi_Service_getOperationAt(blpapi_Service_t *service,
330 blpapi_Operation_t **operation,
331 size_t index);
332
355BLPAPI_EXPORT
356int blpapi_Service_getEventDefinition(blpapi_Service_t *service,
357 blpapi_SchemaElementDefinition_t **result,
358 const char *nameString,
359 const blpapi_Name_t *name);
360
374BLPAPI_EXPORT
375int blpapi_Service_getEventDefinitionAt(blpapi_Service_t *service,
376 blpapi_SchemaElementDefinition_t **result,
377 size_t index);
378
394BLPAPI_EXPORT
395int blpapi_Service_createRequest(blpapi_Service_t *service,
396 blpapi_Request_t **request,
397 const char *operation);
398
416BLPAPI_EXPORT
417int blpapi_Service_createAuthorizationRequest(blpapi_Service_t *service,
418 blpapi_Request_t **request,
419 const char *operation);
420
434BLPAPI_EXPORT
435int blpapi_Service_createPublishEvent(
436 blpapi_Service_t *service, blpapi_Event_t **event);
437
452BLPAPI_EXPORT
453int blpapi_Service_createAdminEvent(
454 blpapi_Service_t *service, blpapi_Event_t **event);
455
471BLPAPI_EXPORT
472int blpapi_Service_createResponseEvent(blpapi_Service_t *service,
473 const blpapi_CorrelationId_t *correlationId,
474 blpapi_Event_t **event);
475
493BLPAPI_EXPORT int blpapi_Service_print(const blpapi_Service_t *service,
494 blpapi_StreamWriter_t streamWriter,
495 void *stream,
496 int level,
497 int spacesPerLevel);
498
501
502#ifdef __cplusplus
503}
504
505#ifndef INCLUDED_BLPAPI_EXCEPTION
506#include <blpapi_exception.h>
507#endif
508
509#include <utility>
510
511namespace BloombergLP {
512namespace blpapi {
519
531
532 blpapi_Operation_t *d_handle;
533
534 public:
535 explicit Operation(blpapi_Operation_t *handle);
536
537 ~Operation();
541
542 const char *name() const;
548
549 const char *description() const;
555
561
562 int numResponseDefinitions() const;
567
573
579
581 blpapi_Operation_t *handle() const;
586
587 bool isValid() const;
592};
593
616class Service {
617
618 blpapi_Service_t *d_handle;
619
620 void addRef();
621 void release();
622
623 public:
624 // PUBLIC TYPES
625 struct TestService { }; // tag type
626
627 // CREATORS
628 Service();
633
634 explicit Service(blpapi_Service_t *handle);
638
639 Service(blpapi_Service_t *handle, TestService tag);
643
644 Service(const Service& original);
648
649 ~Service();
654
655 // MANIPULATORS
656
657 Service& operator=(const Service& rhs);
661
662 // ACCESSORS
663
664 Request createRequest(const char *operation) const;
673
675 const char *authorizationOperation = 0) const;
687
688 blpapi_Event_t *createPublishEvent() const;
693
694 blpapi_Event_t *createAdminEvent() const;
701
702 blpapi_Event_t *createResponseEvent(
703 const CorrelationId& correlationId) const;
708
709 const char *name() const;
715
716 const char *description() const;
722
723 size_t numOperations() const;
727
728 bool hasOperation(const char *name) const;
733
734 bool hasOperation(const Name& name) const;
739
740 Operation getOperation(size_t index) const;
745
746 Operation getOperation(const char *name) const;
754
755 Operation getOperation(const Name& name) const;
761
762 int numEventDefinitions() const;
766
767 bool hasEventDefinition(const char *name) const;
772
773 bool hasEventDefinition(const Name& name) const;
778
785
795
803
804 const char *authorizationServiceName() const;
811
812 bool isValid() const;
817
819 blpapi_Service_t *handle() const;
821
822 std::ostream& print(
823 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
836};
837
840
841// FREE OPERATORS
842std::ostream& operator<<(std::ostream& stream, const Service& service);
854
855// ============================================================================
856// INLINE FUNCTION DEFINITIONS
857// ============================================================================
858
859// ---------------
860// class Operation
861// ---------------
862inline Operation::Operation(blpapi_Operation_t *newHandle)
863 : d_handle(newHandle)
864{
865}
866
868
869inline const char *Operation::name() const
870{
871 if (!isValid()) {
872 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
873 }
874
875 return blpapi_Operation_name(d_handle);
876}
877
878inline const char *Operation::description() const
879{
880 if (!isValid()) {
881 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
882 }
883
884 return blpapi_Operation_description(d_handle);
885}
886
888{
889 blpapi_SchemaElementDefinition_t *definition = 0;
890
892 blpapi_Operation_requestDefinition(d_handle, &definition));
893 return SchemaElementDefinition(definition);
894}
895
897{
898 if (!isValid()) {
899 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
900 }
901
902 return blpapi_Operation_numResponseDefinitions(d_handle);
903}
904
906 size_t index) const
907{
908 blpapi_SchemaElementDefinition_t *definition = 0;
909
911 blpapi_Operation_responseDefinition(d_handle, &definition, index));
912 return SchemaElementDefinition(definition);
913}
914
916 const Name& name) const
917{
918 blpapi_SchemaElementDefinition_t *definition = 0;
919
921 BLPAPI_CALL(blpapi_Operation_responseDefinitionFromName)(
922 d_handle, &definition, name.impl()));
923 return SchemaElementDefinition(definition);
924}
925
927inline blpapi_Operation_t *Operation::handle() const { return d_handle; }
929
930inline bool Operation::isValid() const { return d_handle != 0; }
931// -------------
932// class Service
933// -------------
934
936 : d_handle(0)
937{
938}
939
940inline Service::Service(const Service& original)
941 : d_handle(original.d_handle)
942{
943 addRef();
944}
945
946inline Service::Service(blpapi_Service_t *newHandle)
947 : d_handle(newHandle)
948{
949 addRef();
950}
951
952inline Service::Service(blpapi_Service_t *handle, TestService)
953 : d_handle(handle)
954{
955 // test service de-serialise releases the handle to us
956}
957
958inline Service::~Service() { release(); }
959
961{
962 using std::swap;
963
964 Service tmp(rhs);
965 swap(tmp.d_handle, d_handle);
966
967 return *this;
968}
969
970inline void Service::addRef()
971{
972 if (d_handle) {
973 blpapi_Service_addRef(d_handle);
974 }
975}
976
977inline void Service::release()
978{
979 if (d_handle) {
980 blpapi_Service_release(d_handle);
981 }
982}
983
984inline Request Service::createRequest(const char *operation) const
985{
986 blpapi_Request_t *request = 0;
988 blpapi_Service_createRequest(d_handle, &request, operation));
989 return Request(request);
990}
991
993 const char *authorizationOperation) const
994{
995 blpapi_Request_t *request = 0;
996 ExceptionUtil::throwOnError(blpapi_Service_createAuthorizationRequest(
997 d_handle, &request, authorizationOperation));
998 return Request(request);
999}
1000
1001inline blpapi_Event_t *Service::createPublishEvent() const
1002{
1003 blpapi_Event_t *event = 0;
1005 blpapi_Service_createPublishEvent(d_handle, &event));
1006 return event;
1007}
1008
1009inline blpapi_Event_t *Service::createAdminEvent() const
1010{
1011 blpapi_Event_t *event = 0;
1013 blpapi_Service_createAdminEvent(d_handle, &event));
1014 return event;
1015}
1016
1017inline blpapi_Event_t *Service::createResponseEvent(
1018 const CorrelationId& correlationId) const
1019{
1020 blpapi_Event_t *event = 0;
1021 ExceptionUtil::throwOnError(blpapi_Service_createResponseEvent(
1022 d_handle, &correlationId.impl(), &event));
1023 return event;
1024}
1025
1027inline blpapi_Service_t *Service::handle() const { return d_handle; }
1029
1030inline bool Service::isValid() const { return (d_handle != 0); }
1031
1032inline const char *Service::name() const
1033{
1034 if (!isValid()) {
1035 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1036 }
1037
1038 return blpapi_Service_name(d_handle);
1039}
1040
1041inline const char *Service::description() const
1042{
1043 if (!isValid()) {
1044 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1045 }
1046
1047 return blpapi_Service_description(d_handle);
1048}
1049
1050inline size_t Service::numOperations() const
1051{
1052 if (!isValid()) {
1053 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1054 }
1055
1056 return static_cast<size_t>(blpapi_Service_numOperations(d_handle));
1057}
1058
1059inline bool Service::hasOperation(const char *operationName) const
1060{
1061 blpapi_Operation_t *operation = 0;
1062 return blpapi_Service_getOperation(d_handle, &operation, operationName, 0)
1063 == 0;
1064}
1065
1066inline bool Service::hasOperation(const Name& operationName) const
1067{
1068 blpapi_Operation_t *operation = 0;
1069 return blpapi_Service_getOperation(
1070 d_handle, &operation, 0, operationName.impl())
1071 == 0;
1072}
1073
1074inline Operation Service::getOperation(size_t index) const
1075{
1076 blpapi_Operation_t *operation = 0;
1078 blpapi_Service_getOperationAt(d_handle, &operation, index));
1079 return Operation(operation);
1080}
1081
1082inline Operation Service::getOperation(const char *operationName) const
1083{
1084 blpapi_Operation_t *operation = 0;
1085 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
1086 d_handle, &operation, operationName, 0));
1087 return Operation(operation);
1088}
1089
1090inline Operation Service::getOperation(const Name& operationName) const
1091{
1092 blpapi_Operation_t *operation = 0;
1093 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
1094 d_handle, &operation, 0, operationName.impl()));
1095 return Operation(operation);
1096}
1097
1099{
1100 if (!isValid()) {
1101 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1102 }
1103
1104 return blpapi_Service_numEventDefinitions(d_handle);
1105}
1106
1107inline bool Service::hasEventDefinition(const char *definitionName) const
1108{
1109 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1110
1111 return blpapi_Service_getEventDefinition(
1112 d_handle, &eventDefinition, definitionName, 0)
1113 == 0
1114 ? true
1115 : false;
1116}
1117
1118inline bool Service::hasEventDefinition(const Name& definitionName) const
1119{
1120 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1121
1122 return blpapi_Service_getEventDefinition(
1123 d_handle, &eventDefinition, 0, definitionName.impl())
1124 == 0
1125 ? true
1126 : false;
1127}
1128
1130{
1131 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1132
1133 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinitionAt(
1134 d_handle, &eventDefinition, index));
1135 return SchemaElementDefinition(eventDefinition);
1136}
1137
1139 const char *definitionName) const
1140{
1141 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1142 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
1143 d_handle, &eventDefinition, definitionName, 0));
1144 return SchemaElementDefinition(eventDefinition);
1145}
1146
1148 const Name& definitionName) const
1149{
1150 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1151 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
1152 d_handle, &eventDefinition, 0, definitionName.impl()));
1153 return SchemaElementDefinition(eventDefinition);
1154}
1155
1156inline const char *Service::authorizationServiceName() const
1157{
1158 if (!isValid()) {
1159 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1160 }
1161
1162 return blpapi_Service_authorizationServiceName(d_handle);
1163}
1164
1165inline std::ostream& Service::print(
1166 std::ostream& stream, int level, int spacesPerLevel) const
1167{
1168 blpapi_Service_print(d_handle,
1170 &stream,
1171 level,
1172 spacesPerLevel);
1173 return stream;
1174}
1175
1176inline std::ostream& operator<<(std::ostream& stream, const Service& service)
1177{
1178 return service.print(stream, 0, -1);
1179}
1180
1181} // close namespace blpapi
1182} // close namespace BloombergLP
1183
1184#endif // #ifdef __cplusplus
1185#endif // #ifndef INCLUDED_BLPAPI_SERVICE
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Defines a request which can be sent for a service.
Provide a representation of a schema describing structured messages.
A signature for callback on print and default C++ implementation.
Provide BLPAPI types.
Definition blpapi_correlationid.h:322
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_name.h:228
Definition blpapi_service.h:530
~Operation()
Definition blpapi_service.h:867
bool isValid() const
Definition blpapi_service.h:930
Operation(blpapi_Operation_t *handle)
Definition blpapi_service.h:862
const char * name() const
Definition blpapi_service.h:869
const char * description() const
Definition blpapi_service.h:878
SchemaElementDefinition responseDefinition(size_t index) const
Definition blpapi_service.h:905
SchemaElementDefinition requestDefinition() const
Definition blpapi_service.h:887
int numResponseDefinitions() const
Definition blpapi_service.h:896
Definition blpapi_request.h:214
Definition blpapi_schema.h:597
Definition blpapi_service.h:616
int numEventDefinitions() const
Definition blpapi_service.h:1098
blpapi_Event_t * createPublishEvent() const
Definition blpapi_service.h:1001
Service & operator=(const Service &rhs)
Definition blpapi_service.h:960
Request createRequest(const char *operation) const
Definition blpapi_service.h:984
Service()
Definition blpapi_service.h:935
blpapi_Event_t * createResponseEvent(const CorrelationId &correlationId) const
Definition blpapi_service.h:1017
~Service()
Definition blpapi_service.h:958
bool hasOperation(const char *name) const
Definition blpapi_service.h:1059
bool isValid() const
Definition blpapi_service.h:1030
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_service.h:1165
Request createAuthorizationRequest(const char *authorizationOperation=0) const
Definition blpapi_service.h:992
Operation getOperation(size_t index) const
Definition blpapi_service.h:1074
SchemaElementDefinition getEventDefinition(size_t index) const
Definition blpapi_service.h:1129
const char * name() const
Definition blpapi_service.h:1032
size_t numOperations() const
Definition blpapi_service.h:1050
const char * description() const
Definition blpapi_service.h:1041
bool hasEventDefinition(const char *name) const
Definition blpapi_service.h:1107
const char * authorizationServiceName() const
Definition blpapi_service.h:1156
blpapi_Event_t * createAdminEvent() const
Definition blpapi_service.h:1009
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:916
Definition blpapi_abstractsession.h:448
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:792
Definition blpapi_abstractsession.h:447
Definition blpapi_service.h:625
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108