1 /*
2 * Copyright (c) 2023 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 "intention_stub.h"
17
18 #include "devicestatus_define.h"
19 #include "intention_identity.h"
20
21 #undef LOG_TAG
22 #define LOG_TAG "IntentionStub"
23
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t IntentionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
29 {
30 std::u16string descriptor = IntentionStub::GetDescriptor();
31 std::u16string remoteDescriptor = data.ReadInterfaceToken();
32 if (descriptor != remoteDescriptor) {
33 FI_HILOGE("IntentionStub::OnRemoteRequest failed, descriptor is not matched");
34 return E_DEVICESTATUS_GET_SERVICE_FAILED;
35 }
36 Intention intention = static_cast<Intention>(GINTENTION(code));
37
38 switch (GACTION(code)) {
39 case CommonAction::ENABLE: {
40 return Enable(intention, data, reply);
41 }
42 case CommonAction::DISABLE: {
43 return Disable(intention, data, reply);
44 }
45 case CommonAction::START: {
46 return Start(intention, data, reply);
47 }
48 case CommonAction::STOP: {
49 return Stop(intention, data, reply);
50 }
51 case CommonAction::ADD_WATCH: {
52 return AddWatch(intention, GPARAM(code), data, reply);
53 }
54 case CommonAction::REMOVE_WATCH: {
55 return RemoveWatch(intention, GPARAM(code), data, reply);
56 }
57 case CommonAction::SET_PARAM: {
58 return SetParam(intention, GPARAM(code), data, reply);
59 }
60 case CommonAction::GET_PARAM: {
61 return GetParam(intention, GPARAM(code), data, reply);
62 }
63 case CommonAction::CONTROL: {
64 return Control(intention, GPARAM(code), data, reply);
65 }
66 default: {
67 FI_HILOGE("Unknown action");
68 }
69 }
70 return RET_ERR;
71 }
72 } // namespace DeviceStatus
73 } // namespace Msdp
74 } // namespace OHOS