ladishd: Basic recent projects functionality
[ladish.git] / daemon / app_supervisor.h
blobd641936158eb5efc82432b19316aa5f8bbd6c614
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009, 2010 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 /**
39 * App supervisor object handle (pointer to opaque data)
41 typedef struct ladish_app_supervisor_tag { int unused; /**< fake */ } * ladish_app_supervisor_handle;
43 /**
44 * App object handle (pointer to opaque data)
46 * The app objects are owned by the app supervisor objects (there is not refcounting)
48 typedef struct ladish_app_tag { int unused; /**< fake */ } * ladish_app_handle;
50 /**
51 * Type of function that is called when app is renamed
53 * @param[in] context User defined context that was supplied to ladish_app_supervisor_create()
54 * @param[in] uuid uuid of the app
55 * @param[in] old_name Old name of the app
56 * @param[in] new_name New name of the app
58 typedef void (* ladish_app_supervisor_on_app_renamed_callback)(
59 void * context,
60 const uuid_t uuid,
61 const char * old_name,
62 const char * new_app_name);
64 /**
65 * Type of function that is called during app enumeration
67 * @param[in] context User defined context that was supplied to ladish_app_supervisor_enum()
68 * @param[in] name Name of the app
69 * @param[in] running Whether the app is currently running
70 * @param[in] command Commandline that is used to start the app
71 * @param[in] terminal Whether the app is started in terminal
72 * @param[in] level The level that app was started in
73 * @param[in] pid PID of the app; Zero if app is not started
74 * @param[in] uuid uuid of the app
76 typedef bool (* ladish_app_supervisor_enum_callback)(
77 void * context,
78 const char * name,
79 bool running,
80 const char * command,
81 bool terminal,
82 uint8_t level,
83 pid_t pid,
84 const uuid_t uuid);
86 /**
87 * Create app supervisor object
89 * @param[out] supervisor_handle_ptr Pointer to variable that will receive supervisor handle
90 * @param[in] opath Unique D-Bus object path for supervisor being created
91 * @param[in] name Name of the supervisor
92 * @param[in] context User defined context to be supplied when the callback suppiled through the @c on_app_renamed parameter is called
93 * @param[in] on_app_renamed Callback to call when app is renamed
95 * @return success status
97 bool
98 ladish_app_supervisor_create(
99 ladish_app_supervisor_handle * supervisor_handle_ptr,
100 const char * opath,
101 const char * name,
102 void * context,
103 ladish_app_supervisor_on_app_renamed_callback on_app_renamed);
106 * Destroy app supervisor object
108 * @param[in] supervisor_handle supervisor object handle
110 void
111 ladish_app_supervisor_destroy(
112 ladish_app_supervisor_handle supervisor_handle);
115 * Set the directory where apps will be started. If never called, apps will be started in the root directory ("/")
117 * @param[in] supervisor_handle supervisor object handle
119 * @return success status
121 bool
122 ladish_app_supervisor_set_directory(
123 ladish_app_supervisor_handle supervisor_handle,
124 const char * dir);
127 * Mark that app has quit
129 * 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.
131 * @param[in] supervisor_handle supervisor object handle
132 * @param[in] pid of the app whose termination was detected
134 bool
135 ladish_app_supervisor_child_exit(
136 ladish_app_supervisor_handle supervisor_handle,
137 pid_t pid);
140 * Iterate apps that are owned by supervisor
142 * @param[in] supervisor_handle supervisor object handle
143 * @param[in] context User defined context to be supplied when the callback suppiled through the @c callback parameter is called
144 * @param[in] callback Callback to call for each app
146 bool
147 ladish_app_supervisor_enum(
148 ladish_app_supervisor_handle supervisor_handle,
149 void * context,
150 ladish_app_supervisor_enum_callback callback);
153 * Remove stopped apps; For running apps, initiate stop and
154 * mark them as zombies thus causing app autoremove
155 * once it quits.
157 * @param[in] supervisor_handle supervisor object handle
159 void
160 ladish_app_supervisor_clear(
161 ladish_app_supervisor_handle supervisor_handle);
164 * Send SIGUSR1 to all currently running L1 apps.
166 * @param[in] supervisor_handle supervisor object handle
168 void
169 ladish_app_supervisor_save_L1(
170 ladish_app_supervisor_handle supervisor_handle);
173 * Add app. Apps are added in stopped state
175 * @param[in] supervisor_handle supervisor object handle
176 * @param[in] name Name of the app
177 * @param[in] autorun whether to start the app when ladish_app_supervisor_autorun() is called
178 * @param[in] command Commandline that is used to start the app
179 * @param[in] terminal Whether the app is started in terminal
180 * @param[in] level The level that app was started in
182 * @return app handle on success; NULL on failure; the app handle is owned by the app supervisor object
184 ladish_app_handle
185 ladish_app_supervisor_add(
186 ladish_app_supervisor_handle supervisor_handle,
187 const char * name,
188 bool autorun,
189 const char * command,
190 bool terminal,
191 uint8_t level);
194 * Initiate stop of all apps owned by this supervisor
196 * @param[in] supervisor_handle supervisor object handle
198 void
199 ladish_app_supervisor_stop(
200 ladish_app_supervisor_handle supervisor_handle);
203 * Start all apps that were added with autorun enabled
205 * @param[in] supervisor_handle supervisor object handle
207 void
208 ladish_app_supervisor_autorun(
209 ladish_app_supervisor_handle supervisor_handle);
212 * Get name of the supervisor
214 * TODO: This should be probably removed in favour of ladish_app_supervisor_get_opath(); it is used for debuging purposes only
216 * @param[in] supervisor_handle supervisor object handle
218 * @retval app name; the buffer is owned by the app supervisor object
220 const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervisor_handle);
223 * Get number of apps that are currently running
225 * @param[in] supervisor_handle supervisor object handle
227 * @return Number of apps that are currently running
229 unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle);
232 * Check whether there are apps (running or not)
234 * @param[in] supervisor_handle supervisor object handle
236 * @return whether there are apps
238 bool ladish_app_supervisor_has_apps(ladish_app_supervisor_handle supervisor_handle);
241 * Find app by name
243 * @param[in] supervisor_handle supervisor object handle
244 * @param[in] name name of the app to search for
246 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
248 ladish_app_handle ladish_app_supervisor_find_app_by_name(ladish_app_supervisor_handle supervisor_handle, const char * name);
251 * Find app by id (as exposed through the D-Bus interface)
253 * @param[in] supervisor_handle supervisor object handle
254 * @param[in] id id of the app
256 * @return app handle on success; NULL if app is not found; the app handle is owned by the app supervisor object
258 ladish_app_handle ladish_app_supervisor_find_app_by_id(ladish_app_supervisor_handle supervisor_handle, uint64_t id);
261 * Search app by process id
263 * @param[in] supervisor_handle supervisor object handle
264 * @param[in] pid pid of the app to search for
266 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
268 ladish_app_handle
269 ladish_app_supervisor_find_app_by_pid(
270 ladish_app_supervisor_handle supervisor_handle,
271 pid_t pid);
274 * The the D-Bus object path for the supervisor.
276 * @param[in] supervisor_handle supervisor object handle
278 * @retval supervisor name; the buffer is owned by the app supervisor object
280 const char * ladish_app_supervisor_get_opath(ladish_app_supervisor_handle supervisor_handle);
283 * Start an app. The app must be in stopped state.
285 * @param[in] supervisor_handle supervisor object handle
286 * @param[in] app_handle Handle of app to start
288 * @return success status
290 bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
293 * Remove an app. The app must be in stopped state.
295 * @param[in] supervisor_handle supervisor object handle
296 * @param[in] app_handle Handle of app to remove
298 void ladish_app_supervisor_remove_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
301 * Get commandline for an app.
303 * @param[in] app_handle app object handle
305 * @retval app commandline; the buffer is owned by the app supervisor object
307 const char * ladish_app_get_commandline(ladish_app_handle app_handle);
310 * Get app state
312 * @param[in] app_handle app object handle
314 * @return app state
315 * @retval LADISH_APP_STATE_STOPPED app is stopped (not running)
316 * @retval LADISH_APP_STATE_STARTED app is running and not stopping or being killed
317 * @retval LADISH_APP_STATE_STOPPING app is stopping
318 * @retval LADISH_APP_STATE_KILL app is being force killed
320 unsigned int ladish_app_get_state(ladish_app_handle app_handle);
323 * Check whether app is currently running
325 * @param[in] app_handle app object handle
327 * @retval true App is running
328 * @retval false App is not running
330 bool ladish_app_is_running(ladish_app_handle app_handle);
333 * Get app name
335 * @param[in] app_handle app object handle
337 * @retval app name; the buffer is owned by the app supervisor
339 const char * ladish_app_get_name(ladish_app_handle app_handle);
342 * Get app uuid
344 * @param[in] app_handle app object handle
345 * @param[out] uuid pointer to uuid_t storage where the app uuid will be store
348 void ladish_app_get_uuid(ladish_app_handle app_handle, uuid_t uuid);
351 * Stop an app. The app must be in started state.
353 * @param[in] app_handle Handle of app to stop
355 void ladish_app_stop(ladish_app_handle app_handle);
358 * Force kill an app. The app must be in started state.
360 * @param[in] app_handle Handle of app to kill
362 void ladish_app_kill(ladish_app_handle app_handle);
365 * Send SIGUSR1 signal to app. The app must be in started state.
367 * @param[in] app_handle Handle of app to send signal to
369 void ladish_app_save_L1(ladish_app_handle app_handle);
372 * D-Bus interface descriptor for the app supervisor interface. The call context must be a ::ladish_app_supervisor_handle
374 extern const struct dbus_interface_descriptor g_iface_app_supervisor;
376 #endif /* #ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED */