• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef PLATFORM_MANAGER_H
10 #define PLATFORM_MANAGER_H
11 
12 #include "hdf_base.h"
13 #include "hdf_dlist.h"
14 #include "osal_spinlock.h"
15 #include "platform_device.h"
16 
17 #ifdef __cplusplus
18 #if __cplusplus
19 extern "C" {
20 #endif
21 #endif /* __cplusplus */
22 
23 enum PlatformModuleType;
24 struct PlatformManager {
25     struct PlatformDevice device;
26     struct DListHead devices;  /* list to keep all it's device instances */
27     int32_t (*add)(struct PlatformManager *manager, struct PlatformDevice *device);
28     int32_t (*del)(struct PlatformManager *manager, struct PlatformDevice *device);
29 };
30 
31 /**
32  * @brief Create a platform manager.
33  *
34  * Create a platform manager with member initialized.
35  *
36  * @param name Indicates the name of the manager.
37  * @param manager Indicates the double pointer to receive the created manager instance.
38  *
39  * @return Returns 0 if create successfully; returns a negative value otherwise.
40  * @since 1.0
41  */
42 int32_t PlatformManagerCreate(const char *name, struct PlatformManager **manager);
43 
44 /**
45  * @brief Destroy a platform manager.
46  *
47  * @param name Indicates the name of the manager.
48  *
49  * @since 1.0
50  */
51 void PlatformManagerDestroy(struct PlatformManager *manager);
52 
53 /**
54  * @brief Get a platform manager by module type.
55  *
56  * @param module Indicates the module type of the manager.
57  *
58  * @return Returns the pointer to the paltform manager on success; returns NULL otherwise.
59  * @since 1.0
60  */
61 struct PlatformManager *PlatformManagerGet(enum PlatformModuleType module);
62 
63 /**
64  * @brief Add a platform device to a platform manager.
65  *
66  * Add a platform device to make it managed by platform core.
67  *
68  * @param manager Indicates the pointer to the platform manager.
69  * @param device Indicates the pointer to the platform device.
70  *
71  * @return Returns 0 if the devcie added successfully; returns a negative value otherwise.
72  * @since 1.0
73  */
74 int32_t PlatformManagerAddDevice(struct PlatformManager *manager, struct PlatformDevice *device);
75 
76 /**
77  * @brief Remove a platform device from a platform manager.
78  *
79  * Remove a platform device to make it away from management of platform core.
80  *
81  * @param manager Indicates the pointer to the platform manager.
82  * @param device Indicates the pointer to the platform device.
83  *
84  * @return Returns 0 if the remove successfully; returns a negative value otherwise.
85  * @since 1.0
86  */
87 int32_t PlatformManagerDelDevice(struct PlatformManager *manager, struct PlatformDevice *device);
88 
89 /**
90  * @brief Find a particular device from the manager.
91  *
92  * Locate a particular device from the manager by a matching function, witch will be called for
93  * each device, untill it returns true indicatting a device is "found".
94  * The device found will be returned with reference count increased.
95  *
96  * @param manager Indicates the pointer to the platform manager.
97  * @param data Indicates the pointer to the data passed to match function.
98  * @param match Indicates the pointer to the match function.
99  *
100  * @return Returns the pointer to the paltform device on success; returns NULL otherwise.
101  * @since 1.0
102  */
103 struct PlatformDevice *PlatformManagerFindDevice(struct PlatformManager *manager, void *data,
104     bool (*match)(struct PlatformDevice *pdevice, void *data));
105 
106 /**
107  * @brief Get a platform device from the manager by number.
108  *
109  * The device got will be returned with reference count increased.
110  *
111  * @param manager Indicates the pointer to the platform manager.
112  * @param number Indicates the number of the target platform device.
113  *
114  * @return Returns the pointer to the paltform device on success; returns NULL otherwise.
115  * @since 1.0
116  */
117 struct PlatformDevice *PlatformManagerGetDeviceByNumber(struct PlatformManager *manager, uint32_t number);
118 
119 /**
120  * @brief Get a platform device from the manager by device name.
121  *
122  * The device got will be returned with reference count increased.
123  *
124  * @param manager Indicates the pointer to the platform manager.
125  * @param number Indicates the name of the target platform device.
126  *
127  * @return Returns the pointer to the paltform device on success; returns NULL otherwise.
128  * @since 1.0
129  */
130 struct PlatformDevice *PlatformManagerGetDeviceByName(struct PlatformManager *manager, const char *name);
131 
132 #ifdef __cplusplus
133 #if __cplusplus
134 }
135 #endif
136 #endif /* __cplusplus */
137 
138 #endif /* PLATFORM_MANAGER_H */
139