1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains interface to app supervisor object
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/** @file app_supervisor.h */
#ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED
#define APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED
#include "common.h"
#define LADISH_APP_STATE_STOPPED 0 /**< @brief app is stopped (not running) */
#define LADISH_APP_STATE_STARTED 1 /**< @brief app is running and not stopping */
#define LADISH_APP_STATE_STOPPING 2 /**< @brief app is stopping */
#define LADISH_APP_STATE_KILL 3 /**< @brief app is being force killed */
#define MAX_LEVEL_CHARCOUNT 12 /* includes terminating nul char */
/**
* App supervisor object handle (pointer to opaque data)
*/
typedef struct ladish_app_supervisor_tag { int unused; /**< fake */ } * ladish_app_supervisor_handle;
/**
* App object handle (pointer to opaque data)
*
* The app objects are owned by the app supervisor objects (there is not refcounting)
*/
typedef struct ladish_app_tag { int unused; /**< fake */ } * ladish_app_handle;
/**
* Type of function that is called when app is renamed
*
* @param[in] context User defined context that was supplied to ladish_app_supervisor_create()
* @param[in] uuid uuid of the app
* @param[in] old_name Old name of the app
* @param[in] new_name New name of the app
*/
typedef void (* ladish_app_supervisor_on_app_renamed_callback)(
void * context,
const uuid_t uuid,
const char * old_name,
const char * new_app_name);
/**
* Type of function that is called during app enumeration
*
* @param[in] context User defined context that was supplied to ladish_app_supervisor_enum()
* @param[in] name Name of the app
* @param[in] running Whether the app is currently running
* @param[in] command Commandline that is used to start the app
* @param[in] terminal Whether the app is started in terminal
* @param[in] level The level that app was started in
* @param[in] pid PID of the app; Zero if app is not started
* @param[in] uuid uuid of the app
*/
typedef bool (* ladish_app_supervisor_enum_callback)(
void * context,
const char * name,
bool running,
const char * command,
bool terminal,
const char * level,
pid_t pid,
const uuid_t uuid);
/**
* Type of function that is called when save is complete
*
* @param[in] context User defined context that was supplied to ladish_app_supervisor_save()
* @param[in] success Whether save was successfull or not
*/
typedef void (* ladish_save_complete_callback)(void * context, bool success);
/**
* Check whether app level string is valid.
*
* @param [in] app level string
* @param [out] len_ptr When not NULL, the pointed variable will receive length of the level string, excluding terminating nul char.
*
* @return whether level string is valid
*/
bool
ladish_check_app_level_validity(
const char * level,
size_t * len_ptr);
/**
* Create app supervisor object
*
* @param[out] supervisor_handle_ptr Pointer to variable that will receive supervisor handle
* @param[in] opath Unique D-Bus object path for supervisor being created
* @param[in] name Name of the supervisor
* @param[in] context User defined context to be supplied when the callback suppiled through the @c on_app_renamed parameter is called
* @param[in] on_app_renamed Callback to call when app is renamed
*
* @return success status
*/
bool
ladish_app_supervisor_create(
ladish_app_supervisor_handle * supervisor_handle_ptr,
const char * opath,
const char * name,
void * context,
ladish_app_supervisor_on_app_renamed_callback on_app_renamed);
/**
* Destroy app supervisor object
*
* @param[in] supervisor_handle supervisor object handle
*/
void
ladish_app_supervisor_destroy(
ladish_app_supervisor_handle supervisor_handle);
/**
* Set the directory where apps will be started. If never called, apps will be started in the root directory ("/")
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] dir directory where apps will be started
*
* @return success status
*/
bool
ladish_app_supervisor_set_directory(
ladish_app_supervisor_handle supervisor_handle,
const char * dir);
/**
* Set/reset the project name
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] project_name project name. NULL means that there is no project name.
*
* @return success status
*/
bool
ladish_app_supervisor_set_project_name(
ladish_app_supervisor_handle supervisor_handle,
const char * project_name);
/**
* Mark that app has quit
*
* 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.
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] pid of the app whose termination was detected
*/
bool
ladish_app_supervisor_child_exit(
ladish_app_supervisor_handle supervisor_handle,
pid_t pid);
/**
* Iterate apps that are owned by supervisor
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] context User defined context to be supplied when the callback suppiled through the @c callback parameter is called
* @param[in] callback Callback to call for each app
*/
bool
ladish_app_supervisor_enum(
ladish_app_supervisor_handle supervisor_handle,
void * context,
ladish_app_supervisor_enum_callback callback);
/**
* Remove stopped apps; For running apps, initiate stop and
* mark them as zombies thus causing app autoremove
* once it quits.
*
* @param[in] supervisor_handle supervisor object handle
*
* @return Whether there were no running apps
*/
bool
ladish_app_supervisor_clear(
ladish_app_supervisor_handle supervisor_handle);
/**
* Initiate save for apps running at level higher than 0
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] context User defined context to be supplied when callback supplied throuth @c callback parameter is called
* @param[in] callback Callback to call when save is complete
*/
void
ladish_app_supervisor_save(
ladish_app_supervisor_handle supervisor_handle,
void * context,
ladish_save_complete_callback callback);
/**
* Add app. Apps are added in stopped state
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] name Name of the app
* @param[in] uuid Optional uuid of the app. If NULL, new uuid will be generated.
* @param[in] autorun whether to start the app when ladish_app_supervisor_autorun() is called
* @param[in] command Commandline that is used to start the app
* @param[in] terminal Whether the app is started in terminal
* @param[in] level The level that app was started in
*
* @return app handle on success; NULL on failure; the app handle is owned by the app supervisor object
*/
ladish_app_handle
ladish_app_supervisor_add(
ladish_app_supervisor_handle supervisor_handle,
const char * name,
uuid_t uuid,
bool autorun,
const char * command,
bool terminal,
const char * level);
/**
* Initiate stop of all apps owned by this supervisor
*
* @param[in] supervisor_handle supervisor object handle
*/
void
ladish_app_supervisor_stop(
ladish_app_supervisor_handle supervisor_handle);
/**
* Start all apps that were added with autorun enabled
*
* @param[in] supervisor_handle supervisor object handle
*/
void
ladish_app_supervisor_autorun(
ladish_app_supervisor_handle supervisor_handle);
/**
* Get name of the supervisor
*
* TODO: This should be probably removed in favour of ladish_app_supervisor_get_opath(); it is used for debuging purposes only
*
* @param[in] supervisor_handle supervisor object handle
*
* @retval app name; the buffer is owned by the app supervisor object
*/
const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervisor_handle);
/**
* Get number of apps that are currently running
*
* @param[in] supervisor_handle supervisor object handle
*
* @return Number of apps that are currently running
*/
unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle);
/**
* Check whether there are apps (running or not)
*
* @param[in] supervisor_handle supervisor object handle
*
* @return whether there are apps
*/
bool ladish_app_supervisor_has_apps(ladish_app_supervisor_handle supervisor_handle);
/**
* Dump to log the contents of the app supervisor
*
* @param[in] supervisor_handle supervisor object handle
*/
void ladish_app_supervisor_dump(ladish_app_supervisor_handle supervisor_handle);
/**
* Find app by name
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] name name of the app to search for
*
* @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
*/
ladish_app_handle ladish_app_supervisor_find_app_by_name(ladish_app_supervisor_handle supervisor_handle, const char * name);
/**
* Find app by id (as exposed through the D-Bus interface)
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] id id of the app
*
* @return app handle on success; NULL if app is not found; the app handle is owned by the app supervisor object
*/
ladish_app_handle ladish_app_supervisor_find_app_by_id(ladish_app_supervisor_handle supervisor_handle, uint64_t id);
/**
* Search app by process id
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] pid pid of the app to search for
*
* @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
*/
ladish_app_handle
ladish_app_supervisor_find_app_by_pid(
ladish_app_supervisor_handle supervisor_handle,
pid_t pid);
/**
* Search app by uuid
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] uuid uuid of the app to search for
*
* @return app handle on if found; NULL if app is not found; the app handle is owned by the app supervisor object
*/
ladish_app_handle
ladish_app_supervisor_find_app_by_uuid(
ladish_app_supervisor_handle supervisor_handle,
const uuid_t uuid);
/**
* The the D-Bus object path for the supervisor.
*
* @param[in] supervisor_handle supervisor object handle
*
* @retval supervisor name; the buffer is owned by the app supervisor object
*/
const char * ladish_app_supervisor_get_opath(ladish_app_supervisor_handle supervisor_handle);
/**
* Start an app. The app must be in stopped state.
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] app_handle Handle of app to start
*
* @return success status
*/
bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
/**
* Remove an app. The app must be in stopped state.
*
* @param[in] supervisor_handle supervisor object handle
* @param[in] app_handle Handle of app to remove
*/
void ladish_app_supervisor_remove_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
/**
* Get commandline for an app.
*
* @param[in] app_handle app object handle
*
* @retval app commandline; the buffer is owned by the app supervisor object
*/
const char * ladish_app_get_commandline(ladish_app_handle app_handle);
/**
* Get app state
*
* @param[in] app_handle app object handle
*
* @return app state
* @retval LADISH_APP_STATE_STOPPED app is stopped (not running)
* @retval LADISH_APP_STATE_STARTED app is running and not stopping or being killed
* @retval LADISH_APP_STATE_STOPPING app is stopping
* @retval LADISH_APP_STATE_KILL app is being force killed
*/
unsigned int ladish_app_get_state(ladish_app_handle app_handle);
/**
* Check whether app is currently running
*
* @param[in] app_handle app object handle
*
* @retval true App is running
* @retval false App is not running
*/
bool ladish_app_is_running(ladish_app_handle app_handle);
/**
* Get app name
*
* @param[in] app_handle app object handle
*
* @retval app name; the buffer is owned by the app supervisor
*/
const char * ladish_app_get_name(ladish_app_handle app_handle);
/**
* Get app uuid
*
* @param[in] app_handle app object handle
* @param[out] uuid pointer to uuid_t storage where the app uuid will be store
*
*/
void ladish_app_get_uuid(ladish_app_handle app_handle, uuid_t uuid);
/**
* Tell app to stop. The app must be in started state.
*
* @param[in] app_handle Handle of app to stop
*/
void ladish_app_stop(ladish_app_handle app_handle);
/**
* Force kill an app. The app must be in started state.
*
* @param[in] app_handle Handle of app to kill
*/
void ladish_app_kill(ladish_app_handle app_handle);
/**
* Initiate restore of app internal state. The app must be in started state.
*
* @param[in] app_handle Handle of app
*/
void ladish_app_restore(ladish_app_handle app_handle);
/**
* Associate pid with app.
*
* @param[in] app_handle Handle of app
* @param[in] pid PID to associate with the app
*/
void ladish_app_add_pid(ladish_app_handle app_handle, pid_t pid);
/**
* Deassociate pid with app.
*
* @param[in] app_handle Handle of app
* @param[in] pid PID to deassociate with the app
*/
void ladish_app_del_pid(ladish_app_handle app_handle, pid_t pid);
/**
* Set the D-Bus unique name for the app.
*
* @param[in] app_handle Handle of app
* @param[in] name D-Bus unique name
*
* @return success status
*/
bool ladish_app_set_dbus_name(ladish_app_handle app_handle, const char * name);
/**
* D-Bus interface descriptor for the app supervisor interface. The call context must be a ::ladish_app_supervisor_handle
*/
extern const struct cdbus_interface_descriptor g_iface_app_supervisor;
#endif /* #ifndef APP_SUPERVISOR_H__712E6589_DCB1_4CE9_9812_4F250D55E8A2__INCLUDED */
|