• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_proxy.h"
17 
18 #include <message_parcel.h>
19 
20 #include "iremote_object.h"
21 #include "message_option.h"
22 
23 #include "devicestatus_client.h"
24 #include "devicestatus_common.h"
25 #include "devicestatus_define.h"
26 
27 namespace OHOS {
28 namespace Msdp {
29 namespace DeviceStatus {
30 namespace {
31 constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusCallbackProxy" };
32 } // namespace
33 
OnDeviceStatusChanged(const Data & devicestatusData)34 void DeviceStatusCallbackProxy::OnDeviceStatusChanged(const Data& devicestatusData)
35 {
36     sptr<IRemoteObject> remote = Remote();
37     CHKPV(remote);
38     MessageParcel data;
39     MessageParcel reply;
40     MessageOption option;
41 
42     if (!data.WriteInterfaceToken(DeviceStatusCallbackProxy::GetDescriptor())) {
43         FI_HILOGE("Write descriptor failed");
44         return;
45     }
46     WRITEINT32(data, static_cast<int32_t>(devicestatusData.type));
47     WRITEINT32(data, static_cast<int32_t>(devicestatusData.value));
48 
49     int32_t ret = remote->SendRequest(static_cast<int32_t>(IRemoteDevStaCallback::DEVICESTATUS_CHANGE),
50         data, reply, option);
51     if (ret != RET_OK) {
52         FI_HILOGE("SendRequest is failed, error code:%{public}d", ret);
53         return;
54     }
55 }
56 } // namespace DeviceStatus
57 } // namespace Msdp
58 } // namespace OHOS
59