1f857971dSopenharmony_ci/*
2f857971dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f857971dSopenharmony_ci * you may not use this file except in compliance with the License.
5f857971dSopenharmony_ci * You may obtain a copy of the License at
6f857971dSopenharmony_ci *
7f857971dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f857971dSopenharmony_ci *
9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f857971dSopenharmony_ci * See the License for the specific language governing permissions and
13f857971dSopenharmony_ci * limitations under the License.
14f857971dSopenharmony_ci */
15f857971dSopenharmony_ci
16f857971dSopenharmony_ci#include "intention_stub.h"
17f857971dSopenharmony_ci
18f857971dSopenharmony_ci#include "devicestatus_define.h"
19f857971dSopenharmony_ci#include "intention_identity.h"
20f857971dSopenharmony_ci
21f857971dSopenharmony_ci#undef LOG_TAG
22f857971dSopenharmony_ci#define LOG_TAG "IntentionStub"
23f857971dSopenharmony_ci
24f857971dSopenharmony_cinamespace OHOS {
25f857971dSopenharmony_cinamespace Msdp {
26f857971dSopenharmony_cinamespace DeviceStatus {
27f857971dSopenharmony_ci
28f857971dSopenharmony_ciint32_t IntentionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
29f857971dSopenharmony_ci{
30f857971dSopenharmony_ci    std::u16string descriptor = IntentionStub::GetDescriptor();
31f857971dSopenharmony_ci    std::u16string remoteDescriptor = data.ReadInterfaceToken();
32f857971dSopenharmony_ci    if (descriptor != remoteDescriptor) {
33f857971dSopenharmony_ci        FI_HILOGE("IntentionStub::OnRemoteRequest failed, descriptor is not matched");
34f857971dSopenharmony_ci        return E_DEVICESTATUS_GET_SERVICE_FAILED;
35f857971dSopenharmony_ci    }
36f857971dSopenharmony_ci    Intention intention = static_cast<Intention>(GINTENTION(code));
37f857971dSopenharmony_ci
38f857971dSopenharmony_ci    switch (GACTION(code)) {
39f857971dSopenharmony_ci        case CommonAction::ENABLE: {
40f857971dSopenharmony_ci            return Enable(intention, data, reply);
41f857971dSopenharmony_ci        }
42f857971dSopenharmony_ci        case CommonAction::DISABLE: {
43f857971dSopenharmony_ci            return Disable(intention, data, reply);
44f857971dSopenharmony_ci        }
45f857971dSopenharmony_ci        case CommonAction::START: {
46f857971dSopenharmony_ci            return Start(intention, data, reply);
47f857971dSopenharmony_ci        }
48f857971dSopenharmony_ci        case CommonAction::STOP: {
49f857971dSopenharmony_ci            return Stop(intention, data, reply);
50f857971dSopenharmony_ci        }
51f857971dSopenharmony_ci        case CommonAction::ADD_WATCH: {
52f857971dSopenharmony_ci            return AddWatch(intention, GPARAM(code), data, reply);
53f857971dSopenharmony_ci        }
54f857971dSopenharmony_ci        case CommonAction::REMOVE_WATCH: {
55f857971dSopenharmony_ci            return RemoveWatch(intention, GPARAM(code), data, reply);
56f857971dSopenharmony_ci        }
57f857971dSopenharmony_ci        case CommonAction::SET_PARAM: {
58f857971dSopenharmony_ci            return SetParam(intention, GPARAM(code), data, reply);
59f857971dSopenharmony_ci        }
60f857971dSopenharmony_ci        case CommonAction::GET_PARAM: {
61f857971dSopenharmony_ci            return GetParam(intention, GPARAM(code), data, reply);
62f857971dSopenharmony_ci        }
63f857971dSopenharmony_ci        case CommonAction::CONTROL: {
64f857971dSopenharmony_ci            return Control(intention, GPARAM(code), data, reply);
65f857971dSopenharmony_ci        }
66f857971dSopenharmony_ci        default: {
67f857971dSopenharmony_ci            FI_HILOGE("Unknown action");
68f857971dSopenharmony_ci        }
69f857971dSopenharmony_ci    }
70f857971dSopenharmony_ci    return RET_ERR;
71f857971dSopenharmony_ci}
72f857971dSopenharmony_ci} // namespace DeviceStatus
73f857971dSopenharmony_ci} // namespace Msdp
74f857971dSopenharmony_ci} // namespace OHOS