BLPAPI C++  3.24.10
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 
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90 
91 // All of the blpapi_UserHandle_* functions have been deprecated. Please use
92 // blpapi_Identity_* versions of these functions instead.
93 
96 
99 
102  const blpapi_Service_t *service,
103  const blpapi_Element_t *eidElement,
104  const int *entitlementIds,
105  size_t numEntitlements,
106  int *failedEntitlements,
107  int *failedEntitlementsCount);
108 
111  const blpapi_CorrelationId_t *correlationIds,
112  size_t numCorrelationIds,
113  const char *requestLabel,
114  int requestLabelLen);
115 
118  blpapi_AbstractSession_t *session,
119  const blpapi_Request_t *request,
120  blpapi_Identity_t *identity,
121  blpapi_CorrelationId_t *correlationId,
122  blpapi_EventQueue_t *eventQueue,
123  const char *requestLabel,
124  int requestLabelLen);
125 
128  blpapi_AbstractSession_t *session, const char *serviceIdentifier);
129 
132  const char *serviceIdentifier,
133  blpapi_CorrelationId_t *correlationId);
134 
137  blpapi_CorrelationId_t *correlationId,
138  blpapi_EventQueue_t *eventQueue);
139 
142  blpapi_AbstractSession_t *session,
143  blpapi_CorrelationId_t *correlationId,
144  const char *user,
145  const char *manualIp,
146  blpapi_EventQueue_t *eventQueue);
147 
150  blpapi_Service_t **service,
151  const char *serviceIdentifier);
152 
155  blpapi_AbstractSession_t *session);
156 
159  blpapi_AbstractSession_t *session,
160  const blpapi_AuthOptions_t *authOptions,
161  blpapi_CorrelationId_t *cid);
162 
165  blpapi_AbstractSession_t *session,
166  const blpapi_CorrelationId_t *cid,
167  blpapi_Identity_t **identity);
168 
171  const char **sessionName,
172  size_t *size);
173 
174 #ifdef __cplusplus
175 }
176 
177 #include <cassert>
178 #include <vector>
179 
187 namespace BloombergLP {
188 namespace blpapi {
189 
191 
192 // =====================
193 // class AbstractSession
194 // =====================
195 
254 
255  blpapi_AbstractSession_t *d_handle_p;
256 
257  private:
258  // NOT IMPLEMENTED
260  AbstractSession& operator=(const AbstractSession&);
261 
262  protected:
264  AbstractSession();
269  void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
273 
275  public:
276  virtual ~AbstractSession();
281  // MANIPULATORS
282  virtual bool start() = 0;
294  virtual bool startAsync() = 0;
306  virtual void stop() = 0;
318  virtual void stopAsync() = 0;
330  virtual Event nextEvent(int timeout = 0) = 0;
346  virtual int tryNextEvent(Event *event) = 0;
354  virtual bool openService(const char *serviceIdentifier);
372  virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
373  const CorrelationId& correlationId = CorrelationId());
391  const Request& authorizationRequest,
392  Identity *identity,
393  const CorrelationId& correlationId = CorrelationId(),
394  EventQueue *eventQueue = 0);
422  virtual void cancel(const CorrelationId& correlationId);
441  virtual void cancel(const std::vector<CorrelationId>& correlationIds);
462  virtual void cancel(
463  const CorrelationId *correlationIds, size_t numCorrelationIds);
485  const CorrelationId& correlationId = CorrelationId(),
486  EventQueue *eventQueue = 0);
496  virtual CorrelationId generateToken(const char *userId,
497  const char *ipAddress,
498  const CorrelationId& correlationId = CorrelationId(),
499  EventQueue *eventQueue = 0);
510  virtual Service getService(const char *serviceIdentifier) const;
524  virtual Identity createIdentity();
531  const CorrelationId& cid = CorrelationId());
550  const CorrelationId& correlationId = CorrelationId());
562  std::string sessionName();
567  blpapi_AbstractSession_t *abstractSessionHandle() const;
572 
575  BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle
583 };
584 
588 //=============================================================================
589 // INLINE FUNCTION DEFINITIONS
590 //=============================================================================
591 
592 // ---------------------
593 // class AbstractSession
594 // ---------------------
595 
596 inline AbstractSession::AbstractSession()
597  : d_handle_p(0)
598 {
599 }
600 
602 
603 inline void AbstractSession::initAbstractSessionHandle(
604  blpapi_AbstractSession_t *handle)
605 {
606  d_handle_p = handle;
607 }
608 
609 inline Service AbstractSession::getService(const char *serviceIdentifier) const
610 {
611  blpapi_Service_t *service;
613  d_handle_p, &service, serviceIdentifier));
614  return Service(service);
615 }
616 
618  const Request& authorizationRequest,
619  Identity *identity,
620  const CorrelationId& correlationId,
621  EventQueue *eventQueue)
622 {
623  assert(identity);
624 
625  CorrelationId retCorrelationId(correlationId);
626 
629  authorizationRequest.handle(),
630  identity->handle(),
631  const_cast<blpapi_CorrelationId_t *>(
632  &retCorrelationId.impl()),
633  eventQueue ? eventQueue->handle() : 0,
634  0,
635  0));
636 
637  return retCorrelationId;
638 }
639 
640 inline void AbstractSession::cancel(const CorrelationId& correlationId)
641 {
642  blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
643 }
644 
646  const std::vector<CorrelationId>& correlationIds)
647 {
648  if (!correlationIds.size()) {
649  return;
650  }
651  cancel(&correlationIds[0], correlationIds.size());
652 }
653 
655  const CorrelationId *correlationIds, size_t numCorrelationIds)
656 {
658  reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
659  numCorrelationIds,
660  0,
661  0);
662 }
663 
665  const CorrelationId& correlationId, EventQueue *eventQueue)
666 {
667  CorrelationId retCorrelationId(correlationId);
668 
671  &retCorrelationId.impl(),
672  eventQueue ? eventQueue->handle() : 0));
673 
674  return retCorrelationId;
675 }
676 
678  const char *ipAddress,
679  const CorrelationId& correlationId,
680  EventQueue *eventQueue)
681 {
682  CorrelationId retCorrelationId(correlationId);
683 
686  &retCorrelationId.impl(),
687  userId,
688  ipAddress,
689  eventQueue ? eventQueue->handle() : 0));
690 
691  return retCorrelationId;
692 }
693 
694 inline bool AbstractSession::openService(const char *serviceIdentifier)
695 {
696  return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
697  ? false
698  : true;
699 }
700 
702  const char *serviceIdentifier, const CorrelationId& correlationId)
703 {
704  blpapi_CorrelationId_t retv = correlationId.impl();
706  d_handle_p, serviceIdentifier, &retv));
707 
708  return CorrelationId(retv);
709 }
710 
712 {
714 }
715 
717 {
719 }
720 
722  const AuthOptions& authOptions, const CorrelationId& cid)
723 {
724  blpapi_CorrelationId_t cidHandle = cid.impl();
725 
728  d_handle_p, authOptions.handle(), &cidHandle));
729 
730  return CorrelationId(cidHandle);
731 }
732 
734  const CorrelationId& correlationId)
735 {
736  blpapi_Identity_t *identity = NULL;
737 
740  d_handle_p, &correlationId.impl(), &identity));
741 
742  return Identity(identity);
743 }
744 
745 inline std::string AbstractSession::sessionName()
746 {
747  const char *sessionName = nullptr;
748  size_t size = 0;
749 
752  d_handle_p, &sessionName, &size));
753  return std::string(sessionName, size);
754 }
755 
756 inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
757 {
758  return d_handle_p;
759 }
760 
761 } // close namespace blpapi
762 } // close namespace BloombergLP
763 
764 #endif // #ifdef __cplusplus
765 #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:640
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:609
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:701
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
BLPAPI_DEPRECATE_ABSTRACT_SESSION_CREATE_USER_HANDLE UserHandle createUserHandle()
Definition: blpapi_abstractsession.h:711
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:187
#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:253
Definition: blpapi_event.h:386
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:733
Provide access to the entitlements for a user.
Identity UserHandle
Definition: blpapi_abstractsession.h:190
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:601
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.
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:617
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)
CorrelationId generateAuthorizedIdentity(const AuthOptions &authOptions, const CorrelationId &cid=CorrelationId())
Definition: blpapi_abstractsession.h:721
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition: blpapi_abstractsession.h:664
Definition: blpapi_event.h:196
std::string sessionName()
Definition: blpapi_abstractsession.h:745
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:716
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:694
blpapi_Identity_t * handle() const
Definition: blpapi_identity.h:381