1 /*
2  * Copyright (c) 2022-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 stub_collector.h
31  *
32  * @brief Defines a stub collector for the hdi-gen tool to manage constructors and objects.
33  * The service module registers the constructor with the object collector based on the interface name,
34  * and then creates a stub object based on the interface name and registered constructor.
35  *
36  * @since 1.0
37  */
38 #ifndef HDI_STUB_COLLECTOR_H
39 #define HDI_STUB_COLLECTOR_H
40 
41 #include <hdf_remote_service.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 
47 /**
48  * @brief Defines the <b>StubConstructor</b> struct.
49  */
50 struct StubConstructor {
51     /** Define the interface type of the stub object constructor. */
52     struct HdfRemoteService **(*constructor)(void *);
53     /** Define the interface type of the stub object destructor. */
54     void (*destructor)(struct HdfRemoteService **);
55 };
56 
57 /**
58  * @brief Registers a stub constructor.
59  *
60  * @param ifDesc Indicates the pointer to the interface descriptor of the stub object.
61  * @param constructor Indicate the pointer to the constructor of the stub object.
62  */
63 void StubConstructorRegister(const char *ifDesc, struct StubConstructor *constructor);
64 
65 /**
66  * @brief Unregisters a stub constructor.
67  *
68  * @param ifDesc Indicates the pointer to the interface descriptor of the stub object.
69  * @param constructor Indicate the pointer to the constructor of the stub object.
70  */
71 void StubConstructorUnregister(const char *ifDesc, const struct StubConstructor *constructor);
72 
73 /**
74  * @brief Creates a stub object and adds it to the object manager.
75  *
76  * @param ifDesc Indicates the pointer to the interface descriptor of the stub object.
77  * @param servPtr Indicates the pointer to the constructor object.
78  * @return Returns the stub object created.
79  */
80 struct HdfRemoteService **StubCollectorGetOrNewObject(const char *ifDesc, void *servPtr);
81 
82 /**
83  * @brief Removes a stub object from the object manager.
84  *
85  * @param ifDesc Indicates the pointer to the interface descriptor of the stub object.
86  * @param servPtr Indicates the pointer to the constructor object.
87  */
88 void StubCollectorRemoveObject(const char *ifDesc, void *servPtr);
89 
90 #ifdef __cplusplus
91 }
92 #endif /* __cplusplus */
93 
94 #endif // HDI_STUB_COLLECTOR_H
95