BLPAPI C++  3.25.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
28 #ifndef INCLUDED_BLPAPI_ABSTRACTSESSION
29 #define INCLUDED_BLPAPI_ABSTRACTSESSION
30 
74 #include <blpapi_authoptions.h>
75 #include <blpapi_call.h>
76 #include <blpapi_correlationid.h>
77 #include <blpapi_defs.h>
78 #include <blpapi_deprecate.h>
79 #include <blpapi_event.h>
80 #include <blpapi_eventdispatcher.h>
81 #include <blpapi_exception.h>
82 #include <blpapi_identity.h>
83 #include <blpapi_request.h>
84 #include <blpapi_service.h>
85 #include <blpapi_types.h>
86 #include <blpapi_versionmacros.h>
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91 
92 // All of the blpapi_UserHandle_* functions have been deprecated. Please use
93 // blpapi_Identity_* versions of these functions instead.
94 
97 
100 
103  const blpapi_Service_t *service,
104  const blpapi_Element_t *eidElement,
105  const int *entitlementIds,
106  size_t numEntitlements,
107  int *failedEntitlements,
108  int *failedEntitlementsCount);
109 
112  const blpapi_CorrelationId_t *correlationIds,
113  size_t numCorrelationIds,
114  const char *requestLabel,
115  int requestLabelLen);
116 
119  blpapi_AbstractSession_t *session,
120  const blpapi_Request_t *request,
121  blpapi_Identity_t *identity,
122  blpapi_CorrelationId_t *correlationId,
123  blpapi_EventQueue_t *eventQueue,
124  const char *requestLabel,
125  int requestLabelLen);
126 
129  blpapi_AbstractSession_t *session, const char *serviceIdentifier);
130 
133  const char *serviceIdentifier,
134  blpapi_CorrelationId_t *correlationId);
135 
138  blpapi_CorrelationId_t *correlationId,
139  blpapi_EventQueue_t *eventQueue);
140 
143  blpapi_AbstractSession_t *session,
144  blpapi_CorrelationId_t *correlationId,
145  const char *user,
146  const char *manualIp,
147  blpapi_EventQueue_t *eventQueue);
148 
151  blpapi_Service_t **service,
152  const char *serviceIdentifier);
153 
156  blpapi_AbstractSession_t *session);
157 
160  blpapi_AbstractSession_t *session,
161  const blpapi_AuthOptions_t *authOptions,
162  blpapi_CorrelationId_t *cid);
163 
166  blpapi_AbstractSession_t *session,
167  const blpapi_CorrelationId_t *cid,
168  blpapi_Identity_t **identity);
169 
172  const char **sessionName,
173  size_t *size);
174 
176 int blpapi_UserAgentInfo_setUserTaskName(const char *userTaskName);
177 
180  const char *language, const char *version);
181 
182 #ifdef __cplusplus
183 }
184 
185 #include <cassert>
186 #include <vector>
187 
195 namespace BloombergLP {
196 namespace blpapi {
197 
199 
200 // =====================
201 // class AbstractSession
202 // =====================
203 
262 
263  blpapi_AbstractSession_t *d_handle_p;
264 
265  private:
266  // NOT IMPLEMENTED
268  AbstractSession& operator=(const AbstractSession&);
269 
270  protected:
272  AbstractSession();
277  void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
281 
283  public:
284  virtual ~AbstractSession();
289  // MANIPULATORS
290  virtual bool start() = 0;
302  virtual bool startAsync() = 0;
314  virtual void stop() = 0;
326  virtual void stopAsync() = 0;
338  virtual Event nextEvent(int timeout = 0) = 0;
354  virtual int tryNextEvent(Event *event) = 0;
362  virtual bool openService(const char *serviceIdentifier);
380  virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
381  const CorrelationId& correlationId = CorrelationId());
399  const Request& authorizationRequest,
400  Identity *identity,
401  const CorrelationId& correlationId = CorrelationId(),
402  EventQueue *eventQueue = 0);
430  virtual void cancel(const CorrelationId& correlationId);
449  virtual void cancel(const std::vector<CorrelationId>& correlationIds);
470  virtual void cancel(
471  const CorrelationId *correlationIds, size_t numCorrelationIds);
493  const CorrelationId& correlationId = CorrelationId(),
494  EventQueue *eventQueue = 0);
504  virtual CorrelationId generateToken(const char *userId,
505  const char *ipAddress,
506  const CorrelationId& correlationId = CorrelationId(),
507  EventQueue *eventQueue = 0);
518  virtual Service getService(const char *serviceIdentifier) const;
532  virtual Identity createIdentity();
539  const CorrelationId& cid = CorrelationId());
558  const CorrelationId& correlationId = CorrelationId());
570  std::string sessionName();
575  blpapi_AbstractSession_t *abstractSessionHandle() const;
580 
583  BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle
591 };
592 
596 //=============================================================================
597 // INLINE FUNCTION DEFINITIONS
598 //=============================================================================
599 
600 // ---------------------
601 // class AbstractSession
602 // ---------------------
603 
604 inline AbstractSession::AbstractSession()
605  : d_handle_p(0)
606 {
607  // Ignore the return value
609  ("C++", BLPAPI_SDK_VERSION_STRING);
610 }
611 
613 
614 inline void AbstractSession::initAbstractSessionHandle(
615  blpapi_AbstractSession_t *handle)
616 {
617  d_handle_p = handle;
618 }
619 
620 inline Service AbstractSession::getService(const char *serviceIdentifier) const
621 {
622  blpapi_Service_t *service;
624  d_handle_p, &service, serviceIdentifier));
625  return Service(service);
626 }
627 
629  const Request& authorizationRequest,
630  Identity *identity,
631  const CorrelationId& correlationId,
632  EventQueue *eventQueue)
633 {
634  assert(identity);
635 
636  CorrelationId retCorrelationId(correlationId);
637 
640  authorizationRequest.handle(),
641  identity->handle(),
642  const_cast<blpapi_CorrelationId_t *>(
643  &retCorrelationId.impl()),
644  eventQueue ? eventQueue->handle() : 0,
645  0,
646  0));
647 
648  return retCorrelationId;
649 }
650 
651 inline void AbstractSession::cancel(const CorrelationId& correlationId)
652 {
653  blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
654 }
655 
657  const std::vector<CorrelationId>& correlationIds)
658 {
659  if (!correlationIds.size()) {
660  return;
661  }
662  cancel(&correlationIds[0], correlationIds.size());
663 }
664 
666  const CorrelationId *correlationIds, size_t numCorrelationIds)
667 {
669  reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
670  numCorrelationIds,
671  0,
672  0);
673 }
674 
676  const CorrelationId& correlationId, EventQueue *eventQueue)
677 {
678  CorrelationId retCorrelationId(correlationId);
679 
682  &retCorrelationId.impl(),
683  eventQueue ? eventQueue->handle() : 0));
684 
685  return retCorrelationId;
686 }
687 
689  const char *ipAddress,
690  const CorrelationId& correlationId,
691  EventQueue *eventQueue)
692 {
693  CorrelationId retCorrelationId(correlationId);
694 
697  &retCorrelationId.impl(),
698  userId,
699  ipAddress,
700  eventQueue ? eventQueue->handle() : 0));
701 
702  return retCorrelationId;
703 }
704 
705 inline bool AbstractSession::openService(const char *serviceIdentifier)
706 {
707  return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
708  ? false
709  : true;
710 }
711 
713  const char *serviceIdentifier, const CorrelationId& correlationId)
714 {
715  blpapi_CorrelationId_t retv = correlationId.impl();
717  d_handle_p, serviceIdentifier, &retv));
718 
719  return CorrelationId(retv);
720 }
721 
723 {
725 }
726 
728 {
730 }
731 
733  const AuthOptions& authOptions, const CorrelationId& cid)
734 {
735  blpapi_CorrelationId_t cidHandle = cid.impl();
736 
739  d_handle_p, authOptions.handle(), &cidHandle));
740 
741  return CorrelationId(cidHandle);
742 }
743 
745  const CorrelationId& correlationId)
746 {
747  blpapi_Identity_t *identity = NULL;
748 
751  d_handle_p, &correlationId.impl(), &identity));
752 
753  return Identity(identity);
754 }
755 
756 inline std::string AbstractSession::sessionName()
757 {
758  const char *sessionName = nullptr;
759  size_t size = 0;
760 
763  d_handle_p, &sessionName, &size));
764  return std::string(sessionName, size);
765 }
766 
767 inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
768 {
769  return d_handle_p;
770 }
771 
772 } // close namespace blpapi
773 } // close namespace BloombergLP
774 
775 #endif // #ifdef __cplusplus
776 #endif // #ifndef INCLUDED_BLPAPI_ABSTRACTSESSION
struct blpapi_Identity blpapi_UserHandle_t
Definition: blpapi_types.h:185
virtual void cancel(const CorrelationId &correlationId)
Definition: blpapi_abstractsession.h:651
BLPAPI_EXPORT int blpapi_AbstractSession_generateAuthorizedIdentityAsync(blpapi_AbstractSession_t *session, const blpapi_AuthOptions_t *authOptions, blpapi_CorrelationId_t *cid)
BLPAPI_EXPORT int blpapi_AbstractSession_sendAuthorizationRequest(blpapi_AbstractSession_t *session, const blpapi_Request_t *request, blpapi_Identity_t *identity, blpapi_CorrelationId_t *correlationId, blpapi_EventQueue_t *eventQueue, const char *requestLabel, int requestLabelLen)
virtual Service getService(const char *serviceIdentifier) const
Definition: blpapi_abstractsession.h:620
#define BLPAPI_SDK_VERSION_STRING
Definition: blpapi_versionmacros.h:69
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:712
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle createUserHandle()
Definition: blpapi_abstractsession.h:722
blpapi_Request_t * handle() const
Definition: blpapi_request.h:718
Common definitions used by the library.
blpapi_EventQueue_t * handle() const
Definition: blpapi_event.h:586
virtual Event nextEvent(int timeout=0)=0
Definition: blpapi_abstractsession.h:195
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
Definition: blpapi_service.h:304
BLPAPI_EXPORT int blpapi_AbstractSession_openServiceAsync(blpapi_AbstractSession_t *session, const char *serviceIdentifier, blpapi_CorrelationId_t *correlationId)
Definition: blpapi_authoptions.h:194
BLPAPI_EXPORT int blpapi_UserHandle_addRef(blpapi_UserHandle_t *handle)
Definition: blpapi_abstractsession.h:261
Definition: blpapi_event.h:386
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:744
Provide access to the entitlements for a user.
Identity UserHandle
Definition: blpapi_abstractsession.h:198
A service which provides access to API data (provide or consume).
blpapi_AuthOptions_t * handle() const
Definition: blpapi_authoptions.h:491
BLPAPI_EXPORT int blpapi_AbstractSession_sessionName(blpapi_AbstractSession_t *session, const char **sessionName, size_t *size)
A component which defines events related operations.
Provide a key to identify individual subscriptions or requests.
Provides configuration settings for authorization.
struct blpapi_EventQueue blpapi_EventQueue_t
Definition: blpapi_types.h:148
virtual ~AbstractSession()
Definition: blpapi_abstractsession.h:612
Definition: blpapi_request.h:147
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
BLPAPI_EXPORT int blpapi_AbstractSession_openService(blpapi_AbstractSession_t *session, const char *serviceIdentifier)
BLPAPI_EXPORT void blpapi_UserHandle_release(blpapi_UserHandle_t *handle)
Defines a request which can be sent for a service.
struct blpapi_AuthOptions blpapi_AuthOptions_t
Definition: blpapi_types.h:203
struct blpapi_Identity blpapi_Identity_t
Definition: blpapi_types.h:188
BLPAPI_EXPORT blpapi_Identity_t * blpapi_AbstractSession_createIdentity(blpapi_AbstractSession_t *session)
Definition: blpapi_correlationid.h:201
Provide a dispatcher to dispatch events.
Provide preprocessor macros for BLPAPI library version information.
BLPAPI_EXPORT int blpapi_UserAgentInfo_setUserTaskName(const char *userTaskName)
Definition: blpapi_identity.h:131
BLPAPI_EXPORT int blpapi_AbstractSession_generateToken(blpapi_AbstractSession_t *session, blpapi_CorrelationId_t *correlationId, blpapi_EventQueue_t *eventQueue)
virtual CorrelationId sendAuthorizationRequest(const Request &authorizationRequest, Identity *identity, const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition: blpapi_abstractsession.h:628
BLPAPI_EXPORT int blpapi_UserHandle_hasEntitlements(const blpapi_UserHandle_t *handle, const blpapi_Service_t *service, const blpapi_Element_t *eidElement, const int *entitlementIds, size_t numEntitlements, int *failedEntitlements, int *failedEntitlementsCount)
BLPAPI_EXPORT int blpapi_UserAgentInfo_setNativeSdkLanguageAndVersion(const char *language, const char *version)
CorrelationId generateAuthorizedIdentity(const AuthOptions &authOptions, const CorrelationId &cid=CorrelationId())
Definition: blpapi_abstractsession.h:732
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition: blpapi_abstractsession.h:675
Definition: blpapi_event.h:196
std::string sessionName()
Definition: blpapi_abstractsession.h:756
Defines Exceptions that can be thrown by the blpapi library.
virtual int tryNextEvent(Event *event)=0
struct blpapi_Request blpapi_Request_t
Definition: blpapi_dispatchtbl.h:81
virtual Identity createIdentity()
Definition: blpapi_abstractsession.h:727
struct blpapi_AbstractSession blpapi_AbstractSession_t
Definition: blpapi_types.h:127
BLPAPI_EXPORT int blpapi_AbstractSession_generateManualToken(blpapi_AbstractSession_t *session, blpapi_CorrelationId_t *correlationId, const char *user, const char *manualIp, blpapi_EventQueue_t *eventQueue)
BLPAPI_EXPORT int blpapi_AbstractSession_cancel(blpapi_AbstractSession_t *session, const blpapi_CorrelationId_t *correlationIds, size_t numCorrelationIds, const char *requestLabel, int requestLabelLen)
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
struct blpapi_Service blpapi_Service_t
Definition: blpapi_types.h:166
BLPAPI_EXPORT int blpapi_AbstractSession_getAuthorizedIdentity(blpapi_AbstractSession_t *session, const blpapi_CorrelationId_t *cid, blpapi_Identity_t **identity)
Provide functions for dispatchtbl.
Provide BLPAPI types.
BLPAPI_EXPORT int blpapi_AbstractSession_getService(blpapi_AbstractSession_t *session, blpapi_Service_t **service, const char *serviceIdentifier)
virtual bool openService(const char *serviceIdentifier)
Definition: blpapi_abstractsession.h:705
blpapi_Identity_t * handle() const
Definition: blpapi_identity.h:381