/* * exec.c * * Copyright (c) 2009 Ismael Gomez-Miguelez, UPC . All rights reserved. * * * This file is part of ALOE. * * ALOE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ALOE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ALOE. If not, see . * */ /* standard libraries */ #include #include #include "phal_hw_api.h" #include "phal_daemons.h" #include "phid.h" #include "pkt.h" #include "set.h" #include "daemon.h" #include "exec.h" /* include command declarations */ #include "exec_cmds.h" /* main function declaration */ void exec_run(); void exec_alloc(); int exec_init(daemon_o daemon); int exec_background(); #ifdef RUN_AS_PROC int main() { exec_run(); return 1; } #endif static cmd_t cmds[] = {{ EXEC_SETSTATUS, exec_incmd_setstatus, "Set new object status", "Error setting object status"}, { EXEC_REPORTSTART, exec_incmd_reportcmd, "Start reports", "Error starting reports"}, { EXEC_REPORTSTOP, exec_incmd_reportcmd, "Stop reports", "Error stopping reports"}, { 0, NULL, NULL, NULL}}; /** EXEC Daemon Main Routine */ void exec_run() { daemon_o daemon; int n; if (!hwapi_init ()) { printf("Error initiating api\n"); exit(-1); } exec_alloc(); daemon = daemon_new(DAEMON_EXEC, cmds); if (!daemon) { xprintf ("SWMAN: Error creating daemon\n"); exit(-1); } exec_init(daemon); xprintf ("EXEC: Init ok\n"); /** main daemon loop * while packets in queue, process them */ while (1) { do { n = daemon_rcvpkt(daemon); if (n > 0) { daemon_processcmd(daemon); } if (n<0) { exit(-1); } } while (n); /** After all commands are processed, we will execute the * real-time and execution status monitoring */ exec_background(); hwapi_relinquish_daemon(); } daemon_delete(&daemon); exit(-1); }