Lightstreamer C++ Client SDK
Loading...
Searching...
No Matches
LightstreamerClient.h
1/*
2 * Copyright (C) 2023 Lightstreamer Srl
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef INCLUDED_Lightstreamer_LightstreamerClient
17#define INCLUDED_Lightstreamer_LightstreamerClient
18
19#include "../Lightstreamer.h"
20#include "Lightstreamer/LoggerProvider.h"
21#include "Lightstreamer/Subscription.h"
22#include "Lightstreamer/ConnectionOptions.h"
23#include "Lightstreamer/ConnectionDetails.h"
24#include "Lightstreamer/LightstreamerError.h"
25
26namespace Lightstreamer {
27
50 HaxeObject _client;
51public:
61 static const char* initialize(void (*unhandledExceptionCallback)(const char *exceptionInfo) = nullptr) {
62 return Lightstreamer_initializeHaxeThread(unhandledExceptionCallback);
63 }
76 static void stop() {
77 Lightstreamer_stopHaxeThreadIfRunning(true);
78 }
82 static std::string libName() {
83 return LightstreamerClient_getLibName();
84 }
88 static std::string libVersion() {
89 return LightstreamerClient_getLibVersion();
90 }
127 static void setLoggerProvider(LoggerProvider* provider) {
128 LightstreamerClient_setLoggerProvider(provider);
129 }
149 static void addCookies(const std::string& uri, const std::vector<std::string>& cookies){
150 LightstreamerClient_addCookies(&uri, &cookies);
151 }
163 static std::vector<std::string> getCookies(const std::string& uri) {
164 return LightstreamerClient_getCookies(&uri);
165 }
177 static void setTrustManagerFactory(const std::string& caFile, const std::string& certificateFile, const std::string& privateKeyFile = "", const std::string& password = "", bool verifyCert = true) {
178 LightstreamerClient_setTrustManagerFactory(&caFile, &certificateFile, &privateKeyFile, &password, verifyCert);
179 }
196
198 LightstreamerClient& operator=(const LightstreamerClient&) = delete;
199
219 explicit LightstreamerClient(const std::string& serverAddress = "", const std::string& adapterSet = "") {
220 _client = LightstreamerClient_new(&serverAddress, &adapterSet);
221 connectionOptions.initDelegate(_client);
222 connectionDetails.initDelegate(_client);
223 }
224
226 LightstreamerClient_disconnect(_client);
227 Lightstreamer_releaseHaxeObject(_client);
228 }
242 void addListener(ClientListener* listener) {
243 if (listener == nullptr)
244 throw LightstreamerError("Argument cannot be null");
245 LightstreamerClient_addListener(_client, listener);
246 }
260 if (listener == nullptr)
261 throw LightstreamerError("Argument cannot be null");
262 LightstreamerClient_removeListener(_client, listener);
263 }
270 std::vector<ClientListener*> getListeners() {
271 return LightstreamerClient_getListeners(_client);
272 }
295 void connect() {
296 LightstreamerClient_connect(_client);
297 }
312 void disconnect() {
313 LightstreamerClient_disconnect(_client);
314 }
338 std::string getStatus() {
339 return LightstreamerClient_getStatus(_client);
340 }
360 void subscribe(Subscription* subscription) {
361 if (subscription == nullptr)
362 throw LightstreamerError("Argument cannot be null");
363 LightstreamerClient_subscribe(_client, subscription->_delegate);
364 }
378 void unsubscribe(Subscription* subscription) {
379 if (subscription == nullptr)
380 throw LightstreamerError("Argument cannot be null");
381 LightstreamerClient_unsubscribe(_client, subscription->_delegate);
382 }
392 std::vector<Subscription*> getSubscriptions() {
393 return LightstreamerClient_getSubscriptions(_client);
394 }
463 void sendMessage(const std::string& message, const std::string& sequence = "", int delayTimeout = -1, ClientMessageListener* listener = nullptr, bool enqueueWhileDisconnected = false) {
464 LightstreamerClient_sendMessage(_client, &message, &sequence, delayTimeout, listener, enqueueWhileDisconnected);
465 }
466};
467
468} // namespace Lightstreamer
469
470#endif // INCLUDED_Lightstreamer_LightstreamerClient
Interface to be implemented to listen to LightstreamerClient events comprehending notifications of co...
Definition ClientListener.h:32
Interface to be implemented to listen to LightstreamerClient#sendMessage events reporting a message p...
Definition ClientMessageListener.h:31
Used by LightstreamerClient to provide a basic connection properties data object.
Definition ConnectionDetails.h:33
Used by LightstreamerClient to provide an extra connection properties data object.
Definition ConnectionOptions.h:33
Facade class for the management of the communication to Lightstreamer Server.
Definition LightstreamerClient.h:49
std::vector< Subscription * > getSubscriptions()
Inquiry method that returns a list containing all the Subscription instances that are currently "acti...
Definition LightstreamerClient.h:392
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:149
static void setLoggerProvider(LoggerProvider *provider)
Static method that permits to configure the logging system used by the library.
Definition LightstreamerClient.h:127
std::vector< ClientListener * > getListeners()
Returns a list containing the ClientListener instances that were added to this client.
Definition LightstreamerClient.h:270
ConnectionDetails connectionDetails
Data object that contains the details needed to open a connection to a Lightstreamer Server.
Definition LightstreamerClient.h:195
static std::string libVersion()
The version of the library.
Definition LightstreamerClient.h:88
static std::string libName()
The name of the library.
Definition LightstreamerClient.h:82
void subscribe(Subscription *subscription)
Operation method that adds a Subscription to the list of "active" Subscriptions.
Definition LightstreamerClient.h:360
void unsubscribe(Subscription *subscription)
Operation method that removes a Subscription that is currently in the "active" state.
Definition LightstreamerClient.h:378
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:163
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:463
ConnectionOptions connectionOptions
Data object that contains options and policies for the connection to the server.
Definition LightstreamerClient.h:187
void removeListener(ClientListener *listener)
Removes a listener from the LightstreamerClient instance so that it will not receive events anymore.
Definition LightstreamerClient.h:259
static void stop()
Stops the Lightstreamer thread, blocking until the thread has completed.
Definition LightstreamerClient.h:76
static const char * initialize(void(*unhandledExceptionCallback)(const char *exceptionInfo)=nullptr)
Initializes a thread that executes the Lightstreamer functions.
Definition LightstreamerClient.h:61
void disconnect()
Operation method that requests to close the Session opened against the configured Lightstreamer Serve...
Definition LightstreamerClient.h:312
void connect()
Operation method that requests to open a Session against the configured Lightstreamer Server.
Definition LightstreamerClient.h:295
std::string getStatus()
Inquiry method that gets the current client status and transport (when applicable).
Definition LightstreamerClient.h:338
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:177
void addListener(ClientListener *listener)
Adds a listener that will receive events from the LightstreamerClient instance.
Definition LightstreamerClient.h:242
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:219
The LightstreamerError class provides a base class for exceptions thrown by the library.
Definition LightstreamerError.h:27
Simple interface to be implemented to provide custom log consumers to the library.
Definition LoggerProvider.h:29
Class representing a Subscription to be submitted to a Lightstreamer Server.
Definition Subscription.h:71