BLPAPI C++ 3.26.7
Loading...
Searching...
No Matches
blpapi_abstractsession.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_ABSTRACTSESSION
39#define INCLUDED_BLPAPI_ABSTRACTSESSION
40
80
81#include <blpapi_authoptions.h>
82#include <blpapi_call.h>
84#include <blpapi_defs.h>
85#include <blpapi_deprecate.h>
86#include <blpapi_event.h>
88#include <blpapi_exception.h>
89#include <blpapi_identity.h>
90#include <blpapi_request.h>
91#include <blpapi_service.h>
92#include <blpapi_types.h>
94
95#ifdef __cplusplus
96extern "C" {
97#endif
98
100
103
104// All of the blpapi_UserHandle_* functions have been deprecated. Please use
105// blpapi_Identity_* versions of these functions instead.
106
115BLPAPI_EXPORT
116void blpapi_UserHandle_release(blpapi_UserHandle_t *handle);
117
129BLPAPI_EXPORT
130int blpapi_UserHandle_addRef(blpapi_UserHandle_t *handle);
131
155BLPAPI_EXPORT
156int blpapi_UserHandle_hasEntitlements(const blpapi_UserHandle_t *handle,
157 const blpapi_Service_t *service,
158 const blpapi_Element_t *eidElement,
159 const int *entitlementIds,
160 size_t numEntitlements,
161 int *failedEntitlements,
162 int *failedEntitlementsCount);
163
182BLPAPI_EXPORT
183int blpapi_AbstractSession_cancel(blpapi_AbstractSession_t *session,
184 const blpapi_CorrelationId_t *correlationIds,
185 size_t numCorrelationIds,
186 const char *requestLabel,
187 int requestLabelLen);
188
211BLPAPI_EXPORT
212int blpapi_AbstractSession_sendAuthorizationRequest(
213 blpapi_AbstractSession_t *session,
214 const blpapi_Request_t *request,
215 blpapi_Identity_t *identity,
216 blpapi_CorrelationId_t *correlationId,
217 blpapi_EventQueue_t *eventQueue,
218 const char *requestLabel,
219 int requestLabelLen);
220
234BLPAPI_EXPORT
235int blpapi_AbstractSession_openService(
236 blpapi_AbstractSession_t *session, const char *serviceIdentifier);
237
252BLPAPI_EXPORT
253int blpapi_AbstractSession_openServiceAsync(blpapi_AbstractSession_t *session,
254 const char *serviceIdentifier,
255 blpapi_CorrelationId_t *correlationId);
256
271BLPAPI_EXPORT
272int blpapi_AbstractSession_generateToken(blpapi_AbstractSession_t *session,
273 blpapi_CorrelationId_t *correlationId,
274 blpapi_EventQueue_t *eventQueue);
275
295BLPAPI_EXPORT
296int blpapi_AbstractSession_generateManualToken(
297 blpapi_AbstractSession_t *session,
298 blpapi_CorrelationId_t *correlationId,
299 const char *user,
300 const char *manualIp,
301 blpapi_EventQueue_t *eventQueue);
302
317BLPAPI_EXPORT
318int blpapi_AbstractSession_getService(blpapi_AbstractSession_t *session,
319 blpapi_Service_t **service,
320 const char *serviceIdentifier);
321
337BLPAPI_EXPORT
338blpapi_Identity_t *blpapi_AbstractSession_createIdentity(
339 blpapi_AbstractSession_t *session);
340
359BLPAPI_EXPORT
360int blpapi_AbstractSession_generateAuthorizedIdentityAsync(
361 blpapi_AbstractSession_t *session,
362 const blpapi_AuthOptions_t *authOptions,
363 blpapi_CorrelationId_t *cid);
364
382BLPAPI_EXPORT
383int blpapi_AbstractSession_getAuthorizedIdentity(
384 blpapi_AbstractSession_t *session,
385 const blpapi_CorrelationId_t *cid,
386 blpapi_Identity_t **identity);
387
403BLPAPI_EXPORT
404int blpapi_AbstractSession_sessionName(blpapi_AbstractSession_t *session,
405 const char **sessionName,
406 size_t *size);
407
418BLPAPI_EXPORT
419int blpapi_UserAgentInfo_setUserTaskName(const char *userTaskName);
420
434BLPAPI_EXPORT
435int blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion(
436 const char *language, const char *version);
437
440
441#ifdef __cplusplus
442}
443
444#include <cassert>
445#include <vector>
446
447namespace BloombergLP {
448namespace blpapi {
455
457
458// =====================
459// class AbstractSession
460// =====================
461
519class AbstractSession {
520
521 blpapi_AbstractSession_t *d_handle_p;
522
523 private:
524 // NOT IMPLEMENTED
525 AbstractSession(const AbstractSession&);
526 AbstractSession& operator=(const AbstractSession&);
527
528 protected:
530 AbstractSession();
534
535 void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
540
541 public:
542 virtual ~AbstractSession();
546
547 // MANIPULATORS
548 virtual bool start() = 0;
559
560 virtual bool startAsync() = 0;
571
572 virtual void stop() = 0;
583
584 virtual void stopAsync() = 0;
595
596 virtual Event nextEvent(int timeout = 0) = 0;
611
612 virtual int tryNextEvent(Event *event) = 0;
619
620 virtual bool openService(const char *serviceIdentifier);
637
638 virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
639 const CorrelationId& correlationId = CorrelationId());
655
657 const Request& authorizationRequest,
658 Identity *identity,
659 const CorrelationId& correlationId = CorrelationId(),
660 EventQueue *eventQueue = 0);
687
688 virtual void cancel(const CorrelationId& correlationId);
706
707 virtual void cancel(const std::vector<CorrelationId>& correlationIds);
727
728 virtual void cancel(
729 const CorrelationId *correlationIds, size_t numCorrelationIds);
749
751 const CorrelationId& correlationId = CorrelationId(),
752 EventQueue *eventQueue = 0);
764
765 virtual CorrelationId generateToken(const char *userId,
766 const char *ipAddress,
767 const CorrelationId& correlationId = CorrelationId(),
768 EventQueue *eventQueue = 0);
778
779 virtual Service getService(const char *serviceIdentifier) const;
792
793 virtual Identity createIdentity();
798
800 const CorrelationId& cid = CorrelationId());
817
819 const CorrelationId& correlationId = CorrelationId());
830
831 std::string sessionName();
835
837 blpapi_AbstractSession_t *abstractSessionHandle() const;
842
844 BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle
852};
853
856
857//=============================================================================
858// INLINE FUNCTION DEFINITIONS
859//=============================================================================
860
861// ---------------------
862// class AbstractSession
863// ---------------------
864
865inline AbstractSession::AbstractSession()
866 : d_handle_p(0)
867{
868 // Ignore the return value
869 BLPAPI_CALL(blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion)
871}
872
874
876inline void AbstractSession::initAbstractSessionHandle(
877 blpapi_AbstractSession_t *handle)
878{
879 d_handle_p = handle;
880}
882
883inline Service AbstractSession::getService(const char *serviceIdentifier) const
884{
885 blpapi_Service_t *service;
886 ExceptionUtil::throwOnError(blpapi_AbstractSession_getService(
887 d_handle_p, &service, serviceIdentifier));
888 return Service(service);
889}
890
892 const Request& authorizationRequest,
893 Identity *identity,
894 const CorrelationId& correlationId,
895 EventQueue *eventQueue)
896{
897 assert(identity);
898
899 CorrelationId retCorrelationId(correlationId);
900
902 blpapi_AbstractSession_sendAuthorizationRequest(d_handle_p,
903 authorizationRequest.handle(),
904 identity->handle(),
905 const_cast<blpapi_CorrelationId_t *>(
906 &retCorrelationId.impl()),
907 eventQueue ? eventQueue->handle() : 0,
908 0,
909 0));
910
911 return retCorrelationId;
912}
913
914inline void AbstractSession::cancel(const CorrelationId& correlationId)
915{
916 blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
917}
918
920 const std::vector<CorrelationId>& correlationIds)
921{
922 if (!correlationIds.size()) {
923 return;
924 }
925 cancel(&correlationIds[0], correlationIds.size());
926}
927
929 const CorrelationId *correlationIds, size_t numCorrelationIds)
930{
931 blpapi_AbstractSession_cancel(d_handle_p,
932 reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
933 numCorrelationIds,
934 0,
935 0);
936}
937
939 const CorrelationId& correlationId, EventQueue *eventQueue)
940{
941 CorrelationId retCorrelationId(correlationId);
942
944 blpapi_AbstractSession_generateToken(d_handle_p,
945 &retCorrelationId.impl(),
946 eventQueue ? eventQueue->handle() : 0));
947
948 return retCorrelationId;
949}
950
952 const char *ipAddress,
953 const CorrelationId& correlationId,
954 EventQueue *eventQueue)
955{
956 CorrelationId retCorrelationId(correlationId);
957
959 BLPAPI_CALL(blpapi_AbstractSession_generateManualToken)(d_handle_p,
960 &retCorrelationId.impl(),
961 userId,
962 ipAddress,
963 eventQueue ? eventQueue->handle() : 0));
964
965 return retCorrelationId;
966}
967
968inline bool AbstractSession::openService(const char *serviceIdentifier)
969{
970 return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
971 ? false
972 : true;
973}
974
976 const char *serviceIdentifier, const CorrelationId& correlationId)
977{
978 blpapi_CorrelationId_t retv = correlationId.impl();
979 ExceptionUtil::throwOnError(blpapi_AbstractSession_openServiceAsync(
980 d_handle_p, serviceIdentifier, &retv));
981
982 return CorrelationId(retv);
983}
984
986{
987 return UserHandle(blpapi_AbstractSession_createIdentity(d_handle_p));
988}
989
991{
992 return Identity(blpapi_AbstractSession_createIdentity(d_handle_p));
993}
994
996 const AuthOptions& authOptions, const CorrelationId& cid)
997{
998 blpapi_CorrelationId_t cidHandle = cid.impl();
999
1000 ExceptionUtil::throwOnError(BLPAPI_CALL(
1001 blpapi_AbstractSession_generateAuthorizedIdentityAsync)(
1002 d_handle_p, authOptions.handle(), &cidHandle));
1003
1004 return CorrelationId(cidHandle);
1005}
1006
1008 const CorrelationId& correlationId)
1009{
1010 blpapi_Identity_t *identity = NULL;
1011
1013 BLPAPI_CALL(blpapi_AbstractSession_getAuthorizedIdentity)(
1014 d_handle_p, &correlationId.impl(), &identity));
1015
1016 return Identity(identity);
1017}
1018
1020{
1021 const char *sessionName = nullptr;
1022 size_t size = 0;
1023
1025 BLPAPI_CALL(blpapi_AbstractSession_sessionName)(
1026 d_handle_p, &sessionName, &size));
1027 return std::string(sessionName, size);
1028}
1029
1031inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
1032{
1033 return d_handle_p;
1034}
1036
1037} // close namespace blpapi
1038} // close namespace BloombergLP
1039
1040#endif // #ifdef __cplusplus
1041#endif // #ifndef INCLUDED_BLPAPI_ABSTRACTSESSION
Provides configuration settings for authorization.
Provide functions for dispatchtbl.
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
A component which defines events related operations.
Provide a dispatcher to dispatch events.
Defines Exceptions that can be thrown by the blpapi library.
Provide access to the entitlements for a user.
Defines a request which can be sent for a service.
A service which provides access to API data (provide or consume).
Provide BLPAPI types.
Provide preprocessor macros for BLPAPI library version information.
virtual bool openService(const char *serviceIdentifier)
Definition blpapi_abstractsession.h:968
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition blpapi_abstractsession.h:938
std::string sessionName()
Definition blpapi_abstractsession.h:1019
virtual Event nextEvent(int timeout=0)=0
UserHandle createUserHandle()
Definition blpapi_abstractsession.h:985
virtual int tryNextEvent(Event *event)=0
virtual CorrelationId sendAuthorizationRequest(const Request &authorizationRequest, Identity *identity, const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition blpapi_abstractsession.h:891
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:1007
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:975
CorrelationId generateAuthorizedIdentity(const AuthOptions &authOptions, const CorrelationId &cid=CorrelationId())
Definition blpapi_abstractsession.h:995
virtual Identity createIdentity()
Definition blpapi_abstractsession.h:990
virtual void cancel(const CorrelationId &correlationId)
Definition blpapi_abstractsession.h:914
virtual ~AbstractSession()
Definition blpapi_abstractsession.h:873
virtual Service getService(const char *serviceIdentifier) const
Definition blpapi_abstractsession.h:883
Definition blpapi_authoptions.h:485
Definition blpapi_correlationid.h:322
Definition blpapi_event.h:532
Definition blpapi_event.h:325
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_identity.h:217
Definition blpapi_request.h:214
Definition blpapi_service.h:616
Identity UserHandle
Definition blpapi_abstractsession.h:456
#define BLPAPI_SDK_VERSION_STRING
C-string encoding the version of the BLPAPI headers used at compile time in "MAJOR....
Definition blpapi_versionmacros.h:99
Definition blpapi_abstractsession.h:448
Definition blpapi_abstractsession.h:447