Agora C++ API Reference for All Platforms

NGIAgoraSyncClient.h
1 // Copyright (c) 2020 Agora.io. All rights reserved
2
3 // This program is confidential and proprietary to Agora.io.
4 // And may not be copied, reproduced, modified, disclosed to others, published
5 // or used, in whole or in part, without the express prior written permission
6 // of Agora.io.
7
8 #pragma once // NOLINT(build/header_guard)
9 #include "AgoraRefPtr.h"
10 #include "AgoraBase.h"
11 #include <functional>
12 #include <api/aosl_ref.h>
13
14 namespace agora {
15 namespace base {
16
17 enum SyncClientError {
18 kOk = 0,
19 kFail = -1,
20 kConnectSyncFailed = -2,
21 kConnectDatabaseFailed = -3,
22 kDisconnectDatabaseFailed = -4,
23 kDatabaseNotConnected = -5,
24 kCreateCollectionFailed = -6,
25 kCollectionNotCreated = -7,
26 kCollectionExisted = -8,
27 kInvalidParams = -9,
28 kNotLoggedIn = -10,
29 kQueryDocFailed = -11,
30 kDocNotCreated = -12,
31 };
32
33 typedef void(*syncClientCallback)(SyncClientError, void*);
34 typedef void(*dataBaseOpCallback)(SyncClientError, const char*, void*);
35 typedef void(*collectionOpCallback)(SyncClientError, const char*, const char*, void*);
36 typedef void(*queryDocCallback)(SyncClientError error, const char* resultJson, size_t count, bool more, void* userData);
37
38 enum SyncEventType {
39 kInserted = 0,
40 kPut = 1,
41 kDeleted = 2,
42
43 kToBeInserted = 3,
44 kToBePut = 4,
45 kToBeDeleted = 5,
46
47 kTransactionBegin = 6,
48 kTransactionEnd = 7,
49 kDocSyncEnd = 8,
50 kInitialized = 9
51 };
52
53 enum OP_Privilege {
54 OP_READ,
55 OP_WRITE
56 };
57
61 class ISyncClientObserver {
62 public:
63 struct CollectionEvent {
64 SyncEventType type;
65 const char* path;
66 const char* value;
67 };
68 virtual void onCollectionEvent(const char* previousJson, const char* curJson, const char* collection, const char* docName,
69 const CollectionEvent* events, int eventSize) = 0;
70 virtual void onDatabaseEvent(const char* databaseName, SyncClientError error) = 0;
71 virtual void onDataException(const char* databaseName, const char* collectionName) = 0;
72 virtual ~ISyncClientObserver() {};
73 };
74
78 struct SyncConfig {
79 const char* appId;
80 /* shakehand interval in seconds, 0 means enable manual shake hand */
81 uint32_t shakehand_interval;
82 /* connection timeout in seconds */
83 uint32_t connection_timeout;
84 /* compact interval in seconds */
85 uint32_t compact_interval;
86 SyncConfig() : appId(NULL), shakehand_interval(1), connection_timeout(10), compact_interval(3600 * 1000) {}
87 };
88
89 class ISyncClient : public RefCountInterface {
90 protected:
91 virtual ~ISyncClient() {}
92 public:
93
94 virtual int32_t registerSyncClientObserver(ISyncClientObserver* observer, void(*safeDeleter)(ISyncClientObserver*) = OPTIONAL_NULLPTR, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
95 virtual int32_t unregisterSyncClientObserver(ISyncClientObserver* observer) = 0;
96 // client operations
97 virtual int32_t login(const char* token, const char* channelName, user_id_t userId, syncClientCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
98 virtual int32_t queryDoc(const char* database, const char* coll, const char* range_start, const char* range_end, int64_t limits, bool doc_only, bool count_only, queryDocCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
99 virtual int32_t logout(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
100 virtual int32_t renewToken(const char* token, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
101
102 // database operations
103 virtual int32_t connectDatabase(const char* database, dataBaseOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
104 virtual int32_t disconnectDatabase(const char* database,
105 dataBaseOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
106 virtual int32_t createCollection(const char* database, const char* collection,
107 const char** readable, int readSize,
108 collectionOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
109 virtual int32_t deleteCollection(const char* database, const char* collection,
110 collectionOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
111
112 // collection operations
113 virtual int32_t subscribe(const char* database, const char* collection,
114 util::AString& snapshotJson) = 0;
115 virtual int32_t unsubscribe(const char* database, const char* collection, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
116 virtual int32_t addReadable(const char* database, const char* coll, const char* readable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
117 virtual int32_t removeReadable(const char* database, const char* coll, const char* readable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
118 virtual int32_t putDoc(const char* database, const char* collection,
119 const char* docName, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
120 virtual int32_t deleteDoc(const char* database, const char* collection,
121 const char* docName, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
122 virtual int32_t getDocs(const char* database, const char* collection,
123 util::AString* docNames, uint32_t docSize) = 0;
124
125 // document operations
126 virtual int32_t putDocValue(const char* database, const char* collection,
127 const char* docName, const char* jsonValue, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
128 virtual int32_t updateDocValue(const char* database, const char* collection,
129 const char* docName, const char* path,
130 const char* jsonValue, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
131 virtual int32_t deleteDocValue(const char* database, const char* collection,
132 const char* docName, const char* path, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
133 virtual int32_t deleteDocValues(const char* database, const char* collection, const char* docName,
134 const char** path, uint32_t pathSize,
135 aosl_ref_t ares = AOSL_REF_INVALID) = 0;
136 virtual int32_t getDocValue(const char* database, const char* collection,
137 const char* docName, util::AString& jsonValue) = 0;
138 virtual int32_t hasPath(const char* database, const char* collection,
139 const char* docName, const char* path, bool& result) = 0;
140 virtual int32_t keepAliveDoc(const char* database, const char* collection,
141 const char* docName, uint32_t ttl, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
142 virtual bool isOpPermission(const char* database, const char* collection,
143 const char* docName, OP_Privilege op) = 0;
144
145 // sync operations
146 virtual int32_t shakehand(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
147 };
148 }// namespace base
149 }// namespace agora
agora::base::ISyncClient::getDocValue
virtual int32_t getDocValue(const char *database, const char *collection, const char *docName, util::AString &jsonValue)=0
agora::base::ISyncClient::putDocValue
virtual int32_t putDocValue(const char *database, const char *collection, const char *docName, const char *jsonValue, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::logout
virtual int32_t logout(aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::syncClientCallback
void(* syncClientCallback)(SyncClientError, void *)
Definition: NGIAgoraSyncClient.h:33
agora::base::kQueryDocFailed
@ kQueryDocFailed
Definition: NGIAgoraSyncClient.h:29
agora::base::kCollectionNotCreated
@ kCollectionNotCreated
Definition: NGIAgoraSyncClient.h:25
agora::base::queryDocCallback
void(* queryDocCallback)(SyncClientError error, const char *resultJson, size_t count, bool more, void *userData)
Definition: NGIAgoraSyncClient.h:36
agora::base::OP_WRITE
@ OP_WRITE
Definition: NGIAgoraSyncClient.h:55
agora::base::kDocSyncEnd
@ kDocSyncEnd
Definition: NGIAgoraSyncClient.h:49
agora::base::SyncEventType
SyncEventType
Definition: NGIAgoraSyncClient.h:38
agora::base::kDisconnectDatabaseFailed
@ kDisconnectDatabaseFailed
Definition: NGIAgoraSyncClient.h:22
agora::base::ISyncClient::unsubscribe
virtual int32_t unsubscribe(const char *database, const char *collection, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::OP_Privilege
OP_Privilege
Definition: NGIAgoraSyncClient.h:53
agora::base::ISyncClient::deleteDocValues
virtual int32_t deleteDocValues(const char *database, const char *collection, const char *docName, const char **path, uint32_t pathSize, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kConnectSyncFailed
@ kConnectSyncFailed
Definition: NGIAgoraSyncClient.h:20
agora::base::dataBaseOpCallback
void(* dataBaseOpCallback)(SyncClientError, const char *, void *)
Definition: NGIAgoraSyncClient.h:34
agora::user_id_t
const char * user_id_t
Definition: AgoraBase.h:817
agora::base::ISyncClient::getDocs
virtual int32_t getDocs(const char *database, const char *collection, util::AString *docNames, uint32_t docSize)=0
agora::base::OP_READ
@ OP_READ
Definition: NGIAgoraSyncClient.h:54
agora::base::ISyncClient::~ISyncClient
virtual ~ISyncClient()
Definition: NGIAgoraSyncClient.h:91
agora::base::kTransactionBegin
@ kTransactionBegin
Definition: NGIAgoraSyncClient.h:47
agora::base::ISyncClient::putDoc
virtual int32_t putDoc(const char *database, const char *collection, const char *docName, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClientObserver::~ISyncClientObserver
virtual ~ISyncClientObserver()
Definition: NGIAgoraSyncClient.h:72
agora::base::SyncConfig::shakehand_interval
uint32_t shakehand_interval
Definition: NGIAgoraSyncClient.h:81
agora::base::kInvalidParams
@ kInvalidParams
Definition: NGIAgoraSyncClient.h:27
agora
Definition: AgoraAtomicOps.h:21
agora::base::kDatabaseNotConnected
@ kDatabaseNotConnected
Definition: NGIAgoraSyncClient.h:23
agora::base::ISyncClientObserver::onCollectionEvent
virtual void onCollectionEvent(const char *previousJson, const char *curJson, const char *collection, const char *docName, const CollectionEvent *events, int eventSize)=0
agora::base::SyncConfig::compact_interval
uint32_t compact_interval
Definition: NGIAgoraSyncClient.h:85
agora::base::ISyncClient::removeReadable
virtual int32_t removeReadable(const char *database, const char *coll, const char *readable, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::queryDoc
virtual int32_t queryDoc(const char *database, const char *coll, const char *range_start, const char *range_end, int64_t limits, bool doc_only, bool count_only, queryDocCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClientObserver
Definition: NGIAgoraSyncClient.h:61
agora::base::SyncConfig::appId
const char * appId
Definition: NGIAgoraSyncClient.h:79
agora::base::ISyncClient::deleteDoc
virtual int32_t deleteDoc(const char *database, const char *collection, const char *docName, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kToBePut
@ kToBePut
Definition: NGIAgoraSyncClient.h:44
agora::base::kCollectionExisted
@ kCollectionExisted
Definition: NGIAgoraSyncClient.h:26
agora::base::kTransactionEnd
@ kTransactionEnd
Definition: NGIAgoraSyncClient.h:48
agora::base::SyncConfig
Definition: NGIAgoraSyncClient.h:78
agora::base::ISyncClient::hasPath
virtual int32_t hasPath(const char *database, const char *collection, const char *docName, const char *path, bool &result)=0
agora::base::kToBeDeleted
@ kToBeDeleted
Definition: NGIAgoraSyncClient.h:45
agora::base::kOk
@ kOk
Definition: NGIAgoraSyncClient.h:18
agora::base::ISyncClient::registerSyncClientObserver
virtual int32_t registerSyncClientObserver(ISyncClientObserver *observer, void(*safeDeleter)(ISyncClientObserver *)=OPTIONAL_NULLPTR, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::collectionOpCallback
void(* collectionOpCallback)(SyncClientError, const char *, const char *, void *)
Definition: NGIAgoraSyncClient.h:35
agora::base::SyncClientError
SyncClientError
Definition: NGIAgoraSyncClient.h:17
agora::base::ISyncClientObserver::CollectionEvent::path
const char * path
Definition: NGIAgoraSyncClient.h:65
agora::base::ISyncClient::shakehand
virtual int32_t shakehand(aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kCreateCollectionFailed
@ kCreateCollectionFailed
Definition: NGIAgoraSyncClient.h:24
agora::base::kConnectDatabaseFailed
@ kConnectDatabaseFailed
Definition: NGIAgoraSyncClient.h:21
agora::base::ISyncClientObserver::CollectionEvent
Definition: NGIAgoraSyncClient.h:63
agora::base::ISyncClient::disconnectDatabase
virtual int32_t disconnectDatabase(const char *database, dataBaseOpCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClientObserver::CollectionEvent::type
SyncEventType type
Definition: NGIAgoraSyncClient.h:64
agora::base::kFail
@ kFail
Definition: NGIAgoraSyncClient.h:19
agora::base::kPut
@ kPut
Definition: NGIAgoraSyncClient.h:40
agora::base::ISyncClientObserver::onDatabaseEvent
virtual void onDatabaseEvent(const char *databaseName, SyncClientError error)=0
agora::base::ISyncClient::deleteCollection
virtual int32_t deleteCollection(const char *database, const char *collection, collectionOpCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::subscribe
virtual int32_t subscribe(const char *database, const char *collection, util::AString &snapshotJson)=0
agora::base::SyncConfig::connection_timeout
uint32_t connection_timeout
Definition: NGIAgoraSyncClient.h:83
agora::base::ISyncClient::keepAliveDoc
virtual int32_t keepAliveDoc(const char *database, const char *collection, const char *docName, uint32_t ttl, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kToBeInserted
@ kToBeInserted
Definition: NGIAgoraSyncClient.h:43
agora::base::ISyncClient::isOpPermission
virtual bool isOpPermission(const char *database, const char *collection, const char *docName, OP_Privilege op)=0
agora::base::SyncConfig::SyncConfig
SyncConfig()
Definition: NGIAgoraSyncClient.h:86
agora::base::ISyncClientObserver::CollectionEvent::value
const char * value
Definition: NGIAgoraSyncClient.h:66
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::base::ISyncClient::unregisterSyncClientObserver
virtual int32_t unregisterSyncClientObserver(ISyncClientObserver *observer)=0
agora::base::kDeleted
@ kDeleted
Definition: NGIAgoraSyncClient.h:41
agora::base::ISyncClientObserver::onDataException
virtual void onDataException(const char *databaseName, const char *collectionName)=0
agora::base::ISyncClient::login
virtual int32_t login(const char *token, const char *channelName, user_id_t userId, syncClientCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kNotLoggedIn
@ kNotLoggedIn
Definition: NGIAgoraSyncClient.h:28
agora::util::CopyableAutoPtr
Definition: AgoraBase.h:156
agora::base::ISyncClient::createCollection
virtual int32_t createCollection(const char *database, const char *collection, const char **readable, int readSize, collectionOpCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::addReadable
virtual int32_t addReadable(const char *database, const char *coll, const char *readable, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kDocNotCreated
@ kDocNotCreated
Definition: NGIAgoraSyncClient.h:30
agora::base::ISyncClient
Definition: NGIAgoraSyncClient.h:89
agora::base::ISyncClient::connectDatabase
virtual int32_t connectDatabase(const char *database, dataBaseOpCallback callback, void *userData, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kInitialized
@ kInitialized
Definition: NGIAgoraSyncClient.h:50
agora::base::ISyncClient::renewToken
virtual int32_t renewToken(const char *token, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::updateDocValue
virtual int32_t updateDocValue(const char *database, const char *collection, const char *docName, const char *path, const char *jsonValue, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::deleteDocValue
virtual int32_t deleteDocValue(const char *database, const char *collection, const char *docName, const char *path, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::kInserted
@ kInserted
Definition: NGIAgoraSyncClient.h:39