afm-util: don't reload if afm-install
[src/app-framework-main.git] / scripts / afm-util
index 60434a7..c5e48eb 100755 (executable)
@@ -1,25 +1,8 @@
-#!/bin/sh
-
-if [ "x" = "x${DBUS_SESSION_BUS_ADDRESS}" ]; then
-       DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
-fi
-export DBUS_SESSION_BUS_ADDRESS
-
-pretty() {
-       sed \
-               -e '/^method return .*/d' \
-               -e 's/^Error org.freedesktop.DBus.Error.Failed: "\?\(.*\)"\?$/ERROR: \1/' \
-               -e 's/^   string "\(.*\)"/\1/' \
-               -e 's/},/&\n/'
-}
+#!/bin/bash
 
 send() {
-       dbus-send --session --print-reply \
-               --dest=org.AGL.afm.user \
-               /org/AGL/afm/user \
-               org.AGL.afm.user.$1 \
-               "string:$2" |
-       pretty
+       afb-client-demo -H -d unix:/run/afm/apis/ws/afm-main "$1" "$2" |
+       awk '$1=="ON-REPLY-FAIL"{$1="ERROR:";$2="";print;exit 1;}NR>1'
 }
 
 case "$1" in
@@ -30,7 +13,9 @@ case "$1" in
 
   add|install)
     f=$(realpath $2)
-    send install '{"wgt":"'"$f"'","force":true}'
+    r=true
+    if [[ "$(basename $0)" = "afm-install" ]]; then r=false; fi
+    send install '{"wgt":"'"$f"'","force":true,"reload":'"$r"'}'
     ;;
 
   remove|uninstall)
@@ -52,6 +37,16 @@ case "$1" in
     send start "\"$i\""
     ;;
 
+  run-remote|start-remote)
+    i=$2
+    send start '{"id":"'"$i"'","mode":"remote"}'
+    ;;
+
+  once)
+    i=$2
+    send once "\"$i\""
+    ;;
+
   terminate|kill)
     i=$2
     send terminate "$i"
@@ -59,12 +54,12 @@ case "$1" in
 
   stop|pause)
     i=$2
-    send stop "$i"
+    send pause "$i"
     ;;
 
   resume|continue)
     i=$2
-    send continue "$i"
+    send resume "$i"
     ;;
 
   state|status)
@@ -96,17 +91,19 @@ The commands are:
   run id
   start id       start an instance of the widget of id
 
+  once id        run once an instance of the widget of id
+
   kill rid
-  terminate rid       terminate the running instance rid
+  terminate rid  terminate the running instance rid
 
   stop rid
-  pause rid      stop the running instance rid
+  pause rid      pause the running instance rid
 
   resume rid
-  continue rid   continue the previously rid
+  continue rid   continue the previously paused rid
 
   status rid
-  state rid     get status of the running instance rid
+  state rid      get status of the running instance rid
 
 EOC
     ;;