BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_ABSTRACTSESSION
37#define INCLUDED_BLPAPI_ABSTRACTSESSION
38
81
82#include <blpapi_authoptions.h>
83#include <blpapi_call.h>
85#include <blpapi_defs.h>
86#include <blpapi_deprecate.h>
87#include <blpapi_event.h>
89#include <blpapi_exception.h>
90#include <blpapi_identity.h>
91#include <blpapi_request.h>
92#include <blpapi_service.h>
93#include <blpapi_types.h>
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
101
104
105// All of the blpapi_UserHandle_* functions have been deprecated. Please use
106// blpapi_Identity_* versions of these functions instead.
107
108BLPAPI_EXPORT
109void blpapi_UserHandle_release(blpapi_UserHandle_t *handle);
110
111BLPAPI_EXPORT
112int blpapi_UserHandle_addRef(blpapi_UserHandle_t *handle);
113
114BLPAPI_EXPORT
115int blpapi_UserHandle_hasEntitlements(const blpapi_UserHandle_t *handle,
116 const blpapi_Service_t *service,
117 const blpapi_Element_t *eidElement,
118 const int *entitlementIds,
119 size_t numEntitlements,
120 int *failedEntitlements,
121 int *failedEntitlementsCount);
122
123BLPAPI_EXPORT
124int blpapi_AbstractSession_cancel(blpapi_AbstractSession_t *session,
125 const blpapi_CorrelationId_t *correlationIds,
126 size_t numCorrelationIds,
127 const char *requestLabel,
128 int requestLabelLen);
129
130BLPAPI_EXPORT
131int blpapi_AbstractSession_sendAuthorizationRequest(
132 blpapi_AbstractSession_t *session,
133 const blpapi_Request_t *request,
134 blpapi_Identity_t *identity,
135 blpapi_CorrelationId_t *correlationId,
136 blpapi_EventQueue_t *eventQueue,
137 const char *requestLabel,
138 int requestLabelLen);
139
140BLPAPI_EXPORT
141int blpapi_AbstractSession_openService(
142 blpapi_AbstractSession_t *session, const char *serviceIdentifier);
143
144BLPAPI_EXPORT
145int blpapi_AbstractSession_openServiceAsync(blpapi_AbstractSession_t *session,
146 const char *serviceIdentifier,
147 blpapi_CorrelationId_t *correlationId);
148
149BLPAPI_EXPORT
150int blpapi_AbstractSession_generateToken(blpapi_AbstractSession_t *session,
151 blpapi_CorrelationId_t *correlationId,
152 blpapi_EventQueue_t *eventQueue);
153
154BLPAPI_EXPORT
155int blpapi_AbstractSession_generateManualToken(
156 blpapi_AbstractSession_t *session,
157 blpapi_CorrelationId_t *correlationId,
158 const char *user,
159 const char *manualIp,
160 blpapi_EventQueue_t *eventQueue);
161
162BLPAPI_EXPORT
163int blpapi_AbstractSession_getService(blpapi_AbstractSession_t *session,
164 blpapi_Service_t **service,
165 const char *serviceIdentifier);
166
167BLPAPI_EXPORT
168blpapi_Identity_t *blpapi_AbstractSession_createIdentity(
169 blpapi_AbstractSession_t *session);
170
171BLPAPI_EXPORT
172int blpapi_AbstractSession_generateAuthorizedIdentityAsync(
173 blpapi_AbstractSession_t *session,
174 const blpapi_AuthOptions_t *authOptions,
175 blpapi_CorrelationId_t *cid);
176
177BLPAPI_EXPORT
178int blpapi_AbstractSession_getAuthorizedIdentity(
179 blpapi_AbstractSession_t *session,
180 const blpapi_CorrelationId_t *cid,
181 blpapi_Identity_t **identity);
182
183BLPAPI_EXPORT
184int blpapi_AbstractSession_sessionName(blpapi_AbstractSession_t *session,
185 const char **sessionName,
186 size_t *size);
187
188BLPAPI_EXPORT
189int blpapi_UserAgentInfo_setUserTaskName(const char *userTaskName);
190
191BLPAPI_EXPORT
192int blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion(
193 const char *language, const char *version);
194
197
198#ifdef __cplusplus
199}
200
201#include <cassert>
202#include <vector>
203
210
211namespace BloombergLP {
212namespace blpapi {
213
215
216// =====================
217// class AbstractSession
218// =====================
219
277class AbstractSession {
278
279 blpapi_AbstractSession_t *d_handle_p;
280
281 private:
282 // NOT IMPLEMENTED
283 AbstractSession(const AbstractSession&);
284 AbstractSession& operator=(const AbstractSession&);
285
286 protected:
288 AbstractSession();
292
293 void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
298
299 public:
300 virtual ~AbstractSession();
304
305 // MANIPULATORS
306 virtual bool start() = 0;
317
318 virtual bool startAsync() = 0;
329
330 virtual void stop() = 0;
341
342 virtual void stopAsync() = 0;
353
354 virtual Event nextEvent(int timeout = 0) = 0;
369
370 virtual int tryNextEvent(Event *event) = 0;
377
378 virtual bool openService(const char *serviceIdentifier);
395
396 virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
397 const CorrelationId& correlationId = CorrelationId());
413
415 const Request& authorizationRequest,
416 Identity *identity,
417 const CorrelationId& correlationId = CorrelationId(),
418 EventQueue *eventQueue = 0);
445
446 virtual void cancel(const CorrelationId& correlationId);
464
465 virtual void cancel(const std::vector<CorrelationId>& correlationIds);
485
486 virtual void cancel(
487 const CorrelationId *correlationIds, size_t numCorrelationIds);
507
509 const CorrelationId& correlationId = CorrelationId(),
510 EventQueue *eventQueue = 0);
522
523 virtual CorrelationId generateToken(const char *userId,
524 const char *ipAddress,
525 const CorrelationId& correlationId = CorrelationId(),
526 EventQueue *eventQueue = 0);
536
537 virtual Service getService(const char *serviceIdentifier) const;
550
551 virtual Identity createIdentity();
556
558 const CorrelationId& cid = CorrelationId());
575
577 const CorrelationId& correlationId = CorrelationId());
588
589 std::string sessionName();
593
595 blpapi_AbstractSession_t *abstractSessionHandle() const;
600
602 BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle
610};
611
614
615//=============================================================================
616// INLINE FUNCTION DEFINITIONS
617//=============================================================================
618
619// ---------------------
620// class AbstractSession
621// ---------------------
622
623inline AbstractSession::AbstractSession()
624 : d_handle_p(0)
625{
626 // Ignore the return value
627 BLPAPI_CALL(blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion)
628 ("C++", BLPAPI_SDK_VERSION_STRING);
629}
630
632
633inline void AbstractSession::initAbstractSessionHandle(
634 blpapi_AbstractSession_t *handle)
635{
636 d_handle_p = handle;
637}
638
639inline Service AbstractSession::getService(const char *serviceIdentifier) const
640{
641 blpapi_Service_t *service;
642 ExceptionUtil::throwOnError(blpapi_AbstractSession_getService(
643 d_handle_p, &service, serviceIdentifier));
644 return Service(service);
645}
646
648 const Request& authorizationRequest,
649 Identity *identity,
650 const CorrelationId& correlationId,
651 EventQueue *eventQueue)
652{
653 assert(identity);
654
655 CorrelationId retCorrelationId(correlationId);
656
658 blpapi_AbstractSession_sendAuthorizationRequest(d_handle_p,
659 authorizationRequest.handle(),
660 identity->handle(),
661 const_cast<blpapi_CorrelationId_t *>(
662 &retCorrelationId.impl()),
663 eventQueue ? eventQueue->handle() : 0,
664 0,
665 0));
666
667 return retCorrelationId;
668}
669
670inline void AbstractSession::cancel(const CorrelationId& correlationId)
671{
672 blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
673}
674
676 const std::vector<CorrelationId>& correlationIds)
677{
678 if (!correlationIds.size()) {
679 return;
680 }
681 cancel(&correlationIds[0], correlationIds.size());
682}
683
685 const CorrelationId *correlationIds, size_t numCorrelationIds)
686{
687 blpapi_AbstractSession_cancel(d_handle_p,
688 reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
689 numCorrelationIds,
690 0,
691 0);
692}
693
695 const CorrelationId& correlationId, EventQueue *eventQueue)
696{
697 CorrelationId retCorrelationId(correlationId);
698
700 blpapi_AbstractSession_generateToken(d_handle_p,
701 &retCorrelationId.impl(),
702 eventQueue ? eventQueue->handle() : 0));
703
704 return retCorrelationId;
705}
706
708 const char *ipAddress,
709 const CorrelationId& correlationId,
710 EventQueue *eventQueue)
711{
712 CorrelationId retCorrelationId(correlationId);
713
715 BLPAPI_CALL(blpapi_AbstractSession_generateManualToken)(d_handle_p,
716 &retCorrelationId.impl(),
717 userId,
718 ipAddress,
719 eventQueue ? eventQueue->handle() : 0));
720
721 return retCorrelationId;
722}
723
724inline bool AbstractSession::openService(const char *serviceIdentifier)
725{
726 return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
727 ? false
728 : true;
729}
730
732 const char *serviceIdentifier, const CorrelationId& correlationId)
733{
734 blpapi_CorrelationId_t retv = correlationId.impl();
735 ExceptionUtil::throwOnError(blpapi_AbstractSession_openServiceAsync(
736 d_handle_p, serviceIdentifier, &retv));
737
738 return CorrelationId(retv);
739}
740
742{
743 return UserHandle(blpapi_AbstractSession_createIdentity(d_handle_p));
744}
745
747{
748 return Identity(blpapi_AbstractSession_createIdentity(d_handle_p));
749}
750
752 const AuthOptions& authOptions, const CorrelationId& cid)
753{
754 blpapi_CorrelationId_t cidHandle = cid.impl();
755
757 blpapi_AbstractSession_generateAuthorizedIdentityAsync)(
758 d_handle_p, authOptions.handle(), &cidHandle));
759
760 return CorrelationId(cidHandle);
761}
762
764 const CorrelationId& correlationId)
765{
766 blpapi_Identity_t *identity = NULL;
767
769 BLPAPI_CALL(blpapi_AbstractSession_getAuthorizedIdentity)(
770 d_handle_p, &correlationId.impl(), &identity));
771
772 return Identity(identity);
773}
774
776{
777 const char *sessionName = nullptr;
778 size_t size = 0;
779
781 BLPAPI_CALL(blpapi_AbstractSession_sessionName)(
782 d_handle_p, &sessionName, &size));
783 return std::string(sessionName, size);
784}
785
786inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
787{
788 return d_handle_p;
789}
790
791} // close namespace blpapi
792} // close namespace BloombergLP
793
794#endif // #ifdef __cplusplus
795#endif // #ifndef INCLUDED_BLPAPI_ABSTRACTSESSION
Provides configuration settings for authorization.
Provide functions for dispatchtbl.
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
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:724
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition blpapi_abstractsession.h:694
std::string sessionName()
Definition blpapi_abstractsession.h:775
virtual Event nextEvent(int timeout=0)=0
UserHandle createUserHandle()
Definition blpapi_abstractsession.h:741
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:647
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:763
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition blpapi_abstractsession.h:731
CorrelationId generateAuthorizedIdentity(const AuthOptions &authOptions, const CorrelationId &cid=CorrelationId())
Definition blpapi_abstractsession.h:751
virtual Identity createIdentity()
Definition blpapi_abstractsession.h:746
virtual void cancel(const CorrelationId &correlationId)
Definition blpapi_abstractsession.h:670
virtual ~AbstractSession()
Definition blpapi_abstractsession.h:631
virtual Service getService(const char *serviceIdentifier) const
Definition blpapi_abstractsession.h:639
Definition blpapi_authoptions.h:210
blpapi_AuthOptions_t * handle() const
Definition blpapi_authoptions.h:507
Definition blpapi_correlationid.h:225
Definition blpapi_event.h:402
blpapi_EventQueue_t * handle() const
Definition blpapi_event.h:602
Definition blpapi_event.h:212
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Definition blpapi_identity.h:147
blpapi_Identity_t * handle() const
Definition blpapi_identity.h:396
Definition blpapi_request.h:163
blpapi_Request_t * handle() const
Definition blpapi_request.h:763
Definition blpapi_service.h:320
Identity UserHandle
Definition blpapi_abstractsession.h:214
Definition blpapi_abstractsession.h:212
Definition blpapi_abstractsession.h:211