1 /*
2 * Copyright (c) 2021 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.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 switch (code) {
30 case SERVIE_STATUS_LISTENER_NOTIFY:
31 return ServStatListenerStubOnReceive(data, reply, option);
32 default:
33 break;
34 }
35
36 return HDF_ERR_NOT_SUPPORT;
37 }
38
ServStatListenerStubOnReceive(MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t ServStatListenerStub::ServStatListenerStubOnReceive(
40 MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42 ServiceStatus status;
43 if (data.ReadInterfaceToken() != GetDescriptor()) {
44 HDF_LOGI("failed to check interface token");
45 return HDF_FAILURE;
46 }
47
48 const char *name = data.ReadCString();
49 status.serviceName = (name == nullptr) ? "" : name;
50 if (status.serviceName.empty()) {
51 HDF_LOGI("failed to read serviceName in ServiceStatus");
52 return HDF_FAILURE;
53 }
54
55 if (!data.ReadUint16(status.deviceClass) || !data.ReadUint16(status.status)) {
56 HDF_LOGI("failed to read deviceClass or status in ServiceStatus");
57 return HDF_FAILURE;
58 }
59
60 const char *info = data.ReadCString();
61 status.info = (info == nullptr) ? "" : info;
62
63 OnReceive(status);
64 return HDF_SUCCESS;
65 }
66 } // namespace V1_0
67 } // namespace ServiceManager
68 } // namespace HDI
69 } // namespace OHOS