BLPAPI C++ 3.26.6
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
156BLPAPI_EXPORT
157int blpapi_UserHandle_hasEntitlements(const blpapi_UserHandle_t *handle,
158 const blpapi_Service_t *service,
159 const blpapi_Element_t *eidElement,
160 const int *entitlementIds,
161 size_t numEntitlements,
162 int *failedEntitlements,
163 int *failedEntitlementsCount);
164
183BLPAPI_EXPORT
184int blpapi_AbstractSession_cancel(blpapi_AbstractSession_t *session,
185 const blpapi_CorrelationId_t *correlationIds,
186 size_t numCorrelationIds,
187 const char *requestLabel,
188 int requestLabelLen);
189
212BLPAPI_EXPORT
213int blpapi_AbstractSession_sendAuthorizationRequest(
214 blpapi_AbstractSession_t *session,
215 const blpapi_Request_t *request,
216 blpapi_Identity_t *identity,
217 blpapi_CorrelationId_t *correlationId,
218 blpapi_EventQueue_t *eventQueue,
219 const char *requestLabel,
220 int requestLabelLen);
221
235BLPAPI_EXPORT
236int blpapi_AbstractSession_openService(
237 blpapi_AbstractSession_t *session, const char *serviceIdentifier);
238
253BLPAPI_EXPORT
254int blpapi_AbstractSession_openServiceAsync(blpapi_AbstractSession_t *session,
255 const char *serviceIdentifier,
256 blpapi_CorrelationId_t *correlationId);
257
272BLPAPI_EXPORT
273int blpapi_AbstractSession_generateToken(blpapi_AbstractSession_t *session,
274 blpapi_CorrelationId_t *correlationId,
275 blpapi_EventQueue_t *eventQueue);
276
296BLPAPI_EXPORT
297int blpapi_AbstractSession_generateManualToken(
298 blpapi_AbstractSession_t *session,
299 blpapi_CorrelationId_t *correlationId,
300 const char *user,
301 const char *manualIp,
302 blpapi_EventQueue_t *eventQueue);
303
318BLPAPI_EXPORT
319int blpapi_AbstractSession_getService(blpapi_AbstractSession_t *session,
320 blpapi_Service_t **service,
321 const char *serviceIdentifier);
322
338BLPAPI_EXPORT
339blpapi_Identity_t *blpapi_AbstractSession_createIdentity(
340 blpapi_AbstractSession_t *session);
341
360BLPAPI_EXPORT
361int blpapi_AbstractSession_generateAuthorizedIdentityAsync(
362 blpapi_AbstractSession_t *session,
363 const blpapi_AuthOptions_t *authOptions,
364 blpapi_CorrelationId_t *cid);
365
386BLPAPI_EXPORT
387int blpapi_AbstractSession_getAuthorizedIdentity(
388 blpapi_AbstractSession_t *session,
389 const blpapi_CorrelationId_t *cid,
390 blpapi_Identity_t **identity);
391
407BLPAPI_EXPORT
408int blpapi_AbstractSession_sessionName(blpapi_AbstractSession_t *session,
409 const char **sessionName,
410 size_t *size);
411
422BLPAPI_EXPORT
423int blpapi_UserAgentInfo_setUserTaskName(const char *userTaskName);
424
438BLPAPI_EXPORT
439int blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion(
440 const char *language, const char *version);
441
444
445#ifdef __cplusplus
446}
447
448#include <cassert>
449#include <vector>
450
451namespace BloombergLP {
452namespace blpapi {
459
461
462// =====================
463// class AbstractSession
464// =====================
465
523class AbstractSession {
524
525 blpapi_AbstractSession_t *d_handle_p;
526
527 private:
528 // NOT IMPLEMENTED
529 AbstractSession(const AbstractSession&);
530 AbstractSession& operator=(const AbstractSession&);
531
532 protected:
534 AbstractSession();
538
539 void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
544
545 public:
546 virtual ~AbstractSession();
550
551 // MANIPULATORS
552 virtual bool start() = 0;
563
564 virtual bool startAsync() = 0;
575
576 virtual void stop() = 0;
587
588 virtual void stopAsync() = 0;
599
600 virtual Event nextEvent(int timeout = 0) = 0;
615
616 virtual int tryNextEvent(Event *event) = 0;
623
624 virtual bool openService(const char *serviceIdentifier);
641
642 virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
643 const CorrelationId& correlationId = CorrelationId());
659
661 const Request& authorizationRequest,
662 Identity *identity,
663 const CorrelationId& correlationId = CorrelationId(),
664 EventQueue *eventQueue = 0);
691
692 virtual void cancel(const CorrelationId& correlationId);
710
711 virtual void cancel(const std::vector<CorrelationId>& correlationIds);
731
732 virtual void cancel(
733 const CorrelationId *correlationIds, size_t numCorrelationIds);
753
755 const CorrelationId& correlationId = CorrelationId(),
756 EventQueue *eventQueue = 0);
768
769 virtual CorrelationId generateToken(const char *userId,
770 const char *ipAddress,
771 const CorrelationId& correlationId = CorrelationId(),
772 EventQueue *eventQueue = 0);
782
783 virtual Service getService(const char *serviceIdentifier) const;
796
797 virtual Identity createIdentity();
802
804 const CorrelationId& cid = CorrelationId());
821
823 const CorrelationId& correlationId = CorrelationId());
834
835 std::string sessionName();
839
841 blpapi_AbstractSession_t *abstractSessionHandle() const;
846
848 BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle
856};
857
860
861//=============================================================================
862// INLINE FUNCTION DEFINITIONS
863//=============================================================================
864
865// ---------------------
866// class AbstractSession
867// ---------------------
868
869inline AbstractSession::AbstractSession()
870 : d_handle_p(0)
871{
872 // Ignore the return value
873 BLPAPI_CALL(blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion)
875}
876
878
880inline void AbstractSession::initAbstractSessionHandle(
881 blpapi_AbstractSession_t *handle)
882{
883 d_handle_p = handle;
884}
886
887inline Service AbstractSession::getService(const char *serviceIdentifier) const
888{
889 blpapi_Service_t *service;
890 ExceptionUtil::throwOnError(blpapi_AbstractSession_getService(
891 d_handle_p, &service, serviceIdentifier));
892 return Service(service);
893}
894
896 const Request& authorizationRequest,
897 Identity *identity,
898 const CorrelationId& correlationId,
899 EventQueue *eventQueue)
900{
901 assert(identity);
902
903 CorrelationId retCorrelationId(correlationId);
904
906 blpapi_AbstractSession_sendAuthorizationRequest(d_handle_p,
907 authorizationRequest.handle(),
908 identity->handle(),
909 const_cast<blpapi_CorrelationId_t *>(
910 &retCorrelationId.impl()),
911 eventQueue ? eventQueue->handle() : 0,
912 0,
913 0));
914
915 return retCorrelationId;
916}
917
918inline void AbstractSession::cancel(const CorrelationId& correlationId)
919{
920 blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
921}
922
924 const std::vector<CorrelationId>& correlationIds)
925{
926 if (!correlationIds.size()) {
927 return;
928 }
929 cancel(&correlationIds[0], correlationIds.size());
930}
931
933 const CorrelationId *correlationIds, size_t numCorrelationIds)
934{
935 blpapi_AbstractSession_cancel(d_handle_p,
936 reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
937 numCorrelationIds,
938 0,
939 0);
940}
941
943 const CorrelationId& correlationId, EventQueue *eventQueue)
944{
945 CorrelationId retCorrelationId(correlationId);
946
948 blpapi_AbstractSession_generateToken(d_handle_p,
949 &retCorrelationId.impl(),
950 eventQueue ? eventQueue->handle() : 0));
951
952 return retCorrelationId;
953}
954
956 const char *ipAddress,
957 const CorrelationId& correlationId,
958 EventQueue *eventQueue)
959{
960 CorrelationId retCorrelationId(correlationId);
961
963 BLPAPI_CALL(blpapi_AbstractSession_generateManualToken)(d_handle_p,
964 &retCorrelationId.impl(),
965 userId,
966 ipAddress,
967 eventQueue ? eventQueue->handle() : 0));
968
969 return retCorrelationId;
970}
971
972inline bool AbstractSession::openService(const char *serviceIdentifier)
973{
974 return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
975 ? false
976 : true;
977}
978
980 const char *serviceIdentifier, const CorrelationId& correlationId)
981{
982 blpapi_CorrelationId_t retv = correlationId.impl();
983 ExceptionUtil::throwOnError(blpapi_AbstractSession_openServiceAsync(
984 d_handle_p, serviceIdentifier, &retv));
985
986 return CorrelationId(retv);
987}
988
990{
991 return UserHandle(blpapi_AbstractSession_createIdentity(d_handle_p));
992}
993
995{
996 return Identity(blpapi_AbstractSession_createIdentity(d_handle_p));
997}
998
1000 const AuthOptions& authOptions, const CorrelationId& cid)
1001{
1002 blpapi_CorrelationId_t cidHandle = cid.impl();
1003
1004 ExceptionUtil::throwOnError(BLPAPI_CALL(
1005 blpapi_AbstractSession_generateAuthorizedIdentityAsync)(
1006 d_handle_p, authOptions.handle(), &cidHandle));
1007
1008 return CorrelationId(cidHandle);
1009}
1010
1012 const CorrelationId& correlationId)
1013{
1014 blpapi_Identity_t *identity = NULL;
1015
1017 BLPAPI_CALL(blpapi_AbstractSession_getAuthorizedIdentity)(
1018 d_handle_p, &correlationId.impl(), &identity));
1019
1020 return Identity(identity);
1021}
1022
1024{
1025 const char *sessionName = nullptr;
1026 size_t size = 0;
1027
1029 BLPAPI_CALL(blpapi_AbstractSession_sessionName)(
1030 d_handle_p, &sessionName, &size));
1031 return std::string(sessionName, size);
1032}
1033
1035inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
1036{
1037 return d_handle_p;
1038}
1040
1041} // close namespace blpapi
1042} // close namespace BloombergLP
1043
1044#endif // #ifdef __cplusplus
1045#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:972
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition blpapi_abstractsession.h:942
std::string sessionName()
Definition blpapi_abstractsession.h:1023
virtual Event nextEvent(int timeout=0)=0
UserHandle createUserHandle()
Definition blpapi_abstractsession.h:989
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:895
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:1011
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:979
CorrelationId generateAuthorizedIdentity(const AuthOptions &authOptions, const CorrelationId &cid=CorrelationId())
Definition blpapi_abstractsession.h:999
virtual Identity createIdentity()
Definition blpapi_abstractsession.h:994
virtual void cancel(const CorrelationId &correlationId)
Definition blpapi_abstractsession.h:918
virtual ~AbstractSession()
Definition blpapi_abstractsession.h:877
virtual Service getService(const char *serviceIdentifier) const
Definition blpapi_abstractsession.h:887
Definition blpapi_authoptions.h:485
Definition blpapi_correlationid.h:306
Definition blpapi_event.h:517
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:619
Identity UserHandle
Definition blpapi_abstractsession.h:460
#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:452
Definition blpapi_abstractsession.h:451