123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #ifndef __mqtt_iclient_persistence_h
- #define __mqtt_iclient_persistence_h
- #include "MQTTAsync.h"
- #include "mqtt/types.h"
- #include "mqtt/buffer_view.h"
- #include "mqtt/string_collection.h"
- #include <vector>
- namespace mqtt {
- inline void* persistence_malloc(size_t n) {
- return MQTTAsync_malloc(n);
- }
- inline void persistence_free(void* p) {
- MQTTAsync_free(p);
- }
- class iclient_persistence
- {
- friend class async_client;
- friend class mock_persistence;
-
- static int persistence_open(void** handle, const char* clientID, const char* serverURI, void* context);
- static int persistence_close(void* handle);
- static int persistence_put(void* handle, char* key, int bufcount, char* buffers[], int buflens[]);
- static int persistence_get(void* handle, char* key, char** buffer, int* buflen);
- static int persistence_remove(void* handle, char* key);
- static int persistence_keys(void* handle, char*** keys, int* nkeys);
- static int persistence_clear(void* handle);
- static int persistence_containskey(void* handle, char* key);
- public:
-
- using ptr_t = std::shared_ptr<iclient_persistence>;
-
- using const_ptr_t = std::shared_ptr<const iclient_persistence>;
-
- virtual ~iclient_persistence() {}
-
- virtual void open(const string& clientId, const string& serverURI) =0;
-
- virtual void close() =0;
-
- virtual void clear() =0;
-
- virtual bool contains_key(const string& key) =0;
-
- virtual string_collection keys() const =0;
-
- virtual void put(const string& key, const std::vector<string_view>& bufs) =0;
-
- virtual string get(const string& key) const =0;
-
- virtual void remove(const string& key) =0;
- };
- using iclient_persistence_ptr = iclient_persistence::ptr_t;
- using const_iclient_persistence_ptr = iclient_persistence::const_ptr_t;
- }
- #endif
|