Agora Java API Reference for Android

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::base::ISyncClientObserver
Definition: NGIAgoraSyncClient.h:61
agora::base::SyncConfig
Definition: NGIAgoraSyncClient.h:79
agora::base::ISyncClientObserver::CollectionEvent
Definition: NGIAgoraSyncClient.h:63
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::util::CopyableAutoPtr
Definition: AgoraBase.h:156
agora::base::ISyncClient
Definition: NGIAgoraSyncClient.h:90