1 /*
2 * Copyright (c) 2022-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 "devicestatus_callback_stub.h"
17
18 #include <message_parcel.h>
19
20 #include "devicestatus_common.h"
21 #include "devicestatus_define.h"
22
23 #undef LOG_TAG
24 #define LOG_TAG "DeviceStatusCallbackStub"
25
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t DeviceStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
31 MessageOption &option)
32 {
33 FI_HILOGD("cmd:%{public}u, flags:%{public}d", code, option.GetFlags());
34 std::u16string descripter = DeviceStatusCallbackStub::GetDescriptor();
35 std::u16string remoteDescripter = data.ReadInterfaceToken();
36 if (descripter != remoteDescripter) {
37 FI_HILOGE("DeviceStatusCallbackStub::OnRemoteRequest failed, descriptor mismatch");
38 return E_DEVICESTATUS_GET_SERVICE_FAILED;
39 }
40
41 switch (code) {
42 case static_cast<int32_t>(IRemoteDevStaCallback::DEVICESTATUS_CHANGE): {
43 return OnDeviceStatusChangedStub(data);
44 }
45 default:
46 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48 return RET_OK;
49 }
50
OnDeviceStatusChangedStub(MessageParcel & data)51 int32_t DeviceStatusCallbackStub::OnDeviceStatusChangedStub(MessageParcel &data)
52 {
53 CALL_DEBUG_ENTER;
54 int32_t type = 0;
55 int32_t value = 0;
56 READINT32(data, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
57 READINT32(data, value, E_DEVICESTATUS_READ_PARCEL_ERROR);
58 Data devicestatusData = {
59 static_cast<Type>(type),
60 static_cast<OnChangedValue>(value)
61 };
62 OnDeviceStatusChanged(devicestatusData);
63 return RET_OK;
64 }
65 } // namespace DeviceStatus
66 } // namespace Msdp
67 } // namespace OHOS
68