1 /*
2 * Copyright (c) 2021-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 "hdf_base.h"
17 #include "hdf_log.h"
18 #include "hdf_service_status_inner.h"
19 #include "iservstat_listener_hdi.h"
20
21 #define HDF_LOG_TAG servstat_listener
22 namespace OHOS {
23 namespace HDI {
24 namespace ServiceManager {
25 namespace V1_0 {
OnRemoteRequest(uint32_t code,OHOS::MessageParcel & data,OHOS::MessageParcel & reply,OHOS::MessageOption & option)26 int ServStatListenerStub::OnRemoteRequest(
27 uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option)
28 {
29 if (code == SERVIE_STATUS_LISTENER_NOTIFY) {
30 return ServStatListenerStubOnReceive(data, reply, option);
31 }
32
33 return HDF_ERR_NOT_SUPPORT;
34 }
35
ServStatListenerStubOnReceive(MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t ServStatListenerStub::ServStatListenerStubOnReceive(
37 MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 ServiceStatus status;
40 if (data.ReadInterfaceToken() != GetDescriptor()) {
41 HDF_LOGI("failed to check interface token");
42 return HDF_FAILURE;
43 }
44
45 const char *name = data.ReadCString();
46 status.serviceName = (name == nullptr) ? "" : name;
47 if (status.serviceName.empty()) {
48 HDF_LOGI("failed to read serviceName in ServiceStatus");
49 return HDF_FAILURE;
50 }
51
52 if (!data.ReadUint16(status.deviceClass) || !data.ReadUint16(status.status)) {
53 HDF_LOGI("failed to read deviceClass or status in ServiceStatus");
54 return HDF_FAILURE;
55 }
56
57 const char *info = data.ReadCString();
58 status.info = (info == nullptr) ? "" : info;
59
60 OnReceive(status);
61 return HDF_SUCCESS;
62 }
63 } // namespace V1_0
64 } // namespace ServiceManager
65 } // namespace HDI
66 } // namespace OHOS
67