[tuxdroid-svn] r110 - daemon/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-02-28 01:55:44
|
Author: jaguarondi Date: 2007-02-28 02:55:29 +0100 (Wed, 28 Feb 2007) New Revision: 110 Added: daemon/trunk/main.c Removed: daemon/trunk/USBDaemon_main.c Modified: daemon/trunk/Makefile Log: - CLN: renamed USBDaemon_main.c into main.c Modified: daemon/trunk/Makefile =================================================================== --- daemon/trunk/Makefile 2007-02-28 01:52:35 UTC (rev 109) +++ daemon/trunk/Makefile 2007-02-28 01:55:29 UTC (rev 110) @@ -37,7 +37,7 @@ endif SRC_OBJS = \ - $(OBJ_DIR)/USBDaemon_main.o \ + $(OBJ_DIR)/main.o \ $(OBJ_DIR)/USBDaemon_usb_enum.o \ $(OBJ_DIR)/USBDaemon_usb_readWrite.o \ $(OBJ_DIR)/USBDaemon_status_table.o \ @@ -82,7 +82,7 @@ version.h: version.txt @echo "#define VERSION \"`cat version.txt`\"" > version.h -$(OBJ_DIR)/USBDaemon_main.o: USBDaemon_main.c \ +$(OBJ_DIR)/main.o: main.c \ libs/USBDaemon_globals.h \ libs/USBDaemon_usb_enum.h \ libs/USBDaemon_tcp_server.h \ Deleted: daemon/trunk/USBDaemon_main.c =================================================================== --- daemon/trunk/USBDaemon_main.c 2007-02-28 01:52:35 UTC (rev 109) +++ daemon/trunk/USBDaemon_main.c 2007-02-28 01:55:29 UTC (rev 110) @@ -1,218 +0,0 @@ -/* -* Tux Droid - USB Daemon -* Copyright (C) 2007 C2ME Sa <rem...@c2...> -* -* This program 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 2, or (at your option) -* any later version. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -* 02111-1307, USA. -*/ -/* $Id$ */ -/*_____________________ I N C L U D E S____________________________________ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <usb.h> -#include <glib.h> -#include <glib-object.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <time.h> -#include <signal.h> -#include "libs/USBDaemon_globals.h" -#include "libs/USBDaemon_usb_enum.h" -#include "libs/USBDaemon_tcp_server.h" -#include "libs/USBDaemon_status_table.h" -#include "version.h" -/*_____________________ F U N C T I O N S __________________________________*/ - -struct version_s version = {0, 0, 0, "\0", "\0", 0}; - - // *********************************************************************** - // Print_info_daemon - // *********************************************************************** - void - print_info_daemon() - { - const char delimiters[] = " .-"; - char cp[] = VERSION; - char *token; - - if ((token = strtok (cp, delimiters)) != NULL) - version.major = atoi (token); - if ((token = strtok (NULL, delimiters)) != NULL) - version.minor = atoi (token); - if ((token = strtok (NULL, delimiters)) != NULL) - version.release = atoi (token); - if ((token = strtok (NULL, delimiters)) != NULL) - strncpy (version.maturity, token, 10); - if ((token = strtok (NULL, delimiters)) != NULL) - strncpy (version.release_status, token, 20); - - printf("-----------------------------------\n"); - printf("Tux USB Daemon version %s\n",VERSION); - printf("Kysoh 2007.\n"); - printf("-----------------------------------\n"); - } - - // *********************************************************************** - // On_close_daemon - // *********************************************************************** - void - on_close_daemon() - { - send_daemon_disconnected(); - printf("Daemon closed\n"); - exit(0); - } - - // *********************************************************************** - // Daemonizer - // *********************************************************************** - void - daemonize(unsigned char shell_view) - { - pid_t pid,sid; - - pid=fork(); - switch(pid){ - case 0: - break; - case -1: //erreur - exit(1); - break; - default : - exit(0); - } - umask(0); - sid=setsid(); - if(sid<0){ - perror("sid"); - exit(1); - } - if(chdir("/")<0){ - perror("chdir"); - exit(1); - } - DAEMON_PID=(unsigned short)getpid(); - printf("Daemon started : pid=%d\n",(int)getpid()); - // No shell - if(!shell_view) - { - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - } - } - - // *********************************************************************** - // Show usages of tux daemon - // *********************************************************************** - void - usage() - { - printf("usage : tuxdaemon [options]\n"); - printf("options:\n"); - printf(" -d start in daemon mode\n"); - printf(" -v view in shell ( for daemon mode )\n"); - printf(" -st show the structure of the usb trames\n"); - printf(" -sr show all raw statutes\n"); - printf(" -si show only invalid raw statutes\n"); - printf(" -h show this usage list\n"); - } - - // *********************************************************************** - // USBDaemon main function - // *********************************************************************** - int - main( - int argc, - char *argv[] - ) - { - GMainLoop *loop; - GThread *UsbThread; - GThread *TcpThread; - GError *error=NULL; - unsigned char i; - unsigned char shell_view; - unsigned char daemonized; - - // Print daemon informations - print_info_daemon(); - // Program arguments - daemonized=0; - shell_view=0; - SHOW_TRAMES=0; - SHOW_RAW_STATUS=0; - SHOW_INVALID_RAW=0; - if(argc>1){ - for(i=1;i<argc;i++){ - if(!strcmp("-v", argv[i])) - shell_view=1; - else if(!strcmp("-d", argv[i])) - daemonized=1; - else if(!strcmp("-st", argv[i])) - SHOW_TRAMES=1; - else if(!strcmp("-sr", argv[i])) - SHOW_RAW_STATUS=1; - else if(!strcmp("-si", argv[i])) - SHOW_INVALID_RAW=1; - else if(!strcmp("-h", argv[i])){ - usage(); - exit(1); - }else{ - usage(); - exit(1); - } - } - } - if(daemonized) - daemonize(shell_view); - // On exiting - signal(SIGINT, on_close_daemon); - signal(SIGKILL, on_close_daemon); - // Gestion Multithread - if (!g_thread_supported()) { - g_thread_init(NULL); - }else{ - printf("g_thread NOT supported\n"); - return 1; - } - - TUX_USB_STATUS=0; - TUX_TCP_STATUS=0; - CLOSE_DAEMON=0; - last_remote_key=0xFF; - last_toggle_key=0xFF; - sound_flash_count=0; - - // Start USB task thread - if ((UsbThread = g_thread_create((GThreadFunc)usb_start_task,NULL,TRUE,&error))== NULL ) { - printf("Thread creation failed: %s \n",error->message); - return 2; - } - - // Start TCP task thread - if ((TcpThread = g_thread_create((GThreadFunc)tcp_server_start_task,NULL,TRUE,&error))== NULL ) { - printf("Thread creation failed: %s \n",error->message); - return 2; - } - loop = g_main_loop_new(NULL,FALSE); - g_main_loop_run(loop); - return 0; - } - - Copied: daemon/trunk/main.c (from rev 109, daemon/trunk/USBDaemon_main.c) =================================================================== --- daemon/trunk/main.c (rev 0) +++ daemon/trunk/main.c 2007-02-28 01:55:29 UTC (rev 110) @@ -0,0 +1,218 @@ +/* +* Tux Droid - USB Daemon +* Copyright (C) 2007 C2ME Sa <rem...@c2...> +* +* This program 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 2, or (at your option) +* any later version. +* +* This program 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 this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +* 02111-1307, USA. +*/ +/* $Id$ */ +/*_____________________ I N C L U D E S____________________________________ */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <usb.h> +#include <glib.h> +#include <glib-object.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <time.h> +#include <signal.h> +#include "libs/USBDaemon_globals.h" +#include "libs/USBDaemon_usb_enum.h" +#include "libs/USBDaemon_tcp_server.h" +#include "libs/USBDaemon_status_table.h" +#include "version.h" +/*_____________________ F U N C T I O N S __________________________________*/ + +struct version_s version = {0, 0, 0, "\0", "\0", 0}; + + // *********************************************************************** + // Print_info_daemon + // *********************************************************************** + void + print_info_daemon() + { + const char delimiters[] = " .-"; + char cp[] = VERSION; + char *token; + + if ((token = strtok (cp, delimiters)) != NULL) + version.major = atoi (token); + if ((token = strtok (NULL, delimiters)) != NULL) + version.minor = atoi (token); + if ((token = strtok (NULL, delimiters)) != NULL) + version.release = atoi (token); + if ((token = strtok (NULL, delimiters)) != NULL) + strncpy (version.maturity, token, 10); + if ((token = strtok (NULL, delimiters)) != NULL) + strncpy (version.release_status, token, 20); + + printf("-----------------------------------\n"); + printf("Tux USB Daemon version %s\n",VERSION); + printf("Kysoh 2007.\n"); + printf("-----------------------------------\n"); + } + + // *********************************************************************** + // On_close_daemon + // *********************************************************************** + void + on_close_daemon() + { + send_daemon_disconnected(); + printf("Daemon closed\n"); + exit(0); + } + + // *********************************************************************** + // Daemonizer + // *********************************************************************** + void + daemonize(unsigned char shell_view) + { + pid_t pid,sid; + + pid=fork(); + switch(pid){ + case 0: + break; + case -1: //erreur + exit(1); + break; + default : + exit(0); + } + umask(0); + sid=setsid(); + if(sid<0){ + perror("sid"); + exit(1); + } + if(chdir("/")<0){ + perror("chdir"); + exit(1); + } + DAEMON_PID=(unsigned short)getpid(); + printf("Daemon started : pid=%d\n",(int)getpid()); + // No shell + if(!shell_view) + { + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + } + } + + // *********************************************************************** + // Show usages of tux daemon + // *********************************************************************** + void + usage() + { + printf("usage : tuxdaemon [options]\n"); + printf("options:\n"); + printf(" -d start in daemon mode\n"); + printf(" -v view in shell ( for daemon mode )\n"); + printf(" -st show the structure of the usb trames\n"); + printf(" -sr show all raw statutes\n"); + printf(" -si show only invalid raw statutes\n"); + printf(" -h show this usage list\n"); + } + + // *********************************************************************** + // USBDaemon main function + // *********************************************************************** + int + main( + int argc, + char *argv[] + ) + { + GMainLoop *loop; + GThread *UsbThread; + GThread *TcpThread; + GError *error=NULL; + unsigned char i; + unsigned char shell_view; + unsigned char daemonized; + + // Print daemon informations + print_info_daemon(); + // Program arguments + daemonized=0; + shell_view=0; + SHOW_TRAMES=0; + SHOW_RAW_STATUS=0; + SHOW_INVALID_RAW=0; + if(argc>1){ + for(i=1;i<argc;i++){ + if(!strcmp("-v", argv[i])) + shell_view=1; + else if(!strcmp("-d", argv[i])) + daemonized=1; + else if(!strcmp("-st", argv[i])) + SHOW_TRAMES=1; + else if(!strcmp("-sr", argv[i])) + SHOW_RAW_STATUS=1; + else if(!strcmp("-si", argv[i])) + SHOW_INVALID_RAW=1; + else if(!strcmp("-h", argv[i])){ + usage(); + exit(1); + }else{ + usage(); + exit(1); + } + } + } + if(daemonized) + daemonize(shell_view); + // On exiting + signal(SIGINT, on_close_daemon); + signal(SIGKILL, on_close_daemon); + // Gestion Multithread + if (!g_thread_supported()) { + g_thread_init(NULL); + }else{ + printf("g_thread NOT supported\n"); + return 1; + } + + TUX_USB_STATUS=0; + TUX_TCP_STATUS=0; + CLOSE_DAEMON=0; + last_remote_key=0xFF; + last_toggle_key=0xFF; + sound_flash_count=0; + + // Start USB task thread + if ((UsbThread = g_thread_create((GThreadFunc)usb_start_task,NULL,TRUE,&error))== NULL ) { + printf("Thread creation failed: %s \n",error->message); + return 2; + } + + // Start TCP task thread + if ((TcpThread = g_thread_create((GThreadFunc)tcp_server_start_task,NULL,TRUE,&error))== NULL ) { + printf("Thread creation failed: %s \n",error->message); + return 2; + } + loop = g_main_loop_new(NULL,FALSE); + g_main_loop_run(loop); + return 0; + } + + |