• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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");
28 
29     WATCHER_LOGV("OnRemoteRequest code %u", code);
30     switch (code) {
31         case ADD_WATCHER: {
32             std::string key = data.ReadString();
33             int ret = AddWatcher(key, data.ReadUint32());
34             reply.WriteInt32(ret);
35             break;
36         }
37         case DEL_WATCHER: {
38             std::string key = data.ReadString();
39             int ret = DelWatcher(key, data.ReadUint32());
40             reply.WriteInt32(ret);
41             break;
42         }
43         case ADD_REMOTE_AGENT: {
44             auto remote = data.ReadRemoteObject();
45             // 0 is invalid watcherId
46             WATCHER_CHECK(remote != nullptr, reply.WriteUint32(0);
47                 return 0, "Failed to read remote watcher");
48             uint32_t id = data.ReadUint32();
49             sptr<IWatcher> watcher = new WatcherProxy(remote);
50             uint32_t remoteWatcherId = AddRemoteWatcher(id, watcher);
51             reply.WriteUint32(remoteWatcherId);
52             break;
53         }
54         case DEL_REMOTE_AGENT: {
55             int ret = DelRemoteWatcher(data.ReadUint32());
56             reply.WriteInt32(ret);
57             break;
58         }
59         case REFRESH_WATCHER: {
60             std::string key = data.ReadString();
61             int ret = RefreshWatcher(key, data.ReadUint32());
62             reply.WriteInt32(ret);
63             break;
64         }
65         default: {
66             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67         }
68     }
69     return 0;
70 }
71 }
72 }
73