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 ~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::ISyncClientObserver
Definition: NGIAgoraSyncClient.h:61
agora::base::SyncConfig
Definition: NGIAgoraSyncClient.h:78
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:89