BLPAPI C++ 3.26.6
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
175BLPAPI_EXPORT
176int blpapi_Operation_responseDefinition(blpapi_Operation_t *operation,
177 blpapi_SchemaElementDefinition_t **responseDefinition,
178 size_t index);
179
196BLPAPI_EXPORT
197int blpapi_Operation_responseDefinitionFromName(blpapi_Operation_t *operation,
198 blpapi_SchemaElementDefinition_t **responseDefinition,
199 const blpapi_Name_t *name);
200
209BLPAPI_EXPORT
210const char *blpapi_Service_name(blpapi_Service_t *service);
211
221BLPAPI_EXPORT
222const char *blpapi_Service_description(blpapi_Service_t *service);
223
233BLPAPI_EXPORT
234int blpapi_Service_numOperations(blpapi_Service_t *service);
235
245BLPAPI_EXPORT
246int blpapi_Service_numEventDefinitions(blpapi_Service_t *service);
247
259BLPAPI_EXPORT
260int blpapi_Service_addRef(blpapi_Service_t *service);
261
272BLPAPI_EXPORT
273void blpapi_Service_release(blpapi_Service_t *service);
274
285BLPAPI_EXPORT
286const char *blpapi_Service_authorizationServiceName(blpapi_Service_t *service);
287
310BLPAPI_EXPORT
311int blpapi_Service_getOperation(blpapi_Service_t *service,
312 blpapi_Operation_t **operation,
313 const char *nameString,
314 const blpapi_Name_t *name);
315
330BLPAPI_EXPORT
331int blpapi_Service_getOperationAt(blpapi_Service_t *service,
332 blpapi_Operation_t **operation,
333 size_t index);
334
357BLPAPI_EXPORT
358int blpapi_Service_getEventDefinition(blpapi_Service_t *service,
359 blpapi_SchemaElementDefinition_t **result,
360 const char *nameString,
361 const blpapi_Name_t *name);
362
377BLPAPI_EXPORT
378int blpapi_Service_getEventDefinitionAt(blpapi_Service_t *service,
379 blpapi_SchemaElementDefinition_t **result,
380 size_t index);
381
397BLPAPI_EXPORT
398int blpapi_Service_createRequest(blpapi_Service_t *service,
399 blpapi_Request_t **request,
400 const char *operation);
401
419BLPAPI_EXPORT
420int blpapi_Service_createAuthorizationRequest(blpapi_Service_t *service,
421 blpapi_Request_t **request,
422 const char *operation);
423
437BLPAPI_EXPORT
438int blpapi_Service_createPublishEvent(
439 blpapi_Service_t *service, blpapi_Event_t **event);
440
455BLPAPI_EXPORT
456int blpapi_Service_createAdminEvent(
457 blpapi_Service_t *service, blpapi_Event_t **event);
458
474BLPAPI_EXPORT
475int blpapi_Service_createResponseEvent(blpapi_Service_t *service,
476 const blpapi_CorrelationId_t *correlationId,
477 blpapi_Event_t **event);
478
496BLPAPI_EXPORT int blpapi_Service_print(const blpapi_Service_t *service,
497 blpapi_StreamWriter_t streamWriter,
498 void *stream,
499 int level,
500 int spacesPerLevel);
501
504
505#ifdef __cplusplus
506}
507
508#ifndef INCLUDED_BLPAPI_EXCEPTION
509#include <blpapi_exception.h>
510#endif
511
512#include <utility>
513
514namespace BloombergLP {
515namespace blpapi {
522
534
535 blpapi_Operation_t *d_handle;
536
537 public:
538 explicit Operation(blpapi_Operation_t *handle);
539
540 ~Operation();
544
545 const char *name() const;
551
552 const char *description() const;
558
564
565 int numResponseDefinitions() const;
570
576
582
584 blpapi_Operation_t *handle() const;
589
590 bool isValid() const;
595};
596
619class Service {
620
621 blpapi_Service_t *d_handle;
622
623 void addRef();
624 void release();
625
626 public:
627 // PUBLIC TYPES
628 struct TestService { }; // tag type
629
630 // CREATORS
631 Service();
636
637 explicit Service(blpapi_Service_t *handle);
641
642 Service(blpapi_Service_t *handle, TestService tag);
646
647 Service(const Service& original);
651
652 ~Service();
657
658 // MANIPULATORS
659
660 Service& operator=(const Service& rhs);
664
665 // ACCESSORS
666
667 Request createRequest(const char *operation) const;
676
678 const char *authorizationOperation = 0) const;
690
691 blpapi_Event_t *createPublishEvent() const;
696
697 blpapi_Event_t *createAdminEvent() const;
704
705 blpapi_Event_t *createResponseEvent(
706 const CorrelationId& correlationId) const;
711
712 const char *name() const;
718
719 const char *description() const;
725
726 size_t numOperations() const;
730
731 bool hasOperation(const char *name) const;
736
737 bool hasOperation(const Name& name) const;
742
743 Operation getOperation(size_t index) const;
748
749 Operation getOperation(const char *name) const;
757
758 Operation getOperation(const Name& name) const;
764
765 int numEventDefinitions() const;
769
770 bool hasEventDefinition(const char *name) const;
775
776 bool hasEventDefinition(const Name& name) const;
781
788
798
806
807 const char *authorizationServiceName() const;
814
815 bool isValid() const;
820
822 blpapi_Service_t *handle() const;
824
825 std::ostream& print(
826 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
839};
840
843
844// FREE OPERATORS
845std::ostream& operator<<(std::ostream& stream, const Service& service);
857
858// ============================================================================
859// INLINE FUNCTION DEFINITIONS
860// ============================================================================
861
862// ---------------
863// class Operation
864// ---------------
865inline Operation::Operation(blpapi_Operation_t *newHandle)
866 : d_handle(newHandle)
867{
868}
869
871
872inline const char *Operation::name() const
873{
874 if (!isValid()) {
875 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
876 }
877
878 return blpapi_Operation_name(d_handle);
879}
880
881inline const char *Operation::description() const
882{
883 if (!isValid()) {
884 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
885 }
886
887 return blpapi_Operation_description(d_handle);
888}
889
891{
892 blpapi_SchemaElementDefinition_t *definition = 0;
893
895 blpapi_Operation_requestDefinition(d_handle, &definition));
896 return SchemaElementDefinition(definition);
897}
898
900{
901 if (!isValid()) {
902 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
903 }
904
905 return blpapi_Operation_numResponseDefinitions(d_handle);
906}
907
909 size_t index) const
910{
911 blpapi_SchemaElementDefinition_t *definition = 0;
912
914 blpapi_Operation_responseDefinition(d_handle, &definition, index));
915 return SchemaElementDefinition(definition);
916}
917
919 const Name& name) const
920{
921 blpapi_SchemaElementDefinition_t *definition = 0;
922
924 BLPAPI_CALL(blpapi_Operation_responseDefinitionFromName)(
925 d_handle, &definition, name.impl()));
926 return SchemaElementDefinition(definition);
927}
928
930inline blpapi_Operation_t *Operation::handle() const { return d_handle; }
932
933inline bool Operation::isValid() const { return d_handle != 0; }
934// -------------
935// class Service
936// -------------
937
939 : d_handle(0)
940{
941}
942
943inline Service::Service(const Service& original)
944 : d_handle(original.d_handle)
945{
946 addRef();
947}
948
949inline Service::Service(blpapi_Service_t *newHandle)
950 : d_handle(newHandle)
951{
952 addRef();
953}
954
955inline Service::Service(blpapi_Service_t *handle, TestService)
956 : d_handle(handle)
957{
958 // test service de-serialise releases the handle to us
959}
960
961inline Service::~Service() { release(); }
962
964{
965 using std::swap;
966
967 Service tmp(rhs);
968 swap(tmp.d_handle, d_handle);
969
970 return *this;
971}
972
973inline void Service::addRef()
974{
975 if (d_handle) {
976 blpapi_Service_addRef(d_handle);
977 }
978}
979
980inline void Service::release()
981{
982 if (d_handle) {
983 blpapi_Service_release(d_handle);
984 }
985}
986
987inline Request Service::createRequest(const char *operation) const
988{
989 blpapi_Request_t *request = 0;
991 blpapi_Service_createRequest(d_handle, &request, operation));
992 return Request(request);
993}
994
996 const char *authorizationOperation) const
997{
998 blpapi_Request_t *request = 0;
999 ExceptionUtil::throwOnError(blpapi_Service_createAuthorizationRequest(
1000 d_handle, &request, authorizationOperation));
1001 return Request(request);
1002}
1003
1004inline blpapi_Event_t *Service::createPublishEvent() const
1005{
1006 blpapi_Event_t *event = 0;
1008 blpapi_Service_createPublishEvent(d_handle, &event));
1009 return event;
1010}
1011
1012inline blpapi_Event_t *Service::createAdminEvent() const
1013{
1014 blpapi_Event_t *event = 0;
1016 blpapi_Service_createAdminEvent(d_handle, &event));
1017 return event;
1018}
1019
1020inline blpapi_Event_t *Service::createResponseEvent(
1021 const CorrelationId& correlationId) const
1022{
1023 blpapi_Event_t *event = 0;
1024 ExceptionUtil::throwOnError(blpapi_Service_createResponseEvent(
1025 d_handle, &correlationId.impl(), &event));
1026 return event;
1027}
1028
1030inline blpapi_Service_t *Service::handle() const { return d_handle; }
1032
1033inline bool Service::isValid() const { return (d_handle != 0); }
1034
1035inline const char *Service::name() const
1036{
1037 if (!isValid()) {
1038 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1039 }
1040
1041 return blpapi_Service_name(d_handle);
1042}
1043
1044inline const char *Service::description() const
1045{
1046 if (!isValid()) {
1047 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1048 }
1049
1050 return blpapi_Service_description(d_handle);
1051}
1052
1053inline size_t Service::numOperations() const
1054{
1055 if (!isValid()) {
1056 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1057 }
1058
1059 return static_cast<size_t>(blpapi_Service_numOperations(d_handle));
1060}
1061
1062inline bool Service::hasOperation(const char *operationName) const
1063{
1064 blpapi_Operation_t *operation = 0;
1065 return blpapi_Service_getOperation(d_handle, &operation, operationName, 0)
1066 == 0;
1067}
1068
1069inline bool Service::hasOperation(const Name& operationName) const
1070{
1071 blpapi_Operation_t *operation = 0;
1072 return blpapi_Service_getOperation(
1073 d_handle, &operation, 0, operationName.impl())
1074 == 0;
1075}
1076
1077inline Operation Service::getOperation(size_t index) const
1078{
1079 blpapi_Operation_t *operation = 0;
1081 blpapi_Service_getOperationAt(d_handle, &operation, index));
1082 return Operation(operation);
1083}
1084
1085inline Operation Service::getOperation(const char *operationName) const
1086{
1087 blpapi_Operation_t *operation = 0;
1088 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
1089 d_handle, &operation, operationName, 0));
1090 return Operation(operation);
1091}
1092
1093inline Operation Service::getOperation(const Name& operationName) const
1094{
1095 blpapi_Operation_t *operation = 0;
1096 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
1097 d_handle, &operation, 0, operationName.impl()));
1098 return Operation(operation);
1099}
1100
1102{
1103 if (!isValid()) {
1104 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1105 }
1106
1107 return blpapi_Service_numEventDefinitions(d_handle);
1108}
1109
1110inline bool Service::hasEventDefinition(const char *definitionName) const
1111{
1112 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1113
1114 return blpapi_Service_getEventDefinition(
1115 d_handle, &eventDefinition, definitionName, 0)
1116 == 0
1117 ? true
1118 : false;
1119}
1120
1121inline bool Service::hasEventDefinition(const Name& definitionName) const
1122{
1123 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1124
1125 return blpapi_Service_getEventDefinition(
1126 d_handle, &eventDefinition, 0, definitionName.impl())
1127 == 0
1128 ? true
1129 : false;
1130}
1131
1133{
1134 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1135
1136 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinitionAt(
1137 d_handle, &eventDefinition, index));
1138 return SchemaElementDefinition(eventDefinition);
1139}
1140
1142 const char *definitionName) const
1143{
1144 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1145 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
1146 d_handle, &eventDefinition, definitionName, 0));
1147 return SchemaElementDefinition(eventDefinition);
1148}
1149
1151 const Name& definitionName) const
1152{
1153 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
1154 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
1155 d_handle, &eventDefinition, 0, definitionName.impl()));
1156 return SchemaElementDefinition(eventDefinition);
1157}
1158
1159inline const char *Service::authorizationServiceName() const
1160{
1161 if (!isValid()) {
1162 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
1163 }
1164
1165 return blpapi_Service_authorizationServiceName(d_handle);
1166}
1167
1168inline std::ostream& Service::print(
1169 std::ostream& stream, int level, int spacesPerLevel) const
1170{
1171 blpapi_Service_print(d_handle,
1173 &stream,
1174 level,
1175 spacesPerLevel);
1176 return stream;
1177}
1178
1179inline std::ostream& operator<<(std::ostream& stream, const Service& service)
1180{
1181 return service.print(stream, 0, -1);
1182}
1183
1184} // close namespace blpapi
1185} // close namespace BloombergLP
1186
1187#endif // #ifdef __cplusplus
1188#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:306
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_name.h:228
Definition blpapi_service.h:533
~Operation()
Definition blpapi_service.h:870
bool isValid() const
Definition blpapi_service.h:933
Operation(blpapi_Operation_t *handle)
Definition blpapi_service.h:865
const char * name() const
Definition blpapi_service.h:872
const char * description() const
Definition blpapi_service.h:881
SchemaElementDefinition responseDefinition(size_t index) const
Definition blpapi_service.h:908
SchemaElementDefinition requestDefinition() const
Definition blpapi_service.h:890
int numResponseDefinitions() const
Definition blpapi_service.h:899
Definition blpapi_request.h:214
Definition blpapi_schema.h:597
Definition blpapi_service.h:619
int numEventDefinitions() const
Definition blpapi_service.h:1101
blpapi_Event_t * createPublishEvent() const
Definition blpapi_service.h:1004
Service & operator=(const Service &rhs)
Definition blpapi_service.h:963
Request createRequest(const char *operation) const
Definition blpapi_service.h:987
Service()
Definition blpapi_service.h:938
blpapi_Event_t * createResponseEvent(const CorrelationId &correlationId) const
Definition blpapi_service.h:1020
~Service()
Definition blpapi_service.h:961
bool hasOperation(const char *name) const
Definition blpapi_service.h:1062
bool isValid() const
Definition blpapi_service.h:1033
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_service.h:1168
Request createAuthorizationRequest(const char *authorizationOperation=0) const
Definition blpapi_service.h:995
Operation getOperation(size_t index) const
Definition blpapi_service.h:1077
SchemaElementDefinition getEventDefinition(size_t index) const
Definition blpapi_service.h:1132
const char * name() const
Definition blpapi_service.h:1035
size_t numOperations() const
Definition blpapi_service.h:1053
const char * description() const
Definition blpapi_service.h:1044
bool hasEventDefinition(const char *name) const
Definition blpapi_service.h:1110
const char * authorizationServiceName() const
Definition blpapi_service.h:1159
blpapi_Event_t * createAdminEvent() const
Definition blpapi_service.h:1012
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:860
Definition blpapi_abstractsession.h:452
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:761
Definition blpapi_abstractsession.h:451
Definition blpapi_service.h:628
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108