Lightstreamer C++ Client SDK
Loading...
Searching...
No Matches
LightstreamerClient.h
1#ifndef INCLUDED_Lightstreamer_LightstreamerClient
2#define INCLUDED_Lightstreamer_LightstreamerClient
3
4#include "../Lightstreamer.h"
5#include "Lightstreamer/LoggerProvider.h"
6#include "Lightstreamer/Subscription.h"
7#include "Lightstreamer/ConnectionOptions.h"
8#include "Lightstreamer/ConnectionDetails.h"
9#include "Lightstreamer/LightstreamerError.h"
10
11namespace Lightstreamer {
12
35 HaxeObject _client;
36public:
46 static const char* initialize(void (*unhandledExceptionCallback)(const char *exceptionInfo) = nullptr) {
47 return Lightstreamer_initializeHaxeThread(unhandledExceptionCallback);
48 }
61 static void stop() {
62 Lightstreamer_stopHaxeThreadIfRunning(true);
63 }
67 static std::string libName() {
68 return LightstreamerClient_getLibName();
69 }
73 static std::string libVersion() {
74 return LightstreamerClient_getLibVersion();
75 }
112 static void setLoggerProvider(LoggerProvider* provider) {
113 LightstreamerClient_setLoggerProvider(provider);
114 }
134 static void addCookies(const std::string& uri, const std::vector<std::string>& cookies){
135 LightstreamerClient_addCookies(&uri, &cookies);
136 }
148 static std::vector<std::string> getCookies(const std::string& uri) {
149 return LightstreamerClient_getCookies(&uri);
150 }
162 static void setTrustManagerFactory(const std::string& caFile, const std::string& certificateFile, const std::string& privateKeyFile = "", const std::string& password = "", bool verifyCert = true) {
163 LightstreamerClient_setTrustManagerFactory(&caFile, &certificateFile, &privateKeyFile, &password, verifyCert);
164 }
181
183 LightstreamerClient& operator=(const LightstreamerClient&) = delete;
184
204 explicit LightstreamerClient(const std::string& serverAddress = "", const std::string& adapterSet = "") {
205 _client = LightstreamerClient_new(&serverAddress, &adapterSet);
206 connectionOptions.initDelegate(_client);
207 connectionDetails.initDelegate(_client);
208 }
209
211 LightstreamerClient_disconnect(_client);
212 Lightstreamer_releaseHaxeObject(_client);
213 }
227 void addListener(ClientListener* listener) {
228 if (listener == nullptr)
229 throw LightstreamerError("Argument cannot be null");
230 LightstreamerClient_addListener(_client, listener);
231 }
245 if (listener == nullptr)
246 throw LightstreamerError("Argument cannot be null");
247 LightstreamerClient_removeListener(_client, listener);
248 }
255 std::vector<ClientListener*> getListeners() {
256 return LightstreamerClient_getListeners(_client);
257 }
280 void connect() {
281 LightstreamerClient_connect(_client);
282 }
297 void disconnect() {
298 LightstreamerClient_disconnect(_client);
299 }
323 std::string getStatus() {
324 return LightstreamerClient_getStatus(_client);
325 }
345 void subscribe(Subscription* subscription) {
346 if (subscription == nullptr)
347 throw LightstreamerError("Argument cannot be null");
348 LightstreamerClient_subscribe(_client, subscription->_delegate);
349 }
363 void unsubscribe(Subscription* subscription) {
364 if (subscription == nullptr)
365 throw LightstreamerError("Argument cannot be null");
366 LightstreamerClient_unsubscribe(_client, subscription->_delegate);
367 }
377 std::vector<Subscription*> getSubscriptions() {
378 return LightstreamerClient_getSubscriptions(_client);
379 }
446 void sendMessage(const std::string& message, const std::string& sequence = "", int delayTimeout = -1, ClientMessageListener* listener = nullptr, bool enqueueWhileDisconnected = false) {
447 LightstreamerClient_sendMessage(_client, &message, &sequence, delayTimeout, listener, enqueueWhileDisconnected);
448 }
449};
450
451} // namespace Lightstreamer
452
453#endif // INCLUDED_Lightstreamer_LightstreamerClient
Interface to be implemented to listen to LightstreamerClient events comprehending notifications of co...
Definition ClientListener.h:17
Interface to be implemented to listen to LightstreamerClient#sendMessage events reporting a message p...
Definition ClientMessageListener.h:16
Used by LightstreamerClient to provide a basic connection properties data object.
Definition ConnectionDetails.h:18
Used by LightstreamerClient to provide an extra connection properties data object.
Definition ConnectionOptions.h:18
Facade class for the management of the communication to Lightstreamer Server.
Definition LightstreamerClient.h:34
std::vector< Subscription * > getSubscriptions()
Inquiry method that returns a list containing all the Subscription instances that are currently "acti...
Definition LightstreamerClient.h:377
static void addCookies(const std::string &uri, const std::vector< std::string > &cookies)
Static method that can be used to share cookies between connections to the Server (performed by this ...
Definition LightstreamerClient.h:134
static void setLoggerProvider(LoggerProvider *provider)
Static method that permits to configure the logging system used by the library.
Definition LightstreamerClient.h:112
std::vector< ClientListener * > getListeners()
Returns a list containing the ClientListener instances that were added to this client.
Definition LightstreamerClient.h:255
ConnectionDetails connectionDetails
Data object that contains the details needed to open a connection to a Lightstreamer Server.
Definition LightstreamerClient.h:180
static std::string libVersion()
The version of the library.
Definition LightstreamerClient.h:73
static std::string libName()
The name of the library.
Definition LightstreamerClient.h:67
void subscribe(Subscription *subscription)
Operation method that adds a Subscription to the list of "active" Subscriptions.
Definition LightstreamerClient.h:345
void unsubscribe(Subscription *subscription)
Operation method that removes a Subscription that is currently in the "active" state.
Definition LightstreamerClient.h:363
static std::vector< std::string > getCookies(const std::string &uri)
Static inquiry method that can be used to share cookies between connections to the Server (performed ...
Definition LightstreamerClient.h:148
void sendMessage(const std::string &message, const std::string &sequence="", int delayTimeout=-1, ClientMessageListener *listener=nullptr, bool enqueueWhileDisconnected=false)
Operation method that sends a message to the Server.
Definition LightstreamerClient.h:446
ConnectionOptions connectionOptions
Data object that contains options and policies for the connection to the server.
Definition LightstreamerClient.h:172
void removeListener(ClientListener *listener)
Removes a listener from the LightstreamerClient instance so that it will not receive events anymore.
Definition LightstreamerClient.h:244
static void stop()
Stops the Lightstreamer thread, blocking until the thread has completed.
Definition LightstreamerClient.h:61
static const char * initialize(void(*unhandledExceptionCallback)(const char *exceptionInfo)=nullptr)
Initializes a thread that executes the Lightstreamer functions.
Definition LightstreamerClient.h:46
void disconnect()
Operation method that requests to close the Session opened against the configured Lightstreamer Serve...
Definition LightstreamerClient.h:297
void connect()
Operation method that requests to open a Session against the configured Lightstreamer Server.
Definition LightstreamerClient.h:280
std::string getStatus()
Inquiry method that gets the current client status and transport (when applicable).
Definition LightstreamerClient.h:323
static void setTrustManagerFactory(const std::string &caFile, const std::string &certificateFile, const std::string &privateKeyFile="", const std::string &password="", bool verifyCert=true)
Provides a mean to control the way TLS certificates are evaluated, with the possibility to accept unt...
Definition LightstreamerClient.h:162
void addListener(ClientListener *listener)
Adds a listener that will receive events from the LightstreamerClient instance.
Definition LightstreamerClient.h:227
LightstreamerClient(const std::string &serverAddress="", const std::string &adapterSet="")
Creates an object to be configured to connect to a Lightstreamer server and to handle all the communi...
Definition LightstreamerClient.h:204
The LightstreamerError class provides a base class for exceptions thrown by the library.
Definition LightstreamerError.h:12
Simple interface to be implemented to provide custom log consumers to the library.
Definition LoggerProvider.h:14
Class representing a Subscription to be submitted to a Lightstreamer Server.
Definition Subscription.h:56