1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DISTRIBUTED_RDB_SERVICE_STUB_H
17 #define DISTRIBUTED_RDB_SERVICE_STUB_H
18 
19 #include "iremote_stub.h"
20 #include "rdb_service.h"
21 #include "rdb_notifier.h"
22 #include "feature/feature_system.h"
23 
24 namespace OHOS::DistributedRdb {
25 using RdbServiceCode = OHOS::DistributedRdb::RelationalStore::RdbServiceInterfaceCode;
26 
27 class RdbServiceStub : public RdbService, public DistributedData::FeatureSystem::Feature {
28 public:
29     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService");
30     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override;
31 
32 private:
33     static bool CheckInterfaceToken(MessageParcel& data);
34 
35     int32_t OnRemoteObtainDistributedTableName(MessageParcel& data, MessageParcel& reply);
36 
37     int32_t OnDelete(MessageParcel& data, MessageParcel& reply);
38 
39     int32_t OnRemoteInitNotifier(MessageParcel& data, MessageParcel& reply);
40 
41     int32_t OnRemoteSetDistributedTables(MessageParcel& data, MessageParcel& reply);
42 
43     int32_t OnRemoteDoSync(MessageParcel& data, MessageParcel& reply);
44 
45     int32_t OnRemoteDoAsync(MessageParcel& data, MessageParcel& reply);
46 
47     int32_t OnRemoteDoSubscribe(MessageParcel& data, MessageParcel& reply);
48 
49     int32_t OnRemoteDoUnSubscribe(MessageParcel& data, MessageParcel& reply);
50 
51     int32_t OnRemoteRegisterDetailProgressObserver(MessageParcel& data, MessageParcel& reply);
52 
53     int32_t OnRemoteUnregisterDetailProgressObserver(MessageParcel& data, MessageParcel& reply);
54 
55     int32_t OnRemoteDoRemoteQuery(MessageParcel& data, MessageParcel& reply);
56 
57     int32_t OnRemoteNotifyDataChange(MessageParcel& data, MessageParcel& reply);
58 
59     int32_t OnRemoteSetSearchable(MessageParcel& data, MessageParcel& reply);
60 
61     int32_t OnRemoteQuerySharingResource(MessageParcel& data, MessageParcel& reply);
62 
63     int32_t OnBeforeOpen(MessageParcel& data, MessageParcel& reply);
64 
65     int32_t OnAfterOpen(MessageParcel& data, MessageParcel& reply);
66 
67     int32_t OnDisable(MessageParcel& data, MessageParcel& reply);
68 
69     int32_t OnEnable(MessageParcel& data, MessageParcel& reply);
70 
71     int32_t OnGetPassword(MessageParcel& data, MessageParcel& reply);
72 
73     int32_t OnLockCloudContainer(MessageParcel& data, MessageParcel& reply);
74 
75     int32_t OnUnlockCloudContainer(MessageParcel& data, MessageParcel& reply);
76 
77     int32_t OnGetDebugInfo(MessageParcel& data, MessageParcel& reply);
78 
79     using RequestHandle = int (RdbServiceStub::*)(MessageParcel &, MessageParcel &);
80     static constexpr RequestHandle HANDLERS[static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_MAX)] = {
81         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_OBTAIN_TABLE)] =
82             &RdbServiceStub::OnRemoteObtainDistributedTableName,
83         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_INIT_NOTIFIER)] = &RdbServiceStub::OnRemoteInitNotifier,
84         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_DIST_TABLE)] =
85             &RdbServiceStub::OnRemoteSetDistributedTables,
86         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SYNC)] = &RdbServiceStub::OnRemoteDoSync,
87         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_ASYNC)] = &RdbServiceStub::OnRemoteDoAsync,
88         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SUBSCRIBE)] = &RdbServiceStub::OnRemoteDoSubscribe,
89         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_UNSUBSCRIBE)] = &RdbServiceStub::OnRemoteDoUnSubscribe,
90         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_REMOTE_QUERY)] = &RdbServiceStub::OnRemoteDoRemoteQuery,
91         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_DELETE)] = &RdbServiceStub::OnDelete,
92         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_REGISTER_AUTOSYNC_PROGRESS_OBSERVER)] =
93             &RdbServiceStub::OnRemoteRegisterDetailProgressObserver,
94         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_UNREGISTER_AUTOSYNC_PROGRESS_OBSERVER)] =
95             &RdbServiceStub::OnRemoteUnregisterDetailProgressObserver,
96         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_NOTIFY_DATA_CHANGE)] =
97             &RdbServiceStub::OnRemoteNotifyDataChange,
98         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_SEARCHABLE)] =
99             &RdbServiceStub::OnRemoteSetSearchable,
100         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_QUERY_SHARING_RESOURCE)] =
101             &RdbServiceStub::OnRemoteQuerySharingResource,
102         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_DISABLE)] = &RdbServiceStub::OnDisable,
103         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_ENABLE)] = &RdbServiceStub::OnEnable,
104         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_BEFORE_OPEN)] = &RdbServiceStub::OnBeforeOpen,
105         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_AFTER_OPEN)] = &RdbServiceStub::OnAfterOpen,
106         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_GET_PASSWORD)] = &RdbServiceStub::OnGetPassword,
107         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_LOCK_CLOUD_CONTAINER)] =
108             &RdbServiceStub::OnLockCloudContainer,
109         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_UNLOCK_CLOUD_CONTAINER)] =
110             &RdbServiceStub::OnUnlockCloudContainer,
111         [static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_GET_DEBUG_INFO)] = &RdbServiceStub::OnGetDebugInfo
112     };
113 };
114 } // namespace OHOS::DistributedRdb
115 #endif
116