doc: add new document quick-tutorial
[src/app-framework-main.git] / scripts / afm-util
1 #!/bin/sh
2
3 if [ "x" = "x${DBUS_SESSION_BUS_ADDRESS}" ]; then
4         DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
5 fi
6 export DBUS_SESSION_BUS_ADDRESS
7
8 pretty() {
9         sed \
10                 -e '/^method return .*/d' \
11                 -e 's/^Error org.freedesktop.DBus.Error.Failed: "\?\(.*\)"\?$/ERROR: \1/' \
12                 -e 's/^   string "\(.*\)"/\1/' \
13                 -e 's/},/&\n/'
14 }
15
16 send() {
17         dbus-send --session --print-reply \
18                 --dest=org.AGL.afm.user \
19                 /org/AGL/afm/user \
20                 org.AGL.afm.user.$1 \
21                 "string:$2" |
22         pretty
23 }
24
25 case "$1" in
26
27   list|runnables)
28     send runnables true
29     ;;
30
31   add|install)
32     f=$(realpath $2)
33     send install '{"wgt":"'"$f"'","force":true}'
34     ;;
35
36   remove|uninstall)
37     i=$2
38     send uninstall "\"$i\""
39     ;;
40
41   info|detail)
42     i=$2
43     send detail "\"$i\""
44     ;;
45
46   ps|runners)
47     send runners true
48     ;;
49
50   run|start)
51     i=$2
52     send start "\"$i\""
53     ;;
54
55   terminate|kill)
56     i=$2
57     send terminate "$i"
58     ;;
59
60   stop|pause)
61     i=$2
62     send stop "$i"
63     ;;
64
65   resume|continue)
66     i=$2
67     send continue "$i"
68     ;;
69
70   state|status)
71     i=$2
72     send state "$i"
73     ;;
74
75   -h|--help|help)
76     cat << EOC
77 usage: $(basename $0) command [arg]
78
79 The commands are:
80
81   list
82   runnables      list the runnable widgets installed
83
84   add wgt
85   install wgt    install the wgt file
86
87   remove id
88   uninstall id   remove the installed widget of id
89
90   info id
91   detail id      print detail about the installed widget of id
92
93   ps
94   runners        list the running instance
95
96   run id
97   start id       start an instance of the widget of id
98
99   kill rid
100   terminate rid       terminate the running instance rid
101
102   stop rid
103   pause rid      stop the running instance rid
104
105   resume rid
106   continue rid   continue the previously rid
107
108   status rid
109   state rid     get status of the running instance rid
110
111 EOC
112     ;;
113
114   *)
115     echo "unknown command $1" >&2
116     exit 1
117     ;;
118 esac
119
120