le_cfgAdmin_interface.h

Go to the documentation of this file.
1 
2 
3 /*
4  * ====================== WARNING ======================
5  *
6  * THE CONTENTS OF THIS FILE HAVE BEEN AUTO-GENERATED.
7  * DO NOT MODIFY IN ANY WAY.
8  *
9  * ====================== WARNING ======================
10  */
11 
12 /**
13  * @page c_configAdmin Config Tree Admin API
14  *
15  * @ref le_cfgAdmin_interface.h "API Reference"
16  *
17  * The Config Tree Admin API is intended to provide tools help with administration of Trees. These
18  * administration functions are provided as a separate API for security reasons. The Admin API needs
19  * to be explicitly included to use these admin functions keeping access separate from the main app
20  * permissions.
21  *
22  * The API includes the following functions:
23  * - an iterator function to walk the current list of trees.
24  * - an import function to bulk load the data (full or partial) into a tree.
25  * - an export function to save the contents of a tree.
26  * - a delete function to remove a tree and all its objects.
27  *
28  * Example of @b Iterating the List of Trees:
29  *
30  * @code
31  * void ListTrees(void)
32  * {
33  * // Open a tree iterator. Note that this isn't the same iterator that you would be using for
34  * // read and write transactions.
35  * le_cfgAdmin_IteratorRef_t iteratorRef = le_cfgAdmin_CreateTreeIterator();
36  *
37  * LE_INFO("Listing configuration Trees in the current system...");
38  *
39  * // The iteratorRef starts at item -1, so we need to start with calling NextTree in our loop.
40  * while (le_cfgAdmin_NextTree(iteratorRef) == LE_OK)
41  * {
42  * // Simply extract the name of the tree and dump it to the device log.
43  * char treeName[MAX_TREE_NAME_BYTES] = "";
44  *
45  * if (le_cfgAdmin_GetTreeName(iteratorRef, treeName, sizeof(treeName)) == LE_OK)
46  * {
47  * LE_INFO("Tree: '%s'", treeName);
48  * }
49  * }
50  *
51  * // Again, this isn't a regular config node iterator, so you need to use the cfgAdmin
52  * // release on the tree iterator.
53  * le_cfgAdmin_ReleaseTreeIterator(iteratorRef);
54  * }
55  * @endcode
56  *
57  * Example of @b Importing a Tree:
58  *
59  * @code
60  * void ImportMyTree(const char* filePath)
61  * {
62  * static char resolvedPath[PATH_MAX] = "";
63  *
64  * // Because the configTree is a seperate process, we need to make sure that the path we
65  * // received is an absolute path.
66  * LE_FATAL_IF(realpath(filePath, resolvedPath) == NULL, "Could not resolve filePath: error %d",
67  * errno);
68  *
69  * // Open a write transaction on /myData, as we will be writing to the configTree.
70  * le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn("/myData");
71  *
72  * // Our iterator is currently on /myData, so everything under that node is replaced. If we
73  * // want to replace the whole tree we could supply a "/" here instead of using the iterator's
74  * // current location. Alternativly, we could have opened or moved the iterator to "/" in the
75  * // first place.
76  * LE_FATAL_IF(le_cfgAdmin_ExportTree(iteratorRef, resolvedPath, "") != LE_OK,
77  * "Error occured while writing config data.");
78  *
79  * // Close up the iterator,free it's resources, and commit the new data to the configTree.
80  * le_cfg_CommitTxn(iteratorRef);
81  * }
82  *
83  * // To import the config data back from ./myData.cfg:
84  * ImportMyData("./myData.cfg");
85  * @endcode
86  *
87  * Example of @b Exporting a Tree
88  *
89  * @code
90  * void ExportMyData(const char* filePath)
91  * {
92  * static char resolvedPath[PATH_MAX] = "";
93  *
94  * // Because the configTree is a seperate process, we need to make sure that the path we
95  * // received is an absolute path.
96  * LE_FATAL_IF(realpath(filePath, resolvedPath) == NULL, "Could not resolve filePath: error %d",
97  * errno);
98  *
99  * // Open a read transaction on /myData.
100  * le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn("/myData");
101  *
102  * // Our iterator is currently on /myData, so everything under that node is exported. If we
103  * // want to export the whole tree we could supply a "/" here instead of using the iterator's
104  * // current location. Alternativly, we could have opened or moved the iterator to "/" in the
105  * // first place.
106  * LE_FATAL_IF(le_cfgAdmin_ExportTree(iteratorRef, resolvedPath, "") != LE_OK,
107  * "Error occured while writing config data.");
108  *
109  * // Close up the iterator and free it's resources.
110  * le_cfg_CancelTxn(iteratorRef);
111  * }
112  *
113  * // To export the config tree to ./myData.cfg:
114  * ExportMyData("./myData.cfg");
115  * @endcode
116  *
117  * Example of @b Deleting a Tree
118  *
119  * @code
120  * // To delete a tree simply call le_cfgAdmin_DeleteTree. For example to delete the tree foo,
121  * // call as follows:
122  * le_cfgAdmin_DeleteTree("foo");
123  * @endcode
124  *
125  * Copyright (C) Sierra Wireless Inc.
126  */
127 /**
128  * @file le_cfgAdmin_interface.h
129  *
130  * Legato @ref c_configAdmin include file.
131  *
132  * Copyright (C) Sierra Wireless Inc.
133  */
134 
135 #ifndef LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
136 #define LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
137 
138 
139 #include "legato.h"
140 
141 // Interface specific includes
142 #include "le_cfg_interface.h"
143 
144 // Internal includes for this interface
145 #include "le_cfgAdmin_common.h"
146 //--------------------------------------------------------------------------------------------------
147 /**
148  * Type for handler called when a server disconnects.
149  */
150 //--------------------------------------------------------------------------------------------------
151 typedef void (*le_cfgAdmin_DisconnectHandler_t)(void *);
152 
153 //--------------------------------------------------------------------------------------------------
154 /**
155  *
156  * Connect the current client thread to the service providing this API. Block until the service is
157  * available.
158  *
159  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
160  * called before any other functions in this API. Normally, ConnectService is automatically called
161  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
162  *
163  * This function is created automatically.
164  */
165 //--------------------------------------------------------------------------------------------------
167 (
168  void
169 );
170 
171 //--------------------------------------------------------------------------------------------------
172 /**
173  *
174  * Try to connect the current client thread to the service providing this API. Return with an error
175  * if the service is not available.
176  *
177  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
178  * called before any other functions in this API. Normally, ConnectService is automatically called
179  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
180  *
181  * This function is created automatically.
182  *
183  * @return
184  * - LE_OK if the client connected successfully to the service.
185  * - LE_UNAVAILABLE if the server is not currently offering the service to which the client is
186  * bound.
187  * - LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
188  * - LE_COMM_ERROR if the Service Directory cannot be reached.
189  */
190 //--------------------------------------------------------------------------------------------------
192 (
193  void
194 );
195 
196 //--------------------------------------------------------------------------------------------------
197 /**
198  * Set handler called when server disconnection is detected.
199  *
200  * When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants
201  * to continue without exiting, it should call longjmp() from inside the handler.
202  */
203 //--------------------------------------------------------------------------------------------------
205 (
206  le_cfgAdmin_DisconnectHandler_t disconnectHandler,
207  void *contextPtr
208 );
209 
210 //--------------------------------------------------------------------------------------------------
211 /**
212  *
213  * Disconnect the current client thread from the service providing this API.
214  *
215  * Normally, this function doesn't need to be called. After this function is called, there's no
216  * longer a connection to the service, and the functions in this API can't be used. For details, see
217  * @ref apiFilesC_client.
218  *
219  * This function is created automatically.
220  */
221 //--------------------------------------------------------------------------------------------------
223 (
224  void
225 );
226 
227 
228 //--------------------------------------------------------------------------------------------------
229 /**
230  * Reference to an iterator object that can be used to iterate over the list of trees.
231  */
232 //--------------------------------------------------------------------------------------------------
233 
234 
235 //--------------------------------------------------------------------------------------------------
236 /**
237  * Read a subset of the configuration tree from the given filePath. The tree then overwrites the
238  * node at the given nodePath.
239  *
240  * This function will import a sub-tree as part of the iterator's current transaction. This allows
241  * you to create an iterator on a given node. Import a sub-tree, and then examine the contents of
242  * the import before deciding to commit the new data.
243  *
244  * @return This function will return one of the following values:
245  *
246  * - LE_OK - The commit was completed successfuly.
247  * - LE_FAULT - An I/O error occured while reading the data.
248  * - LE_FORMAT_ERROR - The configuration data being imported appears corrupted.
249  */
250 //--------------------------------------------------------------------------------------------------
252 (
253  le_cfg_IteratorRef_t iteratorRef,
254  ///< [IN] Write iterator that is being used for the import.
255  const char* LE_NONNULL filePath,
256  ///< [IN] Import the tree data from the this file.
257  const char* LE_NONNULL nodePath
258  ///< [IN] Where in the tree should this import happen? Leave
259  ///< as an empty string to use the iterator's current
260  ///< node.
261 );
262 
263 //--------------------------------------------------------------------------------------------------
264 /**
265  * Take a node given from nodePath and stream it and it's children to the file given by filePath.
266  *
267  * This funciton uses the iterator's read transaction, and takes a snapshot of the current state of
268  * the tree. The data write happens immediately.
269  *
270  * @return This function will return one of the following values:
271  *
272  * - LE_OK - The commit was completed successfuly.
273  * - LE_FAULT - An I/O error occured while writing the data.
274  */
275 //--------------------------------------------------------------------------------------------------
277 (
278  le_cfg_IteratorRef_t iteratorRef,
279  ///< [IN] Write iterator that is being used for the export.
280  const char* LE_NONNULL filePath,
281  ///< [IN] Import the tree data from the this file.
282  const char* LE_NONNULL nodePath
283  ///< [IN] Where in the tree should this export happen? Leave
284  ///< as an empty string to use the iterator's current
285  ///< node.
286 );
287 
288 //--------------------------------------------------------------------------------------------------
289 /**
290  * Delete a tree from the system, both from the filesystem and from memory.
291  */
292 //--------------------------------------------------------------------------------------------------
294 (
295  const char* LE_NONNULL treeName
296  ///< [IN] Name of the tree to delete.
297 );
298 
299 //--------------------------------------------------------------------------------------------------
300 /**
301  * Create a new iterator object for iterating over the list of trees currently managed by the
302  * config tree daemon.
303  */
304 //--------------------------------------------------------------------------------------------------
305 le_cfgAdmin_IteratorRef_t le_cfgAdmin_CreateTreeIterator
306 (
307  void
308 );
309 
310 //--------------------------------------------------------------------------------------------------
311 /**
312  * Release the iterator and free it's memory back to the system.
313  */
314 //--------------------------------------------------------------------------------------------------
316 (
317  le_cfgAdmin_IteratorRef_t iteratorRef
318  ///< [IN] Iterator object to release.
319 );
320 
321 //--------------------------------------------------------------------------------------------------
322 /**
323  * Read the name of the tree currently pointed at by the iterator.
324  *
325  * @return LE_OK if there is enough room to copy the name into the supplied buffer. LE_OVERFLOW if
326  * not. LE_NOT_FOUND is returned if the list is empty or if the iterator hasn't been moved
327  * onto the first item yet.
328  */
329 //--------------------------------------------------------------------------------------------------
331 (
332  le_cfgAdmin_IteratorRef_t iteratorRef,
333  ///< [IN] Iterator object to read.
334  char* name,
335  ///< [OUT] Name of the currently referenced tree is
336  ///< passed in this out parameter.
337  size_t nameSize
338  ///< [IN]
339 );
340 
341 //--------------------------------------------------------------------------------------------------
342 /**
343  * Move onto the next tree in the list. If there are no more trees this function returns false,
344  * otherwise true is returned.
345  *
346  * @return LE_OK if there are more trees to iterate through. LE_NOT_FOUND if not.
347  */
348 //--------------------------------------------------------------------------------------------------
350 (
351  le_cfgAdmin_IteratorRef_t iteratorRef
352  ///< [IN] Iterator to iterate.
353 );
354 
355 #endif // LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
void le_cfgAdmin_ConnectService(void)
void le_cfgAdmin_ReleaseTreeIterator(le_cfgAdmin_IteratorRef_t iteratorRef)
le_cfgAdmin_IteratorRef_t le_cfgAdmin_CreateTreeIterator(void)
le_result_t
Definition: le_basics.h:45
le_result_t le_cfgAdmin_ImportTree(le_cfg_IteratorRef_t iteratorRef, const char *LE_NONNULL filePath, const char *LE_NONNULL nodePath)
LE_FULL_API void le_cfgAdmin_SetServerDisconnectHandler(le_cfgAdmin_DisconnectHandler_t disconnectHandler, void *contextPtr)
le_result_t le_cfgAdmin_ExportTree(le_cfg_IteratorRef_t iteratorRef, const char *LE_NONNULL filePath, const char *LE_NONNULL nodePath)
void(* le_cfgAdmin_DisconnectHandler_t)(void *)
Definition: le_cfgAdmin_interface.h:151
void le_cfgAdmin_DeleteTree(const char *LE_NONNULL treeName)
#define LE_FULL_API
Definition: le_apiFeatures.h:40
le_result_t le_cfgAdmin_GetTreeName(le_cfgAdmin_IteratorRef_t iteratorRef, char *name, size_t nameSize)
void le_cfgAdmin_DisconnectService(void)
le_result_t le_cfgAdmin_TryConnectService(void)
le_result_t le_cfgAdmin_NextTree(le_cfgAdmin_IteratorRef_t iteratorRef)