• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <ipc_types.h>
19 #include <message_parcel.h>
20 
21 #include "devicestatus_common.h"
22 
23 namespace OHOS {
24 namespace Msdp {
OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData & devicestatusData)25 void DevicestatusCallbackProxy::OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData)
26 {
27     sptr<IRemoteObject> remote = Remote();
28     DEVICESTATUS_RETURN_IF(remote == nullptr);
29 
30     MessageParcel data;
31     MessageParcel reply;
32     MessageOption option;
33 
34     if (!data.WriteInterfaceToken(DevicestatusCallbackProxy::GetDescriptor())) {
35         DEV_HILOGE(INNERKIT, "Write descriptor failed");
36         return;
37     }
38 
39     DEVICESTATUS_WRITE_PARCEL_NO_RET(data, Int32, static_cast<int32_t>(devicestatusData.type));
40     DEVICESTATUS_WRITE_PARCEL_NO_RET(data, Int32, static_cast<int32_t>(devicestatusData.value));
41 
42     int32_t ret = remote->SendRequest(static_cast<int32_t>(IdevicestatusCallback::DEVICESTATUS_CHANGE),
43         data, reply, option);
44     if (ret != ERR_OK) {
45         DEV_HILOGE(INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
46     }
47 }
48 } // Msdp
49 } // OHOS