5 https://git.automotivelinux.org/src/app-framework-main/plain/docs/1-afm-daemons.md?h=master
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/apis_services/master/app-framework-main-developer-guides-api-services-book.yml -->
10 # The application framework daemons
14 This document describes application framework daemons
15 FCS (Fully Conform to Specification) implementation is still under development.
16 It may happen that current implementation somehow diverges with specifications.
20 Daemons ***afm-user-daemon*** and ***afm-system-daemon*** handle applications
22 Understand that they will manage operations like:
25 - ***uninstallation***
31 In addition, they ensure that operations use the security framework as needed
32 and that applications are executed in the correct context.
34 ***D-Bus*** is in charge of transmitting orders to the appropriate daemon
35 depending upon ***D-Bus*** destination.
37 The figure below summarizes the situation of both **afm-system-daemon** and
38 **afm-user-daemon** in the system.
40 ![afm-daemons][afm-daemons]{:: style="width:65%;"}
42 ## The D-Bus interface
44 ### Overview of the dbus interface
46 The ***afm daemons*** takes theirs orders from the session instance
48 The use of D-Bus is great because it allows to implement
49 discovery and signaling.
51 The dbus session is by default addressed by environment
52 variable *DBUS_SESSION_BUS_ADDRESS*. Using **systemd**
53 variable *DBUS_SESSION_BUS_ADDRESS* is automatically set for
56 They are listening with the destination name ***org.AGL.afm.[user|system]***
57 at the object of path ***/org/AGL/afm/[user|system]*** on the interface
58 ***org.AGL.afm.[user|system]*** for the below detailed members for the
59 ***afm-system-daemon***:
64 And for ***afm-user-daemon***:
78 D-Bus is mainly used for signaling and discovery.
79 Its optimized typed protocol is not used except for transmitting
80 only one string in both directions.
82 The client and the service are using JSON serialization to
84 Signature of any member of the D-Bus interface is
85 ***string -> string*** for ***JSON -> JSON***.
86 This is the normal case, if there is an error, current implementation
87 returns a dbus error that is a string.
89 Here are examples using *dbus-send*, here to install an application from a
93 dbus-send --session --print-reply \
94 --dest=org.AGL.afm.system \
96 org.AGL.afm.system.install 'string:"/tmp/appli.wgt"
99 And here, to query data on installed applications that can be run:
102 dbus-send --session --print-reply \
103 --dest=org.AGL.afm.user \
105 org.AGL.afm.user.runnables string:true
108 ### The protocol over D-Bus
110 On all following sub-chapters we assume that we talk about either
111 ***afm-system-daemon*** or ***afm-user-daemon***. Method and D-Bus parameters
112 are considered as self-explanatory.
114 The D-Bus interface is defined by:
116 - **DESTINATION**: org.AGL.afm.[user|system]
117 - **PATH**: /org/AGL/afm/[user|system]
118 - **INTERFACE**: org.AGL.afm.[user|system]
120 #### Method org.AGL.afm.system.install
122 **Description**: Install an application from a widget file.
124 When an application with the same *id* and *version* already exists. Outside of
125 using *force=true* the application is not reinstalled.
127 Applications are installed the subdirectories of applications common directory.
128 If *root* is specified, the application is installed under the
129 sub-directories of the *root* defined.
131 Note that this methods is a simple accessor method of
132 ***org.AGL.afm.system.install*** from ***afm-system-daemon***.
134 After the installation and before returning to the sender,
135 ***afm-system-daemon*** sends a signal ***org.AGL.afm.system.changed***.
137 **Input**: The *path* of the widget file to install and, optionally,
138 a flag to *force* reinstallation, and, optionally, a *root* directory.
140 Either just a string being the absolute path of the widget file:
143 "/a/path/driving/to/the/widget"
150 "wgt": "/a/path/to/the/widget",
152 "root": "/a/path/to/the/root"
156 "wgt" and "root" must be absolute paths.
158 **output**: An object with the field "added" being the string for
159 the id of the added application.
162 {"added":"appli@x.y"}
167 #### Method org.AGL.afm.system.uninstall
169 **Description**: Uninstall an application from its id.
171 Note that this methods is a simple method accessor of
172 ***org.AGL.afm.system.uninstall*** from ***afm-system-daemon***.
174 After the uninstallation and before returning to the sender,
175 ***afm-system-daemon*** sends a signal ***org.AGL.afm.system.changed***.
177 **Input**: the *id* of the application and optionally the application *root* path.
190 "root": "/a/path/to/the/root"
194 **output**: the value 'true'.
198 #### Method org.AGL.afm.user.detail
200 **Description**: Get details about an application from its id.
202 **Input**: the id of the application as below.
204 Either just a string:
210 Or an object having the field "id" of type string:
216 **Output**: A JSON object describing the application containing
217 the fields described below.
221 "id": string, the application id (id@version)
222 "version": string, the version of the application
223 "width": integer, requested width of the application
224 "height": integer, requested height of the application
225 "name": string, the name of the application
226 "description": string, the description of the application
227 "shortname": string, the short name of the application
228 "author": string, the author of the application
234 #### Method org.AGL.afm.user.runnables
236 **Description**: Get the list of applications that can be run.
238 **Input**: any valid json entry, can be anything except null.
240 **output**: An array of description of the runnable applications.
241 Each item of the array contains an object containing the detail of
242 an application as described above for the method
243 *org.AGL.afm.user.detail*.
247 #### Method org.AGL.afm.user.install
249 **Description**: Install an application from its widget file.
251 If an application of the same *id* and *version* exists, it is not
252 reinstalled except when *force=true*.
254 Applications are installed in the subdirectories of the common directory
255 reserved for applications.
256 If *root* is specified, the application is installed under
257 sub-directories of defined *root*.
259 Note that this methods is a simple accessor to the method
260 ***org.AGL.afm.system.install*** of ***afm-system-daemon***.
262 After the installation and before returning to the sender,
263 ***afm-user-daemon*** sends the signal ***org.AGL.afm.user.changed***.
265 **Input**: The *path* of widget file to be installed. Optionally,
266 a flag to *force* reinstallation and/or a *root* directory.
268 Simple form a simple string containing the absolute widget path:
271 "/a/path/driving/to/the/widget"
278 "wgt": "/a/path/to/the/widget",
280 "root": "/a/path/to/the/root"
284 ***wgt*** and ***root*** MUST be absolute paths.
286 **output**: An object containing field "added" to use as application ID.
289 {"added":"appli@x.y"}
294 #### Method org.AGL.afm.user.uninstall
296 **Description**: Uninstall an application from its id.
298 Note that this methods is a simple accessor to
299 ***org.AGL.afm.system.uninstall*** method from ***afm-system-daemon***.
301 After the uninstallation and before returning to the sender,
302 ***afm-user-daemon*** sends the signal ***org.AGL.afm.user.changed***.
304 **Input**: the *id* of the application and, optionally, the path to
318 "root": "/a/path/to/the/root"
322 **output**: the value 'true'.
326 #### Method org.AGL.afm.user.start
330 **Input**: the *id* of the application and, optionally, the
331 start *mode* as below.
333 Either just a string:
339 Or an object containing field "id" of type string and
340 optionally a field mode:
343 {"id":"appli@x.y","mode":"local"}
346 The field "mode" is a string equal to either "local" or "remote".
348 [Currently the mode is not available in the systemd version]
350 **output**: The *runid* of the application launched. *runid* is an integer.
354 #### Method org.AGL.afm.user.once
358 **Input**: the *id* of the application
360 Either just a string:
366 Or an object containing field "id" of type string.
372 **output**: The *state* of the application retrieved or launched.
373 See *org.AGL.afm.user.state* to get a description of the returned
378 #### Method org.AGL.afm.user.terminate
380 **Description**: Terminates the application attached to *runid*.
382 **Input**: The *runid* (an integer) of running instance to terminate.
384 **output**: the value 'true'.
388 #### Method org.AGL.afm.user.stop
390 Obsolete since 8th November 2016 (2016/11/08).
391 Kept for compatibility.
393 Use **org.AGL.afm.user.pause** instead.
397 #### Method org.AGL.afm.user.continue
399 Obsolete since 8th November 2016 (2016/11/08).
400 Kept for compatibility.
402 Use **org.AGL.afm.user.resume** instead.
406 #### Method org.AGL.afm.user.pause
408 [Currently not available in the systemd version]
410 **Description**: Pauses the application attached to *runid* until terminate or resume.
412 **Input**: The *runid* (integer) of the running instance to pause.
414 **output**: the value 'true'.
418 #### Method org.AGL.afm.user.resume
420 [Currently not available in the systemd version]
422 **Description**: Resumes the application attached to *runid* previously paused.
424 **Input**: The *runid* (integer) of the running instance to resume.
426 **output**: the value 'true'.
430 #### Method org.AGL.afm.user.state
432 **Description**: Get information about a running instance of *runid*.
434 **Input**: The *runid* (integer) of the running instance inspected.
436 **output**: An object describing instance state.
439 - the runid (integer)
440 - the pids of the processes as an array starting
441 - with the group leader
442 - the id of the running application (string)
443 - the state of the application (string either: "starting", "running", "paused").
445 Example of returned state:
450 "pids": [ 435, 436 ],
458 #### Method org.AGL.afm.user.runners
460 **Description**: Get the list of currently running instances.
464 **output**: An array of states, one per running instance, as returned by
465 the method ***org.AGL.afm.user.state***.
467 ## Starting **afm daemons**
469 ***afm-system-daemon*** and ***afm-user-daemon*** are launched as systemd
470 services attached to system and user respectively.
471 Normally, service files are locatedat */lib/systemd/system/afm-system-daemon.service* and
472 */usr/lib/systemd/user/afm-user-daemon.service*.
474 ### ***afm-system-daemon*** options
476 The options for launching **afm-system-daemon** are:
482 Set the root application directory.
484 Note that the default root directory is defined
485 to be /usr/share/afm/applications (may change).
490 Daemonizes the process. It is not needed by systemd.
495 Reduces the verbosity (can be repeated).
500 Increases the verbosity (can be repeated).
508 ### ***afm-user-daemon*** options
510 The options for launching **afm-user-daemon** are:
514 --application directory
516 [Currently not available in the systemd version]
518 Includes the given application directory to
519 the database base of applications.
526 [Currently not available in the systemd version]
528 Includes root application directory or directories when
529 passing multiple rootdir to
530 applications database.
532 Note that default root directory for
533 applications is always added. In current version
534 /usr/share/afm/applications is used as default.
537 --mode (local|remote)
539 [Currently not available in the systemd version]
541 Set the default launch mode.
542 The default value is 'local'
547 Daemonizes the process. It is not needed by systemd.
552 Reduces the verbosity (can be repeated).
557 Increases the verbosity (can be repeated).
565 ## Tasks of **afm-user-daemon**
567 ### Maintaining list of applications
569 At start **afm-user-daemon** scans the directories containing
570 applications and load in memory a list of available applications
571 accessible by current user.
573 When **afm-system-daemon** installs or removes an application.
574 On success it sends the signal *org.AGL.afm.system.changed*.
575 When receiving such a signal, **afm-user-daemon** rebuilds its
578 **afm-user-daemon** provides the data it collects about
579 applications to its clients.
580 Clients may either request the full list
581 of available applications or a more specific information about a
584 ### Launching application
586 **afm-user-daemon** launches application by using systemd.
587 Systemd builds a secure environment for the application
590 Once launched, running instances of application receive
591 a runid that identify them.
592 To make interface with systemd evident, the pid is the runid.
594 ### Managing instances of running applications
596 **afm-user-daemon** manages the list of applications
599 When owning the right permissions, a client can get the list
600 of running instances and details about a specific
602 It can also terminate a given application.
604 ### Installing and uninstalling applications
606 If the client own the right permissions,
607 **afm-user-daemon** delegates that task
608 to **afm-system-daemon**.
610 ## Using ***afm-util***
612 The command line tool ***afm-util*** uses dbus-send to send
613 orders to **afm-user-daemon**.
614 This small scripts allows to send command to ***afm-user-daemon*** either
615 interactively at shell prompt or scriptically.
617 The syntax is simple:
619 - it accept a command and when requires attached arguments.
621 Here is the summary of ***afm-util***:
623 - **afm-util runnables **:
624 list the runnable widgets installed
626 - **afm-util install wgt **:
629 - **afm-util uninstall id **:
630 remove the installed widget of id
632 - **afm-util detail id **:
633 print detail about the installed widget of id
635 - **afm-util runners **:
636 list the running instance
638 - **afm-util start id **:
639 start an instance of the widget of id
641 - **afm-util once id **:
642 run once an instance of the widget of id
644 - **afm-util terminate rid **:
645 terminate the running instance rid
647 - **afm-util state rid **:
648 get status of the running instance rid
650 Here is how to list applications using ***afm-util***:
656 [afm-daemons]: pictures/afm-daemons.svg