BLPAPI C++  3.21.0
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 
76 #ifndef INCLUDED_BLPAPI_CORRELATIONID
77 #include <blpapi_correlationid.h>
78 #endif
79 
80 #ifndef INCLUDED_BLPAPI_CALL
81 #include <blpapi_call.h>
82 #endif
83 
84 #ifndef INCLUDED_BLPAPI_DEFS
85 #include <blpapi_defs.h>
86 #endif
87 
88 #ifndef INCLUDED_BLPAPI_EVENT
89 #include <blpapi_event.h>
90 #endif
91 
92 #ifndef INCLUDED_BLPAPI_EVENTDISPATCHER
93 #include <blpapi_eventdispatcher.h>
94 #endif
95 
96 #ifndef INCLUDED_BLPAPI_EXCEPTION
97 #include <blpapi_exceptionutil.h>
98 #endif
99 
100 #ifndef INCLUDED_BLPAPI_IDENTITY
101 #include <blpapi_identity.h>
102 #endif
103 
104 #ifndef INCLUDED_BLPAPI_REQUEST
105 #include <blpapi_request.h>
106 #endif
107 
108 #ifndef INCLUDED_BLPAPI_SERVICE
109 #include <blpapi_service.h>
110 #endif
111 
112 #ifndef INCLUDED_BLPAPI_TYPES
113 #include <blpapi_types.h>
114 #endif
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
120 // All of the blpapi_UserHandle_* functions have been deprecated. Please use
121 // blpapi_Identity_* versions of these functions instead.
122 
125 
128 
131  const blpapi_Service_t *service,
132  const blpapi_Element_t *eidElement,
133  const int *entitlementIds,
134  size_t numEntitlements,
135  int *failedEntitlements,
136  int *failedEntitlementsCount);
137 
140  const blpapi_CorrelationId_t *correlationIds,
141  size_t numCorrelationIds,
142  const char *requestLabel,
143  int requestLabelLen);
144 
147  blpapi_AbstractSession_t *session,
148  const blpapi_Request_t *request,
149  blpapi_Identity_t *identity,
150  blpapi_CorrelationId_t *correlationId,
151  blpapi_EventQueue_t *eventQueue,
152  const char *requestLabel,
153  int requestLabelLen);
154 
157  blpapi_AbstractSession_t *session, const char *serviceIdentifier);
158 
161  const char *serviceIdentifier,
162  blpapi_CorrelationId_t *correlationId);
163 
166  blpapi_CorrelationId_t *correlationId,
167  blpapi_EventQueue_t *eventQueue);
168 
171  blpapi_AbstractSession_t *session,
172  blpapi_CorrelationId_t *correlationId,
173  const char *user,
174  const char *manualIp,
175  blpapi_EventQueue_t *eventQueue);
176 
179  blpapi_Service_t **service,
180  const char *serviceIdentifier);
181 
184  blpapi_AbstractSession_t *session);
185 
188  blpapi_AbstractSession_t *session,
189  const blpapi_AuthOptions_t *authOptions,
190  blpapi_CorrelationId_t *cid);
191 
194  blpapi_AbstractSession_t *session,
195  const blpapi_CorrelationId_t *cid,
196  blpapi_Identity_t **identity);
197 
198 #ifdef __cplusplus
199 }
200 
201 #include <cassert>
202 
203 #ifndef INCLUDED_VECTOR
204 #include <vector>
205 #define INCLUDED_VECTOR
206 #endif
207 
215 namespace BloombergLP {
216 namespace blpapi {
217 
219 
220 // =====================
221 // class AbstractSession
222 // =====================
223 
282 
283  blpapi_AbstractSession_t *d_handle_p;
284 
285  private:
286  // NOT IMPLEMENTED
288  AbstractSession& operator=(const AbstractSession&);
289 
290  protected:
292  AbstractSession();
297  void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
301 
303  public:
304  virtual ~AbstractSession();
309  // MANIPULATORS
310  virtual bool start() = 0;
322  virtual bool startAsync() = 0;
334  virtual void stop() = 0;
346  virtual void stopAsync() = 0;
358  virtual Event nextEvent(int timeout = 0) = 0;
374  virtual int tryNextEvent(Event *event) = 0;
382  virtual bool openService(const char *serviceIdentifier);
400  virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
401  const CorrelationId& correlationId = CorrelationId());
419  const Request& authorizationRequest,
420  Identity *identity,
421  const CorrelationId& correlationId = CorrelationId(),
422  EventQueue *eventQueue = 0);
450  virtual void cancel(const CorrelationId& correlationId);
469  virtual void cancel(const std::vector<CorrelationId>& correlationIds);
490  virtual void cancel(
491  const CorrelationId *correlationIds, size_t numCorrelationIds);
513  const CorrelationId& correlationId = CorrelationId(),
514  EventQueue *eventQueue = 0);
524  virtual CorrelationId generateToken(const char *userId,
525  const char *ipAddress,
526  const CorrelationId& correlationId = CorrelationId(),
527  EventQueue *eventQueue = 0);
538  virtual Service getService(const char *serviceIdentifier) const;
552  virtual Identity createIdentity();
559  const CorrelationId& cid = CorrelationId());
578  const CorrelationId& correlationId = CorrelationId());
590  blpapi_AbstractSession_t *abstractSessionHandle() const;
595 
605 };
606 
610 //=============================================================================
611 // INLINE FUNCTION DEFINITIONS
612 //=============================================================================
613 
614 // ---------------------
615 // class AbstractSession
616 // ---------------------
617 
618 inline AbstractSession::AbstractSession()
619  : d_handle_p(0)
620 {
621 }
622 
624 
625 inline void AbstractSession::initAbstractSessionHandle(
626  blpapi_AbstractSession_t *handle)
627 {
628  d_handle_p = handle;
629 }
630 
631 inline Service AbstractSession::getService(const char *serviceIdentifier) const
632 {
633  blpapi_Service_t *service;
635  d_handle_p, &service, serviceIdentifier));
636  return service;
637 }
638 
640  const Request& authorizationRequest,
641  Identity *identity,
642  const CorrelationId& correlationId,
643  EventQueue *eventQueue)
644 {
645  assert(identity);
646 
647  CorrelationId retCorrelationId(correlationId);
648 
651  authorizationRequest.handle(),
652  identity->handle(),
653  const_cast<blpapi_CorrelationId_t *>(
654  &retCorrelationId.impl()),
655  eventQueue ? eventQueue->handle() : 0,
656  0,
657  0));
658 
659  return retCorrelationId;
660 }
661 
662 inline void AbstractSession::cancel(const CorrelationId& correlationId)
663 {
664  blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
665 }
666 
668  const std::vector<CorrelationId>& correlationIds)
669 {
670  if (!correlationIds.size()) {
671  return;
672  }
673  cancel(&correlationIds[0], correlationIds.size());
674 }
675 
677  const CorrelationId *correlationIds, size_t numCorrelationIds)
678 {
680  reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
681  numCorrelationIds,
682  0,
683  0);
684 }
685 
687  const CorrelationId& correlationId, EventQueue *eventQueue)
688 {
689  CorrelationId retCorrelationId(correlationId);
690 
693  &retCorrelationId.impl(),
694  eventQueue ? eventQueue->handle() : 0));
695 
696  return retCorrelationId;
697 }
698 
700  const char *ipAddress,
701  const CorrelationId& correlationId,
702  EventQueue *eventQueue)
703 {
704  CorrelationId retCorrelationId(correlationId);
705 
708  &retCorrelationId.impl(),
709  userId,
710  ipAddress,
711  eventQueue ? eventQueue->handle() : 0));
712 
713  return retCorrelationId;
714 }
715 
716 inline bool AbstractSession::openService(const char *serviceIdentifier)
717 {
718  return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
719  ? false
720  : true;
721 }
722 
724  const char *serviceIdentifier, const CorrelationId& correlationId)
725 {
726  blpapi_CorrelationId_t retv = correlationId.impl();
728  d_handle_p, serviceIdentifier, &retv));
729 
730  return retv;
731 }
732 
734 {
735  return blpapi_AbstractSession_createIdentity(d_handle_p);
736 }
737 
739 {
740  return blpapi_AbstractSession_createIdentity(d_handle_p);
741 }
742 
744  const AuthOptions& authOptions, const CorrelationId& cid)
745 {
746  blpapi_CorrelationId_t cidHandle = cid.impl();
747 
750  d_handle_p, authOptions.handle(), &cidHandle));
751 
752  return cidHandle;
753 }
754 
756  const CorrelationId& correlationId)
757 {
758  blpapi_Identity_t *identity = NULL;
759 
762  d_handle_p, &correlationId.impl(), &identity));
763 
764  return identity;
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:662
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:631
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:723
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
UserHandle createUserHandle()
Definition: blpapi_abstractsession.h:733
blpapi_Request_t * handle() const
Definition: blpapi_request.h:712
struct blpapi_Request blpapi_Request_t
Definition: blpapi_request.h:67
Common definitions used by the library.
blpapi_EventQueue_t * handle() const
Definition: blpapi_event.h:468
virtual Event nextEvent(int timeout=0)=0
Definition: blpapi_abstractsession.h:215
#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:281
Definition: blpapi_event.h:278
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:755
Provide access to the entitlements for a user.
Identity UserHandle
Definition: blpapi_abstractsession.h:218
A service which provides access to API data (provide or consume).
blpapi_AuthOptions_t * handle() const
Definition: blpapi_authoptions.h:491
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:623
Definition: blpapi_request.h:145
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:639
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:743
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition: blpapi_abstractsession.h:686
Definition: blpapi_event.h:182
virtual int tryNextEvent(Event *event)=0
virtual Identity createIdentity()
Definition: blpapi_abstractsession.h:738
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:716
blpapi_Identity_t * handle() const
Definition: blpapi_identity.h:381