1 /*
2 * Copyright (c) 2021 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 #include "watcher_manager_stub.h"
17 #include "watcher_proxy.h"
18 #include "watcher_utils.h"
19
20 namespace OHOS {
21 namespace init_param {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code,
23 MessageParcel &data, MessageParcel &reply, MessageOption &option)
24 {
25 std::u16string myDescriptor = IWatcherManager::GetDescriptor();
26 std::u16string remoteDescriptor = data.ReadInterfaceToken();
27 WATCHER_CHECK(myDescriptor == remoteDescriptor, return -1, "Invalid remoteDescriptor %u", code);
28
29 WATCHER_LOGV("OnRemoteRequest code %u", code);
30 switch (code) {
31 case static_cast<uint32_t>(ParamWatcherInterfaceCode::ADD_WATCHER): {
32 std::string key = data.ReadString();
33 int ret = AddWatcher(key, data.ReadUint32());
34 reply.WriteInt32(ret);
35 break;
36 }
37 case static_cast<uint32_t>(ParamWatcherInterfaceCode::DEL_WATCHER): {
38 std::string key = data.ReadString();
39 int ret = DelWatcher(key, data.ReadUint32());
40 reply.WriteInt32(ret);
41 break;
42 }
43 case static_cast<uint32_t>(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT): {
44 auto remote = data.ReadRemoteObject();
45 // 0 is invalid watcherId
46 uint32_t id = data.ReadUint32();
47 sptr<IWatcher> watcher = new WatcherProxy(remote);
48 uint32_t remoteWatcherId = AddRemoteWatcher(id, watcher);
49 reply.WriteUint32(remoteWatcherId);
50 break;
51 }
52 case static_cast<uint32_t>(ParamWatcherInterfaceCode::DEL_REMOTE_AGENT): {
53 int ret = DelRemoteWatcher(data.ReadUint32());
54 reply.WriteInt32(ret);
55 break;
56 }
57 case static_cast<uint32_t>(ParamWatcherInterfaceCode::REFRESH_WATCHER): {
58 std::string key = data.ReadString();
59 int ret = RefreshWatcher(key, data.ReadUint32());
60 reply.WriteInt32(ret);
61 break;
62 }
63 default: {
64 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65 }
66 }
67 return 0;
68 }
69 }
70 }
71