Update to version 2

This commit is contained in:
2022-11-18 13:42:30 +01:00
parent 284fef3ec2
commit 8934eeac6b
23 changed files with 5109 additions and 5695 deletions

View File

@@ -34,6 +34,7 @@
#include <gempa/caps/packet.h>
#include <gempa/caps/socket.h>
#include <gempa/caps/url.h>
#include <gempa/caps/version.h>
#include <gempa/caps/pluginpacket.h>
@@ -70,8 +71,9 @@ class SC_GEMPA_CAPS_API Plugin {
size_t maxBytesBuffered;
};
typedef std::vector<char> Buffer;
typedef boost::shared_ptr<Buffer> BufferPtr;
typedef std::vector<char> Buffer;
typedef boost::shared_ptr<Buffer> BufferPtr;
typedef std::deque<PacketPtr> PacketBuffer;
#if !defined(CAPS_FEATURES_BACKFILLING) || CAPS_FEATURES_BACKFILLING
typedef std::list<PacketPtr> BackfillingBuffer;
@@ -139,11 +141,19 @@ class SC_GEMPA_CAPS_API Plugin {
*/
void setEncoderFactory(EncoderFactory *factory);
void setHost(const std::string &host) { _host = host; }
const std::string &host() const { return _host; }
/**
* @brief Parses connection parameters from address string. Format
* is [[caps|capss]://][user:pass@]host[:port]
* @param addr The address of the caps server as string
* @param defaultPort The default port used when the port is omitted
*/
bool setAddress(const std::string &addr, uint16_t defaultPort = 18003);
void setPort(unsigned short port) { _port = port; }
unsigned short port() const { return _port; }
void setHost(const std::string &host) { _url.host = host; }
const std::string &host() const { return _url.host; }
void setPort(unsigned short port) { _url.port = port; }
unsigned short port() const { return _url.port; }
void setBufferSize(size_t bufferSize) { _bufferSize = bufferSize; }
size_t bufferSize() const { return _bufferSize; }
@@ -159,8 +169,8 @@ class SC_GEMPA_CAPS_API Plugin {
* @param password The password
*/
void setCredentials(const std::string &user, const std::string &password) {
_user = user;
_password = password;
_url.user = user;
_url.password = password;
}
/**
@@ -232,12 +242,42 @@ class SC_GEMPA_CAPS_API Plugin {
const std::string &data);
#endif
void flushEncoders();
void dumpPackets(bool enable);
/**
* @brief Returns the internal packet buffer that
* keeps packets until they have been acknowledged
* by CAPS
* @return The interal packet buffer
*/
const PacketBuffer &packetBuffer() const {
return _packetBuffer;
}
/**
* @brief Sets the agent string. Allows the server to
* identify the application that sends data.
* @param agent The agent string
*/
void setAgent(const std::string &agent);
const char *version() {
return LIB_CAPS_VERSION_NAME;
}
protected:
/**
* @brief Sends HELLO request and parses API version
* from server response. If the server does not support
* the API feature the method sets the version to 0.
* @param version The CAPS API version, e.g., 5
* @return True on success
*/
bool getAPIVersion(int &version);
private:
typedef std::deque<PacketPtr> PacketBuffer;
typedef boost::shared_ptr<Encoder> EncoderPtr;
struct EncoderItem {
@@ -250,6 +290,7 @@ class SC_GEMPA_CAPS_API Plugin {
private:
bool connect();
void disconnect();
void dumpPacket(Packet *packet);
bool isConnected() const;
Encoder* getEncoder(PacketPtr packet);
bool readResponse(unsigned int sec = 0);
@@ -265,7 +306,6 @@ class SC_GEMPA_CAPS_API Plugin {
void tryFlushBackfillingBuffer(StreamState &state);
void trimBackfillingBuffer(StreamState &state);
bool flush();
void flushEncoders();
bool send(char *data, int len, int timeout = 60);
void wait();
@@ -279,8 +319,6 @@ class SC_GEMPA_CAPS_API Plugin {
PacketBuffer _packetBuffer;
bool _packetBufferDirty;
size_t _bytesBuffered;
std::string _host;
unsigned short _port;
char _responseBuf[512];
int _responseBufIdx;
fd_set _readFDs;
@@ -306,13 +344,15 @@ class SC_GEMPA_CAPS_API Plugin {
PacketAckFunc _packetAckFunc;
std::string _user;
std::string _password;
Url _url;
#if !defined(CAPS_FEATURES_SSL) || CAPS_FEATURES_SSL
bool _useSSL;
#endif
Stats _stats;
TimeSpan _maxFutureEndTime;
bool _dumpPackets;
std::string _agent;
};
typedef boost::shared_ptr<Plugin> PluginPtr;