ladishd: Deassociate pids of disappearing clients. Fix for #119
[ladish.git] / daemon / app_supervisor.h
blobe081f7da26df2343c5a36d61a2b5491fc2b9122c
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
118 * @param[in] dir directory where apps will be started
120 * @return success status
122 bool
123 ladish_app_supervisor_set_directory(
124 ladish_app_supervisor_handle supervisor_handle,
125 const char * dir);
128 * Set/reset the project name
130 * @param[in] supervisor_handle supervisor object handle
131 * @param[in] poject_name project name. NULL means that there is no project name.
133 * @return success status
135 bool
136 ladish_app_supervisor_set_project_name(
137 ladish_app_supervisor_handle supervisor_handle,
138 const char * project_name);
141 * Mark that app has quit
143 * 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.
145 * @param[in] supervisor_handle supervisor object handle
146 * @param[in] pid of the app whose termination was detected
148 bool
149 ladish_app_supervisor_child_exit(
150 ladish_app_supervisor_handle supervisor_handle,
151 pid_t pid);
154 * Iterate apps that are owned by supervisor
156 * @param[in] supervisor_handle supervisor object handle
157 * @param[in] context User defined context to be supplied when the callback suppiled through the @c callback parameter is called
158 * @param[in] callback Callback to call for each app
160 bool
161 ladish_app_supervisor_enum(
162 ladish_app_supervisor_handle supervisor_handle,
163 void * context,
164 ladish_app_supervisor_enum_callback callback);
167 * Remove stopped apps; For running apps, initiate stop and
168 * mark them as zombies thus causing app autoremove
169 * once it quits.
171 * @param[in] supervisor_handle supervisor object handle
173 * @return Whether there were no running apps
175 bool
176 ladish_app_supervisor_clear(
177 ladish_app_supervisor_handle supervisor_handle);
180 * Send SIGUSR1 to all currently running L1 apps.
182 * @param[in] supervisor_handle supervisor object handle
184 void
185 ladish_app_supervisor_save_L1(
186 ladish_app_supervisor_handle supervisor_handle);
189 * Add app. Apps are added in stopped state
191 * @param[in] supervisor_handle supervisor object handle
192 * @param[in] name Name of the app
193 * @param[in] autorun whether to start the app when ladish_app_supervisor_autorun() is called
194 * @param[in] command Commandline that is used to start the app
195 * @param[in] terminal Whether the app is started in terminal
196 * @param[in] level The level that app was started in
198 * @return app handle on success; NULL on failure; the app handle is owned by the app supervisor object
200 ladish_app_handle
201 ladish_app_supervisor_add(
202 ladish_app_supervisor_handle supervisor_handle,
203 const char * name,
204 bool autorun,
205 const char * command,
206 bool terminal,
207 uint8_t level);
210 * Initiate stop of all apps owned by this supervisor
212 * @param[in] supervisor_handle supervisor object handle
214 void
215 ladish_app_supervisor_stop(
216 ladish_app_supervisor_handle supervisor_handle);
219 * Start all apps that were added with autorun enabled
221 * @param[in] supervisor_handle supervisor object handle
223 void
224 ladish_app_supervisor_autorun(
225 ladish_app_supervisor_handle supervisor_handle);
228 * Get name of the supervisor
230 * TODO: This should be probably removed in favour of ladish_app_supervisor_get_opath(); it is used for debuging purposes only
232 * @param[in] supervisor_handle supervisor object handle
234 * @retval app name; the buffer is owned by the app supervisor object
236 const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervisor_handle);
239 * Get number of apps that are currently running
241 * @param[in] supervisor_handle supervisor object handle
243 * @return Number of apps that are currently running
245 unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle);
248 * Check whether there are apps (running or not)
250 * @param[in] supervisor_handle supervisor object handle
252 * @return whether there are apps
254 bool ladish_app_supervisor_has_apps(ladish_app_supervisor_handle supervisor_handle);
257 * Find app by name
259 * @param[in] supervisor_handle supervisor object handle
260 * @param[in] name name of the app to search for
262 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
264 ladish_app_handle ladish_app_supervisor_find_app_by_name(ladish_app_supervisor_handle supervisor_handle, const char * name);
267 * Find app by id (as exposed through the D-Bus interface)
269 * @param[in] supervisor_handle supervisor object handle
270 * @param[in] id id of the app
272 * @return app handle on success; NULL if app is not found; the app handle is owned by the app supervisor object
274 ladish_app_handle ladish_app_supervisor_find_app_by_id(ladish_app_supervisor_handle supervisor_handle, uint64_t id);
277 * Search app by process id
279 * @param[in] supervisor_handle supervisor object handle
280 * @param[in] pid pid of the app to search for
282 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
284 ladish_app_handle
285 ladish_app_supervisor_find_app_by_pid(
286 ladish_app_supervisor_handle supervisor_handle,
287 pid_t pid);
290 * Search app by uuid
292 * @param[in] supervisor_handle supervisor object handle
293 * @param[in] uuid uuid of the app to search for
295 * @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
297 ladish_app_handle
298 ladish_app_supervisor_find_app_by_uuid(
299 ladish_app_supervisor_handle supervisor_handle,
300 const uuid_t uuid);
303 * The the D-Bus object path for the supervisor.
305 * @param[in] supervisor_handle supervisor object handle
307 * @retval supervisor name; the buffer is owned by the app supervisor object
309 const char * ladish_app_supervisor_get_opath(ladish_app_supervisor_handle supervisor_handle);
312 * Start an app. The app must be in stopped state.
314 * @param[in] supervisor_handle supervisor object handle
315 * @param[in] app_handle Handle of app to start
317 * @return success status
319 bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
322 * Remove an app. The app must be in stopped state.
324 * @param[in] supervisor_handle supervisor object handle
325 * @param[in] app_handle Handle of app to remove
327 void ladish_app_supervisor_remove_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
330 * Get commandline for an app.
332 * @param[in] app_handle app object handle
334 * @retval app commandline; the buffer is owned by the app supervisor object
336 const char * ladish_app_get_commandline(ladish_app_handle app_handle);
339 * Get app state
341 * @param[in] app_handle app object handle
343 * @return app state
344 * @retval LADISH_APP_STATE_STOPPED app is stopped (not running)
345 * @retval LADISH_APP_STATE_STARTED app is running and not stopping or being killed
346 * @retval LADISH_APP_STATE_STOPPING app is stopping
347 * @retval LADISH_APP_STATE_KILL app is being force killed
349 unsigned int ladish_app_get_state(ladish_app_handle app_handle);
352 * Check whether app is currently running
354 * @param[in] app_handle app object handle
356 * @retval true App is running
357 * @retval false App is not running
359 bool ladish_app_is_running(ladish_app_handle app_handle);
362 * Get app name
364 * @param[in] app_handle app object handle
366 * @retval app name; the buffer is owned by the app supervisor
368 const char * ladish_app_get_name(ladish_app_handle app_handle);
371 * Get app uuid
373 * @param[in] app_handle app object handle
374 * @param[out] uuid pointer to uuid_t storage where the app uuid will be store
377 void ladish_app_get_uuid(ladish_app_handle app_handle, uuid_t uuid);
380 * Stop an app. The app must be in started state.
382 * @param[in] app_handle Handle of app to stop
384 void ladish_app_stop(ladish_app_handle app_handle);
387 * Force kill an app. The app must be in started state.
389 * @param[in] app_handle Handle of app to kill
391 void ladish_app_kill(ladish_app_handle app_handle);
394 * Send SIGUSR1 signal to app. The app must be in started state.
396 * @param[in] app_handle Handle of app to send signal to
398 void ladish_app_save_L1(ladish_app_handle app_handle);
401 * Associate pid with app.
403 * @param[in] app_handle Handle of app
404 * @param[in] pid PID to associate with the app
406 void ladish_app_add_pid(ladish_app_handle app_handle, pid_t pid);
409 * Deassociate pid with app.
411 * @param[in] app_handle Handle of app
412 * @param[in] pid PID to deassociate with the app
414 void ladish_app_del_pid(ladish_app_handle app_handle, pid_t pid);
417 * D-Bus interface descriptor for the app supervisor interface. The call context must be a ::ladish_app_supervisor_handle
419 extern const struct dbus_interface_descriptor g_iface_app_supervisor;
421 #endif /* #ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED */