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
22 namespace OHOS {
23 namespace Msdp {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t DevicestatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
25 MessageOption &option)
26 {
27 DEV_HILOGD(SERVICE, "cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
28 std::u16string descripter = DevicestatusCallbackStub::GetDescriptor();
29 std::u16string remoteDescripter = data.ReadInterfaceToken();
30 if (descripter != remoteDescripter) {
31 DEV_HILOGE(SERVICE, "DevicestatusCallbackStub::OnRemoteRequest failed, descriptor mismatch");
32 return E_DEVICESTATUS_GET_SERVICE_FAILED;
33 }
34
35 switch (code) {
36 case static_cast<int32_t>(IdevicestatusCallback::DEVICESTATUS_CHANGE): {
37 return OnDevicestatusChangedStub(data);
38 }
39 default:
40 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
41 }
42 return ERR_OK;
43 }
44
OnDevicestatusChangedStub(MessageParcel & data)45 int32_t DevicestatusCallbackStub::OnDevicestatusChangedStub(MessageParcel& data)
46 {
47 DEV_HILOGD(SERVICE, "Enter");
48 int32_t type;
49 int32_t value;
50 DEVICESTATUS_READ_PARCEL_WITH_RET(data, Int32, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
51 DEVICESTATUS_READ_PARCEL_WITH_RET(data, Int32, value, E_DEVICESTATUS_READ_PARCEL_ERROR);
52 DevicestatusDataUtils::DevicestatusData devicestatusData = {
53 static_cast<DevicestatusDataUtils::DevicestatusType>(type),
54 static_cast<DevicestatusDataUtils::DevicestatusValue>(value)
55 };
56 OnDevicestatusChanged(devicestatusData);
57 return ERR_OK;
58 }
59 } // namespace Msdp
60 } // namespace OHOS
61