• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
17  * @addtogroup DriverHdi
18  * @{
19  *
20  * @brief Provides APIs for a system ability to obtain hardware device interface (HDI) services,
21  * load or unload a device, and listen for service status, and capabilities for the hdi-gen tool to
22  * automatically generate code in the interface description language (IDL).
23  *
24  * The HDF and the IDL code generated allow system abilities to access the HDI driver service.
25  *
26  * @since 1.0
27  */
28 
29 /**
30  * @file iservstat_listener_hdi.h
31  *
32  * @brief Defines the data structs and interface types related to service status listening based on C++.
33  *
34  * @since 1.0
35  */
36 #ifndef HDI_SERVICE_STATUS_LISTENER_INF_H
37 #define HDI_SERVICE_STATUS_LISTENER_INF_H
38 
39 #include <refbase.h>
40 #include <iremote_broker.h>
41 #include <iremote_stub.h>
42 
43 #include "hdf_device_class.h"
44 
45 namespace OHOS {
46 namespace HDI {
47 namespace ServiceManager {
48 namespace V1_0 {
49 /**
50  * @brief Enumerates the service statuses.
51  */
52 enum ServiceStatusType {
53     /** The service is started. */
54     SERVIE_STATUS_START,
55     /** The service status changes. */
56     SERVIE_STATUS_CHANGE,
57     /** The service is stopped. */
58     SERVIE_STATUS_STOP,
59     /** Maximum value of the service status. */
60     SERVIE_STATUS_MAX,
61 };
62 
63 /**
64  * @brief Defines the service status struct.
65  * The HDF uses this struct to notify the service module of the service status.
66  */
67 struct ServiceStatus {
68     /** Service name */
69     std::string serviceName;
70     /** Device type */
71     uint16_t deviceClass;
72     /** Service status */
73     uint16_t status;
74     /** Service information */
75     std::string info;
76 };
77 
78 /**
79  * @brief Defines the <b>ServStatListener</b> class.
80  */
81 class IServStatListener : public ::OHOS::IRemoteBroker {
82 public:
83     /** HDI interface descriptor, which is used to verify the permission for accessing the HDI interface. */
84     DECLARE_INTERFACE_DESCRIPTOR(u"HDI.IServiceStatusListener.V1_0");
85 
86     /**
87      * @brief Callback of the listener. You need to implement this callback for the service module.
88      *
89      * @param status Indicates the service status obtained.
90      */
91     virtual void OnReceive(const ServiceStatus &status) = 0;
92 };
93 
94 /**
95  * @brief Defines the listener stub class to implement serialization and deserialization of interface parameters.
96  * The listener implementation class must inherit this class and implement <b>OnReceive()</b>.
97  */
98 class ServStatListenerStub : public ::OHOS::IRemoteStub<IServStatListener> {
99 public:
100     ServStatListenerStub() = default;
~ServStatListenerStub()101     virtual ~ServStatListenerStub() {}
102 
103     /**
104      * @brief Distributes messages based on the invoking ID.
105      * This API calls the private function <b>ServStatListenerStubOnReceive()</b>.
106      *
107      * @param code Indicates the distribution command word called by the IPC.
108      * @param data Indicates the input parameter, through which the HDF returns
109      * the service status information to the service module.
110      * @param reply Indicates the data returned by the service module to the HDF.
111      * @param option Indicates the call type.
112      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful. Otherwise, the operation fails.
113      */
114     int OnRemoteRequest(uint32_t code,
115         ::OHOS::MessageParcel &data, ::OHOS::MessageParcel &reply, ::OHOS::MessageOption &option) override;
116 private:
117     /**
118      * @brief Marshals or unmarshals <b>OnReceive()</b> parameters.
119      *
120      * @param code Indicates the distribution command word called by the IPC.
121      * @param data Indicates the input parameter, through which the HDF returns
122      * the service status information to the service module.
123      * @param reply Indicates the data returned by the service module to the HDF.
124      * @param option Indicates the call type.
125      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful. Otherwise, the operation fails.
126      */
127     int32_t ServStatListenerStubOnReceive(::OHOS::MessageParcel& data,
128         ::OHOS::MessageParcel& reply, ::OHOS::MessageOption& option);
129 };
130 } // namespace V1_0
131 } // namespace ServiceManager
132 } // namespace HDI
133 } // namespace OHOS
134 
135 #endif /* HDI_SERVICE_STATUS_LISTENER_INF_H */
136