BLPAPI C++  3.24.6
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 
200  const char **sessionName,
201  size_t *size);
202 
203 #ifdef __cplusplus
204 }
205 
206 #include <cassert>
207 
208 #ifndef INCLUDED_VECTOR
209 #include <vector>
210 #define INCLUDED_VECTOR
211 #endif
212 
220 namespace BloombergLP {
221 namespace blpapi {
222 
224 
225 // =====================
226 // class AbstractSession
227 // =====================
228 
287 
288  blpapi_AbstractSession_t *d_handle_p;
289 
290  private:
291  // NOT IMPLEMENTED
293  AbstractSession& operator=(const AbstractSession&);
294 
295  protected:
297  AbstractSession();
302  void initAbstractSessionHandle(blpapi_AbstractSession_t *handle);
306 
308  public:
309  virtual ~AbstractSession();
314  // MANIPULATORS
315  virtual bool start() = 0;
327  virtual bool startAsync() = 0;
339  virtual void stop() = 0;
351  virtual void stopAsync() = 0;
363  virtual Event nextEvent(int timeout = 0) = 0;
379  virtual int tryNextEvent(Event *event) = 0;
387  virtual bool openService(const char *serviceIdentifier);
405  virtual CorrelationId openServiceAsync(const char *serviceIdentifier,
406  const CorrelationId& correlationId = CorrelationId());
424  const Request& authorizationRequest,
425  Identity *identity,
426  const CorrelationId& correlationId = CorrelationId(),
427  EventQueue *eventQueue = 0);
455  virtual void cancel(const CorrelationId& correlationId);
474  virtual void cancel(const std::vector<CorrelationId>& correlationIds);
495  virtual void cancel(
496  const CorrelationId *correlationIds, size_t numCorrelationIds);
518  const CorrelationId& correlationId = CorrelationId(),
519  EventQueue *eventQueue = 0);
529  virtual CorrelationId generateToken(const char *userId,
530  const char *ipAddress,
531  const CorrelationId& correlationId = CorrelationId(),
532  EventQueue *eventQueue = 0);
543  virtual Service getService(const char *serviceIdentifier) const;
557  virtual Identity createIdentity();
564  const CorrelationId& cid = CorrelationId());
583  const CorrelationId& correlationId = CorrelationId());
595  std::string sessionName();
600  blpapi_AbstractSession_t *abstractSessionHandle() const;
605 
615 };
616 
620 //=============================================================================
621 // INLINE FUNCTION DEFINITIONS
622 //=============================================================================
623 
624 // ---------------------
625 // class AbstractSession
626 // ---------------------
627 
628 inline AbstractSession::AbstractSession()
629  : d_handle_p(0)
630 {
631 }
632 
634 
635 inline void AbstractSession::initAbstractSessionHandle(
636  blpapi_AbstractSession_t *handle)
637 {
638  d_handle_p = handle;
639 }
640 
641 inline Service AbstractSession::getService(const char *serviceIdentifier) const
642 {
643  blpapi_Service_t *service;
645  d_handle_p, &service, serviceIdentifier));
646  return Service(service);
647 }
648 
650  const Request& authorizationRequest,
651  Identity *identity,
652  const CorrelationId& correlationId,
653  EventQueue *eventQueue)
654 {
655  assert(identity);
656 
657  CorrelationId retCorrelationId(correlationId);
658 
661  authorizationRequest.handle(),
662  identity->handle(),
663  const_cast<blpapi_CorrelationId_t *>(
664  &retCorrelationId.impl()),
665  eventQueue ? eventQueue->handle() : 0,
666  0,
667  0));
668 
669  return retCorrelationId;
670 }
671 
672 inline void AbstractSession::cancel(const CorrelationId& correlationId)
673 {
674  blpapi_AbstractSession_cancel(d_handle_p, &correlationId.impl(), 1, 0, 0);
675 }
676 
678  const std::vector<CorrelationId>& correlationIds)
679 {
680  if (!correlationIds.size()) {
681  return;
682  }
683  cancel(&correlationIds[0], correlationIds.size());
684 }
685 
687  const CorrelationId *correlationIds, size_t numCorrelationIds)
688 {
690  reinterpret_cast<const blpapi_CorrelationId_t *>(correlationIds),
691  numCorrelationIds,
692  0,
693  0);
694 }
695 
697  const CorrelationId& correlationId, EventQueue *eventQueue)
698 {
699  CorrelationId retCorrelationId(correlationId);
700 
703  &retCorrelationId.impl(),
704  eventQueue ? eventQueue->handle() : 0));
705 
706  return retCorrelationId;
707 }
708 
710  const char *ipAddress,
711  const CorrelationId& correlationId,
712  EventQueue *eventQueue)
713 {
714  CorrelationId retCorrelationId(correlationId);
715 
718  &retCorrelationId.impl(),
719  userId,
720  ipAddress,
721  eventQueue ? eventQueue->handle() : 0));
722 
723  return retCorrelationId;
724 }
725 
726 inline bool AbstractSession::openService(const char *serviceIdentifier)
727 {
728  return blpapi_AbstractSession_openService(d_handle_p, serviceIdentifier)
729  ? false
730  : true;
731 }
732 
734  const char *serviceIdentifier, const CorrelationId& correlationId)
735 {
736  blpapi_CorrelationId_t retv = correlationId.impl();
738  d_handle_p, serviceIdentifier, &retv));
739 
740  return CorrelationId(retv);
741 }
742 
744 {
746 }
747 
749 {
751 }
752 
754  const AuthOptions& authOptions, const CorrelationId& cid)
755 {
756  blpapi_CorrelationId_t cidHandle = cid.impl();
757 
760  d_handle_p, authOptions.handle(), &cidHandle));
761 
762  return CorrelationId(cidHandle);
763 }
764 
766  const CorrelationId& correlationId)
767 {
768  blpapi_Identity_t *identity = NULL;
769 
772  d_handle_p, &correlationId.impl(), &identity));
773 
774  return Identity(identity);
775 }
776 
777 inline std::string AbstractSession::sessionName()
778 {
779  const char *sessionName = nullptr;
780  size_t size = 0;
781 
784  d_handle_p, &sessionName, &size));
785  return std::string(sessionName, size);
786 }
787 
788 inline blpapi_AbstractSession_t *AbstractSession::abstractSessionHandle() const
789 {
790  return d_handle_p;
791 }
792 
793 } // close namespace blpapi
794 } // close namespace BloombergLP
795 
796 #endif // #ifdef __cplusplus
797 #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:672
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:641
virtual CorrelationId openServiceAsync(const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:733
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
UserHandle createUserHandle()
Definition: blpapi_abstractsession.h:743
blpapi_Request_t * handle() const
Definition: blpapi_request.h:733
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:220
#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:286
Definition: blpapi_event.h:386
Identity getAuthorizedIdentity(const CorrelationId &correlationId=CorrelationId())
Definition: blpapi_abstractsession.h:765
Provide access to the entitlements for a user.
Identity UserHandle
Definition: blpapi_abstractsession.h:223
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:633
Definition: blpapi_request.h:146
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:649
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:753
virtual CorrelationId generateToken(const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0)
Definition: blpapi_abstractsession.h:696
Definition: blpapi_event.h:196
std::string sessionName()
Definition: blpapi_abstractsession.h:777
virtual int tryNextEvent(Event *event)=0
struct blpapi_Request blpapi_Request_t
Definition: blpapi_dispatchtbl.h:81
virtual Identity createIdentity()
Definition: blpapi_abstractsession.h:748
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:726
blpapi_Identity_t * handle() const
Definition: blpapi_identity.h:381