Fix doxygen warnings
[ladish.git] / daemon / app_supervisor.h
blob1b98d7aa8347a2b6d4266fa4a5980c2e641e500e
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009, 2010, 2011, 2012, 2013 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains interface to app supervisor object
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 /** @file app_supervisor.h */
28 #ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED
29 #define APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED
31 #include "common.h"
33 #define LADISH_APP_STATE_STOPPED 0 /**< @brief app is stopped (not running) */
34 #define LADISH_APP_STATE_STARTED 1 /**< @brief app is running and not stopping */
35 #define LADISH_APP_STATE_STOPPING 2 /**< @brief app is stopping */
36 #define LADISH_APP_STATE_KILL 3 /**< @brief app is being force killed */
38 #define MAX_LEVEL_CHARCOUNT 12 /**< @brief max size of level string, includes terminating nul char */
40 /**
41 * App supervisor object handle (pointer to opaque data)
43 typedef struct ladish_app_supervisor_tag { int unused; /**< fake */ } * ladish_app_supervisor_handle;
45 /**
46 * App object handle (pointer to opaque data)
48 * The app objects are owned by the app supervisor objects (there is not refcounting)
50 typedef struct ladish_app_tag { int unused; /**< fake */ } * ladish_app_handle;
52 /**
53 * Type of function that is called when app is renamed
55 * @param[in] context User defined context that was supplied to ladish_app_supervisor_create()
56 * @param[in] uuid uuid of the app
57 * @param[in] old_name Old name of the app
58 * @param[in] new_name New name of the app
60 typedef void (* ladish_app_supervisor_on_app_renamed_callback)(
61 void * context,
62 const uuid_t uuid,
63 const char * old_name,
64 const char * new_app_name);
66 /**
67 * Type of function that is called during app enumeration
69 * @param[in] context User defined context that was supplied to ladish_app_supervisor_enum()
70 * @param[in] name Name of the app
71 * @param[in] running Whether the app is currently running
72 * @param[in] command Commandline that is used to start the app
73 * @param[in] terminal Whether the app is started in terminal
74 * @param[in] level The level that app was started in
75 * @param[in] pid PID of the app; Zero if app is not started
76 * @param[in] uuid uuid of the app
78 * @retval true Continue iteration
79 * @retval false Stop iteration
81 typedef bool (* ladish_app_supervisor_enum_callback)(
82 void * context,
83 const char * name,
84 bool running,
85 const char * command,
86 bool terminal,
87 const char * level,
88 pid_t pid,
89 const uuid_t uuid);
91 /**
92 * Type of function that is called when save is complete
94 * @param[in] context User defined context that was supplied to ladish_app_supervisor_save()
95 * @param[in] success Whether save was successfull or not
97 typedef void (* ladish_save_complete_callback)(void * context, bool success);
99 /**
100 * Check whether app level string is valid.
102 * @param [in] level app level string
103 * @param [out] len_ptr When not NULL, the pointed variable will receive length of the level string, excluding terminating nul char.
105 * @return whether level string is valid
107 bool
108 ladish_check_app_level_validity(
109 const char * level,
110 size_t * len_ptr);
112 * Create app supervisor object
114 * @param[out] supervisor_handle_ptr Pointer to variable that will receive supervisor handle
115 * @param[in] opath Unique D-Bus object path for supervisor being created
116 * @param[in] name Name of the supervisor
117 * @param[in] context User defined context to be supplied when the callback suppiled through the @c on_app_renamed parameter is called
118 * @param[in] on_app_renamed Callback to call when app is renamed
120 * @return success status
122 bool
123 ladish_app_supervisor_create(
124 ladish_app_supervisor_handle * supervisor_handle_ptr,
125 const char * opath,
126 const char * name,
127 void * context,
128 ladish_app_supervisor_on_app_renamed_callback on_app_renamed);
131 * Destroy app supervisor object
133 * @param[in] supervisor_handle supervisor object handle
135 void
136 ladish_app_supervisor_destroy(
137 ladish_app_supervisor_handle supervisor_handle);
140 * Set the directory where apps will be started. If never called, apps will be started in the root directory ("/")
142 * @param[in] supervisor_handle supervisor object handle
143 * @param[in] dir directory where apps will be started
145 * @return success status
147 bool
148 ladish_app_supervisor_set_directory(
149 ladish_app_supervisor_handle supervisor_handle,
150 const char * dir);
153 * Set/reset the project name
155 * @param[in] supervisor_handle supervisor object handle
156 * @param[in] project_name project name. NULL means that there is no project name.
158 * @return success status
160 bool
161 ladish_app_supervisor_set_project_name(
162 ladish_app_supervisor_handle supervisor_handle,
163 const char * project_name);
166 * Mark that app has quit
168 * This function is called to mark that app has quit. Must not be called from signal handler because app supervisor object is not thread safe.
170 * @param[in] supervisor_handle supervisor object handle
171 * @param[in] pid pid of the app whose termination was detected
172 * @param[in] exit_status process exit status as returned by waitpid()
174 * @retval true Success
175 * @retval false Unknown pid
177 bool
178 ladish_app_supervisor_child_exit(
179 ladish_app_supervisor_handle supervisor_handle,
180 pid_t pid,
181 int exit_status);
184 * Iterate apps that are owned by supervisor
186 * @param[in] supervisor_handle supervisor object handle
187 * @param[in] context User defined context to be supplied when the callback suppiled through the @c callback parameter is called
188 * @param[in] callback Callback to call for each app
190 * @retval true All apps iterated
191 * @retval false Iteration stopped because callback returned false
193 bool
194 ladish_app_supervisor_enum(
195 ladish_app_supervisor_handle supervisor_handle,
196 void * context,
197 ladish_app_supervisor_enum_callback callback);
200 * Remove stopped apps; For running apps, initiate stop and
201 * mark them as zombies thus causing app autoremove
202 * once it quits.
204 * @param[in] supervisor_handle supervisor object handle
206 * @return Whether there were no running apps
208 bool
209 ladish_app_supervisor_clear(
210 ladish_app_supervisor_handle supervisor_handle);
213 * Initiate save for apps running at level higher than 0
215 * @param[in] supervisor_handle supervisor object handle
216 * @param[in] context User defined context to be supplied when callback supplied throuth @c callback parameter is called
217 * @param[in] callback Callback to call when save is complete
219 void
220 ladish_app_supervisor_save(
221 ladish_app_supervisor_handle supervisor_handle,
222 void * context,
223 ladish_save_complete_callback callback);
226 * Add app. Apps are added in stopped state
228 * @param[in] supervisor_handle supervisor object handle
229 * @param[in] name Name of the app
230 * @param[in] uuid Optional uuid of the app. If NULL, new uuid will be generated.
231 * @param[in] autorun whether to start the app when ladish_app_supervisor_autorun() is called
232 * @param[in] command Commandline that is used to start the app
233 * @param[in] terminal Whether the app is started in terminal
234 * @param[in] level The level that app was started in
236 * @return app handle on success; NULL on failure; the app handle is owned by the app supervisor object
238 ladish_app_handle
239 ladish_app_supervisor_add(
240 ladish_app_supervisor_handle supervisor_handle,
241 const char * name,
242 uuid_t uuid,
243 bool autorun,
244 const char * command,
245 bool terminal,
246 const char * level);
249 * Initiate stop of all apps owned by this supervisor
251 * @param[in] supervisor_handle supervisor object handle
253 void
254 ladish_app_supervisor_stop(
255 ladish_app_supervisor_handle supervisor_handle);
258 * Start all apps that were added with autorun enabled
260 * @param[in] supervisor_handle supervisor object handle
262 void
263 ladish_app_supervisor_autorun(
264 ladish_app_supervisor_handle supervisor_handle);
267 * Get name of the supervisor
269 * TODO: This should be probably removed in favour of ladish_app_supervisor_get_opath(); it is used for debuging purposes only
271 * @param[in] supervisor_handle supervisor object handle
273 * @retval app name; the buffer is owned by the app supervisor object
275 const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervisor_handle);
278 * Get number of apps that are currently running
280 * @param[in] supervisor_handle supervisor object handle
282 * @return Number of apps that are currently running
284 unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle);
287 * Check whether there are apps (running or not)
289 * @param[in] supervisor_handle supervisor object handle
291 * @return whether there are apps
293 bool ladish_app_supervisor_has_apps(ladish_app_supervisor_handle supervisor_handle);
296 * Dump to log the contents of the app supervisor
298 * @param[in] supervisor_handle supervisor object handle
300 void ladish_app_supervisor_dump(ladish_app_supervisor_handle supervisor_handle);
303 * Find app by name
305 * @param[in] supervisor_handle supervisor object handle
306 * @param[in] name name of the app to search for
308 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
310 ladish_app_handle ladish_app_supervisor_find_app_by_name(ladish_app_supervisor_handle supervisor_handle, const char * name);
313 * Find app by id (as exposed through the D-Bus interface)
315 * @param[in] supervisor_handle supervisor object handle
316 * @param[in] id id of the app
318 * @return app handle on success; NULL if app is not found; the app handle is owned by the app supervisor object
320 ladish_app_handle ladish_app_supervisor_find_app_by_id(ladish_app_supervisor_handle supervisor_handle, uint64_t id);
323 * Search app by process id
325 * @param[in] supervisor_handle supervisor object handle
326 * @param[in] pid pid of the app to search for
328 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
330 ladish_app_handle
331 ladish_app_supervisor_find_app_by_pid(
332 ladish_app_supervisor_handle supervisor_handle,
333 pid_t pid);
336 * Search app by uuid
338 * @param[in] supervisor_handle supervisor object handle
339 * @param[in] uuid uuid of the app to search for
341 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
343 ladish_app_handle
344 ladish_app_supervisor_find_app_by_uuid(
345 ladish_app_supervisor_handle supervisor_handle,
346 const uuid_t uuid);
349 * The the D-Bus object path for the supervisor.
351 * @param[in] supervisor_handle supervisor object handle
353 * @retval supervisor name; the buffer is owned by the app supervisor object
355 const char * ladish_app_supervisor_get_opath(ladish_app_supervisor_handle supervisor_handle);
358 * Start an app. The app must be in stopped state.
360 * @param[in] supervisor_handle supervisor object handle
361 * @param[in] app_handle Handle of app to start
363 * @return success status
365 bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
368 * Remove an app. The app must be in stopped state.
370 * @param[in] supervisor_handle supervisor object handle
371 * @param[in] app_handle Handle of app to remove
373 void ladish_app_supervisor_remove_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
376 * Get commandline for an app.
378 * @param[in] app_handle app object handle
380 * @retval app commandline; the buffer is owned by the app supervisor object
382 const char * ladish_app_get_commandline(ladish_app_handle app_handle);
385 * Get app state
387 * @param[in] app_handle app object handle
389 * @return app state
390 * @retval LADISH_APP_STATE_STOPPED app is stopped (not running)
391 * @retval LADISH_APP_STATE_STARTED app is running and not stopping or being killed
392 * @retval LADISH_APP_STATE_STOPPING app is stopping
393 * @retval LADISH_APP_STATE_KILL app is being force killed
395 unsigned int ladish_app_get_state(ladish_app_handle app_handle);
398 * Check whether app is currently running
400 * @param[in] app_handle app object handle
402 * @retval true App is running
403 * @retval false App is not running
405 bool ladish_app_is_running(ladish_app_handle app_handle);
408 * Get app name
410 * @param[in] app_handle app object handle
412 * @retval app name; the buffer is owned by the app supervisor
414 const char * ladish_app_get_name(ladish_app_handle app_handle);
417 * Get app uuid
419 * @param[in] app_handle app object handle
420 * @param[out] uuid pointer to uuid_t storage where the app uuid will be store
423 void ladish_app_get_uuid(ladish_app_handle app_handle, uuid_t uuid);
426 * Tell app to stop. The app must be in started state.
428 * @param[in] app_handle Handle of app to stop
430 void ladish_app_stop(ladish_app_handle app_handle);
433 * Force kill an app. The app must be in started state.
435 * @param[in] app_handle Handle of app to kill
437 void ladish_app_kill(ladish_app_handle app_handle);
440 * Initiate restore of app internal state. The app must be in started state.
442 * @param[in] app_handle Handle of app
444 void ladish_app_restore(ladish_app_handle app_handle);
447 * Associate pid with app.
449 * @param[in] app_handle Handle of app
450 * @param[in] pid PID to associate with the app
452 void ladish_app_add_pid(ladish_app_handle app_handle, pid_t pid);
455 * Deassociate pid with app.
457 * @param[in] app_handle Handle of app
458 * @param[in] pid PID to deassociate with the app
460 void ladish_app_del_pid(ladish_app_handle app_handle, pid_t pid);
463 * Set the D-Bus unique name for the app.
465 * @param[in] app_handle Handle of app
466 * @param[in] name D-Bus unique name
468 * @return success status
470 bool ladish_app_set_dbus_name(ladish_app_handle app_handle, const char * name);
473 * D-Bus interface descriptor for the app supervisor interface. The call context must be a ::ladish_app_supervisor_handle
475 extern const struct cdbus_interface_descriptor g_iface_app_supervisor;
477 #endif /* #ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED */