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: %m");
67  *
68  * // Open a write transaction on /myData, as we will be writing to the configTree.
69  * le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn("/myData");
70  *
71  * // Our iterator is currently on /myData, so everything under that node is replaced. If we
72  * // want to replace the whole tree we could supply a "/" here instead of using the iterator's
73  * // current location. Alternativly, we could have opened or moved the iterator to "/" in the
74  * // first place.
75  * LE_FATAL_IF(le_cfgAdmin_ExportTree(iteratorRef, resolvedPath, "") != LE_OK,
76  * "Error occured while writing config data.");
77  *
78  * // Close up the iterator,free it's resources, and commit the new data to the configTree.
79  * le_cfg_CommitTxn(iteratorRef);
80  * }
81  *
82  * // To import the config data back from ./myData.cfg:
83  * ImportMyData("./myData.cfg");
84  * @endcode
85  *
86  * Example of @b Exporting a Tree
87  *
88  * @code
89  * void ExportMyData(const char* filePath)
90  * {
91  * static char resolvedPath[PATH_MAX] = "";
92  *
93  * // Because the configTree is a seperate process, we need to make sure that the path we
94  * // received is an absolute path.
95  * LE_FATAL_IF(realpath(filePath, resolvedPath) == NULL, "Could not resolve filePath: %m");
96  *
97  * // Open a read transaction on /myData.
98  * le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn("/myData");
99  *
100  * // Our iterator is currently on /myData, so everything under that node is exported. If we
101  * // want to export the whole tree we could supply a "/" here instead of using the iterator's
102  * // current location. Alternativly, we could have opened or moved the iterator to "/" in the
103  * // first place.
104  * LE_FATAL_IF(le_cfgAdmin_ExportTree(iteratorRef, resolvedPath, "") != LE_OK,
105  * "Error occured while writing config data.");
106  *
107  * // Close up the iterator and free it's resources.
108  * le_cfg_CancelTxn(iteratorRef);
109  * }
110  *
111  * // To export the config tree to ./myData.cfg:
112  * ExportMyData("./myData.cfg");
113  * @endcode
114  *
115  * Example of @b Deleting a Tree
116  *
117  * @code
118  * // To delete a tree simply call le_cfgAdmin_DeleteTree. For example to delete the tree foo,
119  * // call as follows:
120  * le_cfgAdmin_DeleteTree("foo");
121  * @endcode
122  *
123  * Copyright (C) Sierra Wireless Inc.
124  */
125 /**
126  * @file le_cfgAdmin_interface.h
127  *
128  * Legato @ref c_configAdmin include file.
129  *
130  * Copyright (C) Sierra Wireless Inc.
131  */
132 
133 #ifndef LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
134 #define LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
135 
136 
137 #include "legato.h"
138 
139 // Interface specific includes
140 #include "le_cfg_interface.h"
141 
142 
143 //--------------------------------------------------------------------------------------------------
144 /**
145  * Type for handler called when a server disconnects.
146  */
147 //--------------------------------------------------------------------------------------------------
148 typedef void (*le_cfgAdmin_DisconnectHandler_t)(void *);
149 
150 //--------------------------------------------------------------------------------------------------
151 /**
152  *
153  * Connect the current client thread to the service providing this API. Block until the service is
154  * available.
155  *
156  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
157  * called before any other functions in this API. Normally, ConnectService is automatically called
158  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
159  *
160  * This function is created automatically.
161  */
162 //--------------------------------------------------------------------------------------------------
164 (
165  void
166 );
167 
168 //--------------------------------------------------------------------------------------------------
169 /**
170  *
171  * Try to connect the current client thread to the service providing this API. Return with an error
172  * if the service is not available.
173  *
174  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
175  * called before any other functions in this API. Normally, ConnectService is automatically called
176  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
177  *
178  * This function is created automatically.
179  *
180  * @return
181  * - LE_OK if the client connected successfully to the service.
182  * - LE_UNAVAILABLE if the server is not currently offering the service to which the client is
183  * bound.
184  * - LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
185  * - LE_COMM_ERROR if the Service Directory cannot be reached.
186  */
187 //--------------------------------------------------------------------------------------------------
189 (
190  void
191 );
192 
193 //--------------------------------------------------------------------------------------------------
194 /**
195  * Set handler called when server disconnection is detected.
196  *
197  * When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants
198  * to continue without exiting, it should call longjmp() from inside the handler.
199  */
200 //--------------------------------------------------------------------------------------------------
202 (
203  le_cfgAdmin_DisconnectHandler_t disconnectHandler,
204  void *contextPtr
205 );
206 
207 //--------------------------------------------------------------------------------------------------
208 /**
209  *
210  * Disconnect the current client thread from the service providing this API.
211  *
212  * Normally, this function doesn't need to be called. After this function is called, there's no
213  * longer a connection to the service, and the functions in this API can't be used. For details, see
214  * @ref apiFilesC_client.
215  *
216  * This function is created automatically.
217  */
218 //--------------------------------------------------------------------------------------------------
220 (
221  void
222 );
223 
224 
225 //--------------------------------------------------------------------------------------------------
226 /**
227  * Reference to an iterator object that can be used to iterate over the list of trees.
228  */
229 //--------------------------------------------------------------------------------------------------
230 typedef struct le_cfgAdmin_Iterator* le_cfgAdmin_IteratorRef_t;
231 
232 
233 //--------------------------------------------------------------------------------------------------
234 /**
235  * Read a subset of the configuration tree from the given filePath. The tree then overwrites the
236  * node at the given nodePath.
237  *
238  * This function will import a sub-tree as part of the iterator's current transaction. This allows
239  * you to create an iterator on a given node. Import a sub-tree, and then examine the contents of
240  * the import before deciding to commit the new data.
241  *
242  * @return This function will return one of the following values:
243  *
244  * - LE_OK - The commit was completed successfuly.
245  * - LE_FAULT - An I/O error occured while reading the data.
246  * - LE_FORMAT_ERROR - The configuration data being imported appears corrupted.
247  */
248 //--------------------------------------------------------------------------------------------------
250 (
251  le_cfg_IteratorRef_t iteratorRef,
252  ///< [IN] Write iterator that is being used for the import.
253  const char* LE_NONNULL filePath,
254  ///< [IN] Import the tree data from the this file.
255  const char* LE_NONNULL nodePath
256  ///< [IN] Where in the tree should this import happen? Leave
257  ///< as an empty string to use the iterator's current
258  ///< node.
259 );
260 
261 //--------------------------------------------------------------------------------------------------
262 /**
263  * Take a node given from nodePath and stream it and it's children to the file given by filePath.
264  *
265  * This funciton uses the iterator's read transaction, and takes a snapshot of the current state of
266  * the tree. The data write happens immediately.
267  *
268  * @return This function will return one of the following values:
269  *
270  * - LE_OK - The commit was completed successfuly.
271  * - LE_FAULT - An I/O error occured while writing the data.
272  */
273 //--------------------------------------------------------------------------------------------------
275 (
276  le_cfg_IteratorRef_t iteratorRef,
277  ///< [IN] Write iterator that is being used for the export.
278  const char* LE_NONNULL filePath,
279  ///< [IN] Import the tree data from the this file.
280  const char* LE_NONNULL nodePath
281  ///< [IN] Where in the tree should this export happen? Leave
282  ///< as an empty string to use the iterator's current
283  ///< node.
284 );
285 
286 //--------------------------------------------------------------------------------------------------
287 /**
288  * Delete a tree from the system, both from the filesystem and from memory.
289  */
290 //--------------------------------------------------------------------------------------------------
292 (
293  const char* LE_NONNULL treeName
294  ///< [IN] Name of the tree to delete.
295 );
296 
297 //--------------------------------------------------------------------------------------------------
298 /**
299  * Create a new iterator object for iterating over the list of trees currently managed by the
300  * config tree daemon.
301  */
302 //--------------------------------------------------------------------------------------------------
304 (
305  void
306 );
307 
308 //--------------------------------------------------------------------------------------------------
309 /**
310  * Release the iterator and free it's memory back to the system.
311  */
312 //--------------------------------------------------------------------------------------------------
314 (
315  le_cfgAdmin_IteratorRef_t iteratorRef
316  ///< [IN] Iterator object to release.
317 );
318 
319 //--------------------------------------------------------------------------------------------------
320 /**
321  * Read the name of the tree currently pointed at by the iterator.
322  *
323  * @return LE_OK if there is enough room to copy the name into the supplied buffer. LE_OVERFLOW if
324  * not. LE_NOT_FOUND is returned if the list is empty or if the iterator hasn't been moved
325  * onto the first item yet.
326  */
327 //--------------------------------------------------------------------------------------------------
329 (
330  le_cfgAdmin_IteratorRef_t iteratorRef,
331  ///< [IN] Iterator object to read.
332  char* name,
333  ///< [OUT] Name of the currently referenced tree is
334  ///< passed in this out parameter.
335  size_t nameSize
336  ///< [IN]
337 );
338 
339 //--------------------------------------------------------------------------------------------------
340 /**
341  * Move onto the next tree in the list. If there are no more trees this function returns false,
342  * otherwise true is returned.
343  *
344  * @return LE_OK if there are more trees to iterate through. LE_NOT_FOUND if not.
345  */
346 //--------------------------------------------------------------------------------------------------
348 (
349  le_cfgAdmin_IteratorRef_t iteratorRef
350  ///< [IN] Iterator to iterate.
351 );
352 
353 #endif // LE_CFGADMIN_INTERFACE_H_INCLUDE_GUARD
struct le_cfgAdmin_Iterator * le_cfgAdmin_IteratorRef_t
Definition: le_cfgAdmin_interface.h:230
le_result_t le_cfgAdmin_ImportTree(le_cfg_IteratorRef_t iteratorRef, const char *LE_NONNULL filePath, const char *LE_NONNULL nodePath)
void le_cfgAdmin_ReleaseTreeIterator(le_cfgAdmin_IteratorRef_t iteratorRef)
le_result_t
Definition: le_basics.h:35
le_result_t le_cfgAdmin_NextTree(le_cfgAdmin_IteratorRef_t iteratorRef)
void le_cfgAdmin_DisconnectService(void)
void(* le_cfgAdmin_DisconnectHandler_t)(void *)
Definition: le_cfgAdmin_interface.h:148
struct le_cfg_Iterator * le_cfg_IteratorRef_t
Definition: le_cfg_interface.h:454
le_cfgAdmin_IteratorRef_t le_cfgAdmin_CreateTreeIterator(void)
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_ConnectService(void)
le_result_t le_cfgAdmin_TryConnectService(void)
le_result_t le_cfgAdmin_GetTreeName(le_cfgAdmin_IteratorRef_t iteratorRef, char *name, size_t nameSize)
void le_cfgAdmin_DeleteTree(const char *LE_NONNULL treeName)