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