26#include <blackboard/remote.h>
27#include <core/threading/thread.h>
28#include <interfaces/SwitchInterface.h>
29#include <utils/system/argparser.h>
30#include <utils/system/signal.h>
31#include <utils/time/time.h>
37# include <libdaemon/dfork.h>
38# include <libdaemon/dlog.h>
39# include <libdaemon/dpid.h>
70 printf(
"Lost connection to blackboard\n");
71 bb_->
close(switch_if_);
76 printf(
"Trying to connect to remote BB...");
79 printf(
"succeeded\n");
90 if ((now - until_) >= 0) {
100 if (msg->
value() > 0.0) {
111 float duration = fabs(msg->
duration());
112 float value = fabs(msg->
value());
148usage(
const char *progname)
156 daemon_retval_send(-1);
157 daemon_retval_done();
158 daemon_pid_file_remove();
162daemonize(
int argc,
char **argv)
165 mode_t old_umask = umask(0);
168 daemon_retval_init();
171 if ((pid = daemon_fork()) < 0) {
178 if ((ret = daemon_retval_wait(20)) < 0) {
179 daemon_log(LOG_ERR,
"Could not recieve return value from daemon process.");
184 daemon_log(LOG_ERR,
"*** Daemon startup failed, see syslog for details. ***");
186 case 1: daemon_log(LOG_ERR,
"Daemon failed to close file descriptors");
break;
187 case 2: daemon_log(LOG_ERR,
"Daemon failed to create PID file");
break;
195# ifdef DAEMON_CLOSE_ALL_AVAILABLE
196 if (daemon_close_all(-1) < 0) {
197 daemon_log(LOG_ERR,
"Failed to close all file descriptors: %s", strerror(errno));
199 daemon_retval_send(1);
205 if (daemon_pid_file_create() < 0) {
206 printf(
"Could not create PID file (%s).", strerror(errno));
207 daemon_log(LOG_ERR,
"Could not create PID file (%s).", strerror(errno));
210 daemon_retval_send(2);
215 daemon_retval_send(0);
217 daemon_log(LOG_INFO,
"Sucessfully started");
226const char *fawkes_pid_file;
232fawkes_daemon_pid_file_proc()
234 return fawkes_pid_file;
243main(
int argc,
char **argv)
252 daemon_pid_file_ident = daemon_log_ident = daemon_ident_from_argv0(argv[0]);
253 if (argp->
arg(
"D") != NULL) {
254 fawkes_pid_file = argp->
arg(
"D");
255 daemon_pid_file_proc = fawkes_daemon_pid_file_proc;
261 if ((pid = daemon_pid_file_is_running()) < 0) {
262 daemon_log(LOG_ERR,
"Fawkes daemon not running.");
268 if ((ret = daemon_pid_file_kill_wait(SIGINT, 5)) < 0) {
269 daemon_log(LOG_WARNING,
"Failed to kill daemon");
271 return (ret < 0) ? 1 : 0;
276 return (daemon_pid_file_is_running() < 0);
280 if ((pid = daemon_pid_file_is_running()) >= 0) {
281 daemon_log(LOG_ERR,
"Daemon already running on (PID %u)", pid);
285 pid = daemonize(argc, argv);
296 printf(
"Daemonizing support is not available.\n"
297 "(libdaemon[-devel] was not available at compile time)\n");
311 SignalManager::register_handler(SIGINT, &beepd);
312 SignalManager::register_handler(SIGTERM, &beepd);
317 Thread::destroy_main();
Simple speaker beep controller.
void beep_on(float freq=1000)
Enable beeping.
void beep_off()
Disable beeping.
virtual void loop()
Code to execute in the thread.
void handle_signal(int signum)
Handle signals.
FawkesBeepDaemon()
Constructor.
Parse command line arguments.
const char * arg(const char *argn)
Get argument value.
bool has_arg(const char *argn)
Check if argument has been supplied.
The BlackBoard abstract class.
virtual bool is_alive() const noexcept=0
Check if the BlackBoard is still alive.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
bool msgq_first_is()
Check if first message has desired type.
void msgq_pop()
Erase first message from queue.
Message * msgq_first()
Get the first message from the message queue.
bool msgq_empty()
Check if queue is empty.
bool is_valid() const
Check validity of interface.
Interface for signal handling.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
EnableDurationMessage Fawkes BlackBoard Interface Message.
float value() const
Get value value.
float duration() const
Get duration value.
EnableSwitchMessage Fawkes BlackBoard Interface Message.
SetMessage Fawkes BlackBoard Interface Message.
float value() const
Get value value.
bool is_enabled() const
Get enabled value.
SwitchInterface Fawkes BlackBoard Interface.
Thread class encapsulation of pthreads.
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void cancel()
Cancel a thread.
@ OPMODE_CONTINUOUS
operate in continuous mode (default)
A class for handling time.
Fawkes library namespace.