From ae5e2d8004affd8a0519de97a3c1ad700fa2b720 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 21:55:16 +0000 Subject: Add syslog.h; rename lib_rawprintf() to syslog() git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5578 42af7a65-404d-4744-a932-0658087f49c3 --- apps/system/usbmonitor/Makefile | 4 +-- apps/system/usbmonitor/usbmonitor.c | 68 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 36 deletions(-) (limited to 'apps/system/usbmonitor') diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile index 04fcaf0ac..b4c323eb7 100644 --- a/apps/system/usbmonitor/Makefile +++ b/apps/system/usbmonitor/Makefile @@ -44,7 +44,6 @@ endif # Hello Application # TODO: appname can be automatically extracted from the directory name -APPNAME = usbmon PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 768 @@ -90,7 +89,8 @@ $(COBJS): %$(OBJEXT): %.c ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start) + $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonintor_stop) context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat else diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c index b101b128c..b615b99f9 100644 --- a/apps/system/usbmonitor/usbmonitor.c +++ b/apps/system/usbmonitor/usbmonitor.c @@ -40,20 +40,29 @@ #include #include -#include -#include +#include +#include +#include + +#include event, trace->value); + return 0; +} + static int usbmonitor_daemon(int argc, char **argv) { -#ifdef CONFIG_NSH_BUILTIN_APPS - print("USB Monitor running: %d\n", g_usbmonitor.pid); -#endif + syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); -#ifdef CONFIG_NSH_BUILTIN_APPS - /* If we are running as an NSH command, then loop until we detect that - * there is a request to stop. - */ + /* Loop until we detect that there is a request to stop. */ while (!g_usbmonitor.stop) -#else - /* If we are running as a standalone program, then loop forever */ - - for (;;) -#endif { -#warning "Missing logic" + (void)usbmonitor_enumerate(nsh_tracecallback, NULL); } /* Stopped */ -#ifdef CONFIG_NSH_BUILTIN_APPS g_usbmonitor.stop = false; g_usbmonitor.started = false; - print("USB Monitor stopped: %d\n", g_usbmonitor.pid); -#endif + syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); + return 0; } @@ -101,9 +105,8 @@ static int usbmonitor_daemon(int argc, char **argv) * Public Functions ****************************************************************************/ -int usbmonitor_main(int argc, char **argv) +int usbmonitor_start(int argc, char **argv) { -#ifdef CONFIG_NSH_BUILTIN_APPS /* Has the monitor already started? */ sched_lock(); @@ -122,13 +125,14 @@ int usbmonitor_main(int argc, char **argv) if (ret < 0) { int errcode = errno; - fprintf(stderr, "ERROR: Failed to start the USB monitor: %d\n", - errcode); + syslog(USBMON_PREFIX + "ERROR: Failed to start the USB monitor: %d\n", + errcode); } else { g_usbmonitor.pid = ret; - print("USB Monitor started: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Started: %d\n", g_usbmonitor.pid); } sched_unlock(); @@ -136,27 +140,23 @@ int usbmonitor_main(int argc, char **argv) } sched_unlock(); - print("USB Monitor running: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); return 0; -#else - return usbmonitor_daemon(argc, argv); -#endif } -#ifdef CONFIG_NSH_BUILTIN_APPS int usbmonitor_stop(int argc, char **argv) { /* Has the monitor already started? */ if (g_usbmonitor.started) { - print("USB Monitor stopping: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid); g_usbmonitor.stop = true; return 0; } - print("USB Monitor stopped: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); return 0; } -#endif +#endif /* CONFIG_SYSTEM_USBMONITOR */ -- cgit v1.2.3