Agora C++ API Reference for All Platforms

Loading...
Searching...
No Matches
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 void onCollectionSyncCompleted() = 0;
73 virtual ~ISyncClientObserver() {};
74};
75
79 struct SyncConfig {
80 const char* appId;
81 /* shakehand interval in seconds, 0 means enable manual shake hand */
82 uint32_t shakehand_interval;
83 /* connection timeout in seconds */
84 uint32_t connection_timeout;
85 /* compact interval in seconds */
86 uint32_t compact_interval;
87 SyncConfig() : appId(NULL), shakehand_interval(1), connection_timeout(10), compact_interval(3600 * 1000) {}
88};
89
90 class ISyncClient : public RefCountInterface {
91 protected:
92 virtual ~ISyncClient() {}
93 public:
94
95 virtual int32_t registerSyncClientObserver(ISyncClientObserver* observer, void(*safeDeleter)(ISyncClientObserver*) = OPTIONAL_NULLPTR, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
96 virtual int32_t unregisterSyncClientObserver(ISyncClientObserver* observer) = 0;
97 // client operations
98 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;
99 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;
100 virtual int32_t logout(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
101 virtual int32_t renewToken(const char* token, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
102
103 // database operations
104 virtual int32_t connectDatabase(const char* database, dataBaseOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
105 virtual int32_t disconnectDatabase(const char* database,
106 dataBaseOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
107 virtual int32_t createCollection(const char* database, const char* collection,
108 const char** readable, int readSize,
109 collectionOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
110 virtual int32_t deleteCollection(const char* database, const char* collection,
111 collectionOpCallback callback, void* userData, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
112
113 // collection operations
114 virtual int32_t subscribe(const char* database, const char* collection,
115 util::AString& snapshotJson) = 0;
116 virtual int32_t unsubscribe(const char* database, const char* collection, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
117 virtual int32_t addReadable(const char* database, const char* coll, const char* readable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
118 virtual int32_t removeReadable(const char* database, const char* coll, const char* readable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
119 virtual int32_t putDoc(const char* database, const char* collection,
120 const char* docName, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
121 virtual int32_t deleteDoc(const char* database, const char* collection,
122 const char* docName, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
123 virtual int32_t getDocs(const char* database, const char* collection,
124 util::AString* docNames, uint32_t docSize) = 0;
125
126 // document operations
127 virtual int32_t putDocValue(const char* database, const char* collection,
128 const char* docName, const char* jsonValue, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
129 virtual int32_t updateDocValue(const char* database, const char* collection,
130 const char* docName, const char* path,
131 const char* jsonValue, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
132 virtual int32_t deleteDocValue(const char* database, const char* collection,
133 const char* docName, const char* path, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
134 virtual int32_t deleteDocValues(const char* database, const char* collection, const char* docName,
135 const char** path, uint32_t pathSize,
136 aosl_ref_t ares = AOSL_REF_INVALID) = 0;
137 virtual int32_t getDocValue(const char* database, const char* collection,
138 const char* docName, util::AString& jsonValue) = 0;
139 virtual int32_t hasPath(const char* database, const char* collection,
140 const char* docName, const char* path, bool& result) = 0;
141 virtual int32_t keepAliveDoc(const char* database, const char* collection,
142 const char* docName, uint32_t ttl, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
143 virtual bool isOpPermission(const char* database, const char* collection,
144 const char* docName, OP_Privilege op) = 0;
145
146 // sync operations
147 virtual int32_t shakehand(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
148};
149}// namespace base
150}// namespace agora
agora::RefCountInterface
Definition AgoraRefPtr.h:31
agora::base::ISyncClient
Definition NGIAgoraSyncClient.h:90
agora::base::ISyncClient::unsubscribe
virtual int32_t unsubscribe(const char *database, const char *collection, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::~ISyncClient
virtual ~ISyncClient()
Definition NGIAgoraSyncClient.h:92
agora::base::ISyncClient::isOpPermission
virtual bool isOpPermission(const char *database, const char *collection, const char *docName, OP_Privilege op)=0
agora::base::ISyncClient::logout
virtual int32_t logout(aosl_ref_t ares=AOSL_REF_INVALID)=0
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::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::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::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::deleteDoc
virtual int32_t deleteDoc(const char *database, const char *collection, const char *docName, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::base::ISyncClient::renewToken
virtual int32_t renewToken(const char *token, 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::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::putDoc
virtual int32_t putDoc(const char *database, const char *collection, const char *docName, aosl_ref_t ares=AOSL_REF_INVALID)=0
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::ISyncClient::subscribe
virtual int32_t subscribe(const char *database, const char *collection, util::AString &snapshotJson)=0
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::ISyncClient::shakehand
virtual int32_t shakehand(aosl_ref_t ares=AOSL_REF_INVALID)=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::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::ISyncClient::registerSyncClientObserver
virtual int32_t registerSyncClientObserver(ISyncClientObserver *observer, void(*safeDeleter)(ISyncClientObserver *)=OPTIONAL_NULLPTR, aosl_ref_t ares=AOSL_REF_INVALID)=0
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::ISyncClient::unregisterSyncClientObserver
virtual int32_t unregisterSyncClientObserver(ISyncClientObserver *observer)=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::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::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::getDocs
virtual int32_t getDocs(const char *database, const char *collection, util::AString *docNames, uint32_t docSize)=0
agora::base::ISyncClient::getDocValue
virtual int32_t getDocValue(const char *database, const char *collection, const char *docName, util::AString &jsonValue)=0
agora::base::ISyncClientObserver
Definition NGIAgoraSyncClient.h:61
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::ISyncClientObserver::~ISyncClientObserver
virtual ~ISyncClientObserver()
Definition NGIAgoraSyncClient.h:73
agora::base::ISyncClientObserver::onDatabaseEvent
virtual void onDatabaseEvent(const char *databaseName, SyncClientError error)=0
agora::base::ISyncClientObserver::onCollectionSyncCompleted
virtual void onCollectionSyncCompleted()=0
agora::base::ISyncClientObserver::onDataException
virtual void onDataException(const char *databaseName, const char *collectionName)=0
agora::base
Definition IAgoraService.h:73
agora::base::OP_Privilege
OP_Privilege
Definition NGIAgoraSyncClient.h:53
agora::base::OP_WRITE
@ OP_WRITE
Definition NGIAgoraSyncClient.h:55
agora::base::OP_READ
@ OP_READ
Definition NGIAgoraSyncClient.h:54
agora::base::dataBaseOpCallback
void(* dataBaseOpCallback)(SyncClientError, const char *, void *)
Definition NGIAgoraSyncClient.h:34
agora::base::queryDocCallback
void(* queryDocCallback)(SyncClientError error, const char *resultJson, size_t count, bool more, void *userData)
Definition NGIAgoraSyncClient.h:36
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::kCollectionNotCreated
@ kCollectionNotCreated
Definition NGIAgoraSyncClient.h:25
agora::base::kDisconnectDatabaseFailed
@ kDisconnectDatabaseFailed
Definition NGIAgoraSyncClient.h:22
agora::base::kOk
@ kOk
Definition NGIAgoraSyncClient.h:18
agora::base::kDatabaseNotConnected
@ kDatabaseNotConnected
Definition NGIAgoraSyncClient.h:23
agora::base::kCollectionExisted
@ kCollectionExisted
Definition NGIAgoraSyncClient.h:26
agora::base::kConnectSyncFailed
@ kConnectSyncFailed
Definition NGIAgoraSyncClient.h:20
agora::base::kConnectDatabaseFailed
@ kConnectDatabaseFailed
Definition NGIAgoraSyncClient.h:21
agora::base::kNotLoggedIn
@ kNotLoggedIn
Definition NGIAgoraSyncClient.h:28
agora::base::kInvalidParams
@ kInvalidParams
Definition NGIAgoraSyncClient.h:27
agora::base::kDocNotCreated
@ kDocNotCreated
Definition NGIAgoraSyncClient.h:30
agora::base::kQueryDocFailed
@ kQueryDocFailed
Definition NGIAgoraSyncClient.h:29
agora::base::kFail
@ kFail
Definition NGIAgoraSyncClient.h:19
agora::base::kCreateCollectionFailed
@ kCreateCollectionFailed
Definition NGIAgoraSyncClient.h:24
agora::base::syncClientCallback
void(* syncClientCallback)(SyncClientError, void *)
Definition NGIAgoraSyncClient.h:33
agora::base::SyncEventType
SyncEventType
Definition NGIAgoraSyncClient.h:38
agora::base::kToBeInserted
@ kToBeInserted
Definition NGIAgoraSyncClient.h:43
agora::base::kInserted
@ kInserted
Definition NGIAgoraSyncClient.h:39
agora::base::kTransactionEnd
@ kTransactionEnd
Definition NGIAgoraSyncClient.h:48
agora::base::kTransactionBegin
@ kTransactionBegin
Definition NGIAgoraSyncClient.h:47
agora::base::kPut
@ kPut
Definition NGIAgoraSyncClient.h:40
agora::base::kDocSyncEnd
@ kDocSyncEnd
Definition NGIAgoraSyncClient.h:49
agora::base::kDeleted
@ kDeleted
Definition NGIAgoraSyncClient.h:41
agora::base::kToBeDeleted
@ kToBeDeleted
Definition NGIAgoraSyncClient.h:45
agora::base::kInitialized
@ kInitialized
Definition NGIAgoraSyncClient.h:50
agora::base::kToBePut
@ kToBePut
Definition NGIAgoraSyncClient.h:44
agora::util::AString
CopyableAutoPtr< IString > AString
Definition AgoraBase.h:182
agora
Definition AgoraAtomicOps.h:21
agora::user_id_t
const char * user_id_t
Definition AgoraBase.h:849
agora::base::ISyncClientObserver::CollectionEvent
Definition NGIAgoraSyncClient.h:63
agora::base::ISyncClientObserver::CollectionEvent::path
const char * path
Definition NGIAgoraSyncClient.h:65
agora::base::ISyncClientObserver::CollectionEvent::type
SyncEventType type
Definition NGIAgoraSyncClient.h:64
agora::base::ISyncClientObserver::CollectionEvent::value
const char * value
Definition NGIAgoraSyncClient.h:66
agora::base::SyncConfig::compact_interval
uint32_t compact_interval
Definition NGIAgoraSyncClient.h:86
agora::base::SyncConfig::SyncConfig
SyncConfig()
Definition NGIAgoraSyncClient.h:87
agora::base::SyncConfig::connection_timeout
uint32_t connection_timeout
Definition NGIAgoraSyncClient.h:84
agora::base::SyncConfig::shakehand_interval
uint32_t shakehand_interval
Definition NGIAgoraSyncClient.h:82
agora::base::SyncConfig::appId
const char * appId
Definition NGIAgoraSyncClient.h:80