BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_SERVICE
37#define INCLUDED_BLPAPI_SERVICE
38
73
74#ifndef INCLUDED_BLPAPI_DEFS
75#include <blpapi_defs.h>
76#endif
77
78#ifndef INCLUDED_BLPAPI_TYPES
79#include <blpapi_types.h>
80#endif
81
82#ifndef INCLUDED_BLPAPI_SCHEMA
83#include <blpapi_schema.h>
84#endif
85
86#ifndef INCLUDED_BLPAPI_REQUEST
87#include <blpapi_request.h>
88#endif
89
90#ifndef INCLUDED_BLPAPI_CORRELATIONID
92#endif
93
94#ifndef INCLUDED_BLPAPI_STREAMPROXY
95#include <blpapi_streamproxy.h>
96#endif
97
98#include <stddef.h>
99
100#ifdef __cplusplus
101extern "C" {
102#endif
103
105
108
109BLPAPI_EXPORT
110const char *blpapi_Operation_name(blpapi_Operation_t *operation);
111
112BLPAPI_EXPORT
113const char *blpapi_Operation_description(blpapi_Operation_t *operation);
114
115BLPAPI_EXPORT
116int blpapi_Operation_requestDefinition(blpapi_Operation_t *operation,
117 blpapi_SchemaElementDefinition_t **requestDefinition);
118
119BLPAPI_EXPORT
120int blpapi_Operation_numResponseDefinitions(blpapi_Operation_t *operation);
121
122BLPAPI_EXPORT
123int blpapi_Operation_responseDefinition(blpapi_Operation_t *operation,
124 blpapi_SchemaElementDefinition_t **responseDefinition,
125 size_t index);
126
127BLPAPI_EXPORT
128int blpapi_Operation_responseDefinitionFromName(blpapi_Operation_t *operation,
129 blpapi_SchemaElementDefinition_t **responseDefinition,
130 const blpapi_Name_t *name);
131
132BLPAPI_EXPORT
133const char *blpapi_Service_name(blpapi_Service_t *service);
134
135BLPAPI_EXPORT
136const char *blpapi_Service_description(blpapi_Service_t *service);
137
138BLPAPI_EXPORT
139int blpapi_Service_numOperations(blpapi_Service_t *service);
140
141BLPAPI_EXPORT
142int blpapi_Service_numEventDefinitions(blpapi_Service_t *service);
143
144BLPAPI_EXPORT
145int blpapi_Service_addRef(blpapi_Service_t *service);
146
147BLPAPI_EXPORT
148void blpapi_Service_release(blpapi_Service_t *service);
149
150BLPAPI_EXPORT
151const char *blpapi_Service_authorizationServiceName(blpapi_Service_t *service);
152
153BLPAPI_EXPORT
154int blpapi_Service_getOperation(blpapi_Service_t *service,
155 blpapi_Operation_t **operation,
156 const char *nameString,
157 const blpapi_Name_t *name);
158
159BLPAPI_EXPORT
160int blpapi_Service_getOperationAt(blpapi_Service_t *service,
161 blpapi_Operation_t **operation,
162 size_t index);
163
164BLPAPI_EXPORT
165int blpapi_Service_getEventDefinition(blpapi_Service_t *service,
166 blpapi_SchemaElementDefinition_t **result,
167 const char *nameString,
168 const blpapi_Name_t *name);
169
170BLPAPI_EXPORT
171int blpapi_Service_getEventDefinitionAt(blpapi_Service_t *service,
172 blpapi_SchemaElementDefinition_t **result,
173 size_t index);
174
175BLPAPI_EXPORT
176int blpapi_Service_createRequest(blpapi_Service_t *service,
177 blpapi_Request_t **request,
178 const char *operation);
179
180BLPAPI_EXPORT
181int blpapi_Service_createAuthorizationRequest(blpapi_Service_t *service,
182 blpapi_Request_t **request,
183 const char *operation);
184
185BLPAPI_EXPORT
186int blpapi_Service_createPublishEvent(
187 blpapi_Service_t *service, blpapi_Event_t **event);
188
189BLPAPI_EXPORT
190int blpapi_Service_createAdminEvent(
191 blpapi_Service_t *service, blpapi_Event_t **event);
192
193BLPAPI_EXPORT
194int blpapi_Service_createResponseEvent(blpapi_Service_t *service,
195 const blpapi_CorrelationId_t *correlationId,
196 blpapi_Event_t **event);
197
198BLPAPI_EXPORT int blpapi_Service_print(const blpapi_Service_t *service,
199 blpapi_StreamWriter_t streamWriter,
200 void *stream,
201 int level,
202 int spacesPerLevel);
203
206
207#ifdef __cplusplus
208}
209
210#ifndef INCLUDED_BLPAPI_EXCEPTION
211#include <blpapi_exception.h>
212#endif
213
214#include <utility>
215
222
223namespace BloombergLP {
224namespace blpapi {
225
237
238 blpapi_Operation_t *d_handle;
239
240 public:
241 explicit Operation(blpapi_Operation_t *handle);
242
243 ~Operation();
247
248 const char *name() const;
254
255 const char *description() const;
261
267
268 int numResponseDefinitions() const;
273
279
285
286 blpapi_Operation_t *handle() const;
290
291 bool isValid() const;
296};
297
320class Service {
321
322 blpapi_Service_t *d_handle;
323
324 void addRef();
325 void release();
326
327 public:
328 // PUBLIC TYPES
329 struct TestService { }; // tag type
330
331 // CREATORS
332 Service();
337
338 explicit Service(blpapi_Service_t *handle);
342
343 Service(blpapi_Service_t *handle, TestService tag);
347
348 Service(const Service& original);
352
353 ~Service();
358
359 // MANIPULATORS
360
361 Service& operator=(const Service& rhs);
365
366 // ACCESSORS
367
368 Request createRequest(const char *operation) const;
377
379 const char *authorizationOperation = 0) const;
391
392 blpapi_Event_t *createPublishEvent() const;
397
398 blpapi_Event_t *createAdminEvent() const;
405
406 blpapi_Event_t *createResponseEvent(
407 const CorrelationId& correlationId) const;
412
413 const char *name() const;
419
420 const char *description() const;
426
427 size_t numOperations() const;
431
432 bool hasOperation(const char *name) const;
437
438 bool hasOperation(const Name& name) const;
443
444 Operation getOperation(size_t index) const;
449
450 Operation getOperation(const char *name) const;
456
457 Operation getOperation(const Name& name) const;
463
464 int numEventDefinitions() const;
468
469 bool hasEventDefinition(const char *name) const;
474
475 bool hasEventDefinition(const Name& name) const;
480
487
495
503
504 const char *authorizationServiceName() const;
511
512 bool isValid() const;
517
518 blpapi_Service_t *handle() const;
519
520 std::ostream& print(
521 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
534};
535
538
539// FREE OPERATORS
540std::ostream& operator<<(std::ostream& stream, const Service& service);
552
553// ============================================================================
554// INLINE FUNCTION DEFINITIONS
555// ============================================================================
556
557// ---------------
558// class Operation
559// ---------------
560inline Operation::Operation(blpapi_Operation_t *newHandle)
561 : d_handle(newHandle)
562{
563}
564
566
567inline const char *Operation::name() const
568{
569 if (!isValid()) {
570 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
571 }
572
573 return blpapi_Operation_name(d_handle);
574}
575
576inline const char *Operation::description() const
577{
578 if (!isValid()) {
579 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
580 }
581
582 return blpapi_Operation_description(d_handle);
583}
584
586{
587 blpapi_SchemaElementDefinition_t *definition = 0;
588
590 blpapi_Operation_requestDefinition(d_handle, &definition));
591 return SchemaElementDefinition(definition);
592}
593
595{
596 if (!isValid()) {
597 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
598 }
599
600 return blpapi_Operation_numResponseDefinitions(d_handle);
601}
602
604 size_t index) const
605{
606 blpapi_SchemaElementDefinition_t *definition = 0;
607
609 blpapi_Operation_responseDefinition(d_handle, &definition, index));
610 return SchemaElementDefinition(definition);
611}
612
614 const Name& name) const
615{
616 blpapi_SchemaElementDefinition_t *definition = 0;
617
619 BLPAPI_CALL(blpapi_Operation_responseDefinitionFromName)(
620 d_handle, &definition, name.impl()));
621 return SchemaElementDefinition(definition);
622}
623
624inline blpapi_Operation_t *Operation::handle() const { return d_handle; }
625
626inline bool Operation::isValid() const { return d_handle != 0; }
627// -------------
628// class Service
629// -------------
630
632 : d_handle(0)
633{
634}
635
636inline Service::Service(const Service& original)
637 : d_handle(original.d_handle)
638{
639 addRef();
640}
641
642inline Service::Service(blpapi_Service_t *newHandle)
643 : d_handle(newHandle)
644{
645 addRef();
646}
647
648inline Service::Service(blpapi_Service_t *handle, TestService)
649 : d_handle(handle)
650{
651 // test service de-serialise releases the handle to us
652}
653
654inline Service::~Service() { release(); }
655
657{
658 using std::swap;
659
660 Service tmp(rhs);
661 swap(tmp.d_handle, d_handle);
662
663 return *this;
664}
665
666inline void Service::addRef()
667{
668 if (d_handle) {
669 blpapi_Service_addRef(d_handle);
670 }
671}
672
673inline void Service::release()
674{
675 if (d_handle) {
676 blpapi_Service_release(d_handle);
677 }
678}
679
680inline Request Service::createRequest(const char *operation) const
681{
682 blpapi_Request_t *request = 0;
684 blpapi_Service_createRequest(d_handle, &request, operation));
685 return Request(request);
686}
687
689 const char *authorizationOperation) const
690{
691 blpapi_Request_t *request = 0;
692 ExceptionUtil::throwOnError(blpapi_Service_createAuthorizationRequest(
693 d_handle, &request, authorizationOperation));
694 return Request(request);
695}
696
697inline blpapi_Event_t *Service::createPublishEvent() const
698{
699 blpapi_Event_t *event = 0;
701 blpapi_Service_createPublishEvent(d_handle, &event));
702 return event;
703}
704
705inline blpapi_Event_t *Service::createAdminEvent() const
706{
707 blpapi_Event_t *event = 0;
709 blpapi_Service_createAdminEvent(d_handle, &event));
710 return event;
711}
712
713inline blpapi_Event_t *Service::createResponseEvent(
714 const CorrelationId& correlationId) const
715{
716 blpapi_Event_t *event = 0;
717 ExceptionUtil::throwOnError(blpapi_Service_createResponseEvent(
718 d_handle, &correlationId.impl(), &event));
719 return event;
720}
721
722inline blpapi_Service_t *Service::handle() const { return d_handle; }
723
724inline bool Service::isValid() const { return (d_handle != 0); }
725
726inline const char *Service::name() const
727{
728 if (!isValid()) {
729 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
730 }
731
732 return blpapi_Service_name(d_handle);
733}
734
735inline const char *Service::description() const
736{
737 if (!isValid()) {
738 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
739 }
740
741 return blpapi_Service_description(d_handle);
742}
743
744inline size_t Service::numOperations() const
745{
746 if (!isValid()) {
747 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
748 }
749
750 return static_cast<size_t>(blpapi_Service_numOperations(d_handle));
751}
752
753inline bool Service::hasOperation(const char *operationName) const
754{
755 blpapi_Operation_t *operation = 0;
756 return blpapi_Service_getOperation(d_handle, &operation, operationName, 0)
757 == 0;
758}
759
760inline bool Service::hasOperation(const Name& operationName) const
761{
762 blpapi_Operation_t *operation = 0;
763 return blpapi_Service_getOperation(
764 d_handle, &operation, 0, operationName.impl())
765 == 0;
766}
767
768inline Operation Service::getOperation(size_t index) const
769{
770 blpapi_Operation_t *operation = 0;
772 blpapi_Service_getOperationAt(d_handle, &operation, index));
773 return Operation(operation);
774}
775
776inline Operation Service::getOperation(const char *operationName) const
777{
778 blpapi_Operation_t *operation = 0;
779 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
780 d_handle, &operation, operationName, 0));
781 return Operation(operation);
782}
783
784inline Operation Service::getOperation(const Name& operationName) const
785{
786 blpapi_Operation_t *operation = 0;
787 ExceptionUtil::throwOnError(blpapi_Service_getOperation(
788 d_handle, &operation, 0, operationName.impl()));
789 return Operation(operation);
790}
791
793{
794 if (!isValid()) {
795 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
796 }
797
798 return blpapi_Service_numEventDefinitions(d_handle);
799}
800
801inline bool Service::hasEventDefinition(const char *definitionName) const
802{
803 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
804
805 return blpapi_Service_getEventDefinition(
806 d_handle, &eventDefinition, definitionName, 0)
807 == 0
808 ? true
809 : false;
810}
811
812inline bool Service::hasEventDefinition(const Name& definitionName) const
813{
814 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
815
816 return blpapi_Service_getEventDefinition(
817 d_handle, &eventDefinition, 0, definitionName.impl())
818 == 0
819 ? true
820 : false;
821}
822
824{
825 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
826
827 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinitionAt(
828 d_handle, &eventDefinition, index));
829 return SchemaElementDefinition(eventDefinition);
830}
831
833 const char *definitionName) const
834{
835 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
836 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
837 d_handle, &eventDefinition, definitionName, 0));
838 return SchemaElementDefinition(eventDefinition);
839}
840
842 const Name& definitionName) const
843{
844 blpapi_SchemaElementDefinition_t *eventDefinition = 0;
845 ExceptionUtil::throwOnError(blpapi_Service_getEventDefinition(
846 d_handle, &eventDefinition, 0, definitionName.impl()));
847 return SchemaElementDefinition(eventDefinition);
848}
849
850inline const char *Service::authorizationServiceName() const
851{
852 if (!isValid()) {
853 ExceptionUtil::throwOnError(BLPAPI_ERROR_ILLEGAL_ARG);
854 }
855
856 return blpapi_Service_authorizationServiceName(d_handle);
857}
858
859inline std::ostream& Service::print(
860 std::ostream& stream, int level, int spacesPerLevel) const
861{
862 blpapi_Service_print(d_handle,
864 &stream,
865 level,
866 spacesPerLevel);
867 return stream;
868}
869
870inline std::ostream& operator<<(std::ostream& stream, const Service& service)
871{
872 return service.print(stream, 0, -1);
873}
874
875} // close namespace blpapi
876} // close namespace BloombergLP
877
878#endif // #ifdef __cplusplus
879#endif // #ifndef INCLUDED_BLPAPI_SERVICE
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
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:225
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Definition blpapi_name.h:242
blpapi_Name_t * impl() const
Definition blpapi_name.h:495
Definition blpapi_service.h:236
~Operation()
Definition blpapi_service.h:565
bool isValid() const
Definition blpapi_service.h:626
Operation(blpapi_Operation_t *handle)
Definition blpapi_service.h:560
const char * name() const
Definition blpapi_service.h:567
const char * description() const
Definition blpapi_service.h:576
SchemaElementDefinition responseDefinition(size_t index) const
Definition blpapi_service.h:603
SchemaElementDefinition requestDefinition() const
Definition blpapi_service.h:585
blpapi_Operation_t * handle() const
Definition blpapi_service.h:624
int numResponseDefinitions() const
Definition blpapi_service.h:594
Definition blpapi_request.h:163
Definition blpapi_schema.h:342
Definition blpapi_service.h:320
int numEventDefinitions() const
Definition blpapi_service.h:792
blpapi_Event_t * createPublishEvent() const
Definition blpapi_service.h:697
Service & operator=(const Service &rhs)
Definition blpapi_service.h:656
Request createRequest(const char *operation) const
Definition blpapi_service.h:680
Service()
Definition blpapi_service.h:631
blpapi_Event_t * createResponseEvent(const CorrelationId &correlationId) const
Definition blpapi_service.h:713
~Service()
Definition blpapi_service.h:654
bool hasOperation(const char *name) const
Definition blpapi_service.h:753
bool isValid() const
Definition blpapi_service.h:724
blpapi_Service_t * handle() const
Definition blpapi_service.h:722
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_service.h:859
Request createAuthorizationRequest(const char *authorizationOperation=0) const
Definition blpapi_service.h:688
Operation getOperation(size_t index) const
Definition blpapi_service.h:768
SchemaElementDefinition getEventDefinition(size_t index) const
Definition blpapi_service.h:823
const char * name() const
Definition blpapi_service.h:726
size_t numOperations() const
Definition blpapi_service.h:744
const char * description() const
Definition blpapi_service.h:735
bool hasEventDefinition(const char *name) const
Definition blpapi_service.h:801
const char * authorizationServiceName() const
Definition blpapi_service.h:850
blpapi_Event_t * createAdminEvent() const
Definition blpapi_service.h:705
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition blpapi_event.h:739
Definition blpapi_abstractsession.h:212
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:680
Definition blpapi_abstractsession.h:211
Definition blpapi_service.h:329
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:109