#!/bin/sh
#
# Try talking to the jami daemon via DBus messages.

set -e

at_exit() {
    echo "info: test exiting"
}
trap at_exit INT TERM EXIT

dringop() {
    part="$1"; shift
    op="$1"; shift
    dbus-send --session \
        --dest="cx.ring.Ring" /cx/ring/Ring/$part cx.ring.Ring.$part.$op $*
}

dringopreply() {
    part="$1"; shift
    op="$1"; shift
    xvfb-run -a dbus-send --session --print-reply \
        --dest="cx.ring.Ring" /cx/ring/Ring/$part cx.ring.Ring.$part.$op $*
}

firstaccount() {
    dringopreply ConfigurationManager getAccountList | \
      grep string | awk -F'"' '{print $2}' | head -n 1
}

echo "info: Trying to fetch account information from jami daemon"
account=$(firstaccount)
echo "info: Completed fetching of account information: $account"

exit 0
