From 930af02f228ed63a535c6a93211d3f6a10c7b772 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 22 Mar 2019 14:05:05 -0400 Subject: [PATCH] Differentiate start functions rather than setting a variable --- x4/bin/khatus_x4_lib_common_sensor.sh | 29 ++++++++++++++++++++++----- x4/bin/khatus_x4_sensor_bluetooth | 2 +- x4/bin/khatus_x4_sensor_datetime | 2 +- x4/bin/khatus_x4_sensor_energy | 3 +-- x4/bin/khatus_x4_sensor_mpd | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/x4/bin/khatus_x4_lib_common_sensor.sh b/x4/bin/khatus_x4_lib_common_sensor.sh index fae1356..8dd5737 100755 --- a/x4/bin/khatus_x4_lib_common_sensor.sh +++ b/x4/bin/khatus_x4_lib_common_sensor.sh @@ -2,6 +2,10 @@ set -e +# ============================================================================= +# Private +# ============================================================================= + # Defaults prefix='/dev/shm/khatus' host="$(hostname)" @@ -85,16 +89,16 @@ run_in_foreground() { trap true INT trap exit TERM trap pid_file_remove EXIT - $run_as + $1 } run_in_background_2nd_fork() { - run_in_foreground & + run_in_foreground $1 & pid_file_create_of_child } run_in_background() { - run_in_background_2nd_fork & + run_in_background_2nd_fork $1 & } run() { @@ -108,15 +112,30 @@ run() { pid_file_test case "$run_in" in 'background') - run_in_background + run_in_background $1 ;; 'foreground') pid_file_create_of_parent - run_in_foreground + run_in_foreground $1 ;; *) printf "Error - illegal value for \$run_in: $run_in\n" 1>&2 exit 1 esac } +# ============================================================================= +# API +# ----------------------------------------------------------------------------- +# run_as_poller +# run_as_streamer +# ============================================================================= + +run_as_poller() { + run 'poller' +} + +run_as_streamer() { + run 'streamer' +} + set_common_options $@ init_dirs diff --git a/x4/bin/khatus_x4_sensor_bluetooth b/x4/bin/khatus_x4_sensor_bluetooth index 96d28a8..71c6a06 100755 --- a/x4/bin/khatus_x4_sensor_bluetooth +++ b/x4/bin/khatus_x4_sensor_bluetooth @@ -20,4 +20,4 @@ sensor() { printf "count_connected_devices %d\n" $(count_connected_devices) } -run +run_as_poller diff --git a/x4/bin/khatus_x4_sensor_datetime b/x4/bin/khatus_x4_sensor_datetime index 4665847..2b204f9 100755 --- a/x4/bin/khatus_x4_sensor_datetime +++ b/x4/bin/khatus_x4_sensor_datetime @@ -8,4 +8,4 @@ sensor() { printf "datetime $(date +'%a %b %d %H:%M:%S')\n" } -run +run_as_poller diff --git a/x4/bin/khatus_x4_sensor_energy b/x4/bin/khatus_x4_sensor_energy index a7ade3f..e447523 100755 --- a/x4/bin/khatus_x4_sensor_energy +++ b/x4/bin/khatus_x4_sensor_energy @@ -11,5 +11,4 @@ sensor() { stdbuf -o L upower --monitor-detail | stdbuf -o L "$bin_dir"/khatus_x4_parse_upower } -run_as='streamer' -run +run_as_streamer diff --git a/x4/bin/khatus_x4_sensor_mpd b/x4/bin/khatus_x4_sensor_mpd index cc29595..fe3f16f 100755 --- a/x4/bin/khatus_x4_sensor_mpd +++ b/x4/bin/khatus_x4_sensor_mpd @@ -24,4 +24,4 @@ sensor() { | "$bin_dir"/khatus_x4_parse_mpd_status_currentsong } -run +run_as_poller -- 2.20.1