[Dsctl-devel] SF.net SVN: dsctl: [125] src
Status: Alpha
Brought to you by:
roger-linux
|
From: <rog...@us...> - 2007-07-18 06:29:33
|
Revision: 125
http://dsctl.svn.sourceforge.net/dsctl/?rev=125&view=rev
Author: roger-linux
Date: 2007-07-17 23:29:26 -0700 (Tue, 17 Jul 2007)
Log Message:
-----------
This commits moves ~/.dsctl config file to ~/.dsctl/config and while running, updates ~/.dsctl/metadata with reception status info. Use the -i [pid] and dsctl will give Ices a SIGUSR1 signal for rereading the metadata file. (See -h for instructions.)
Lots of bugs to fix, such as dsctl writing to the metadata file every .5 seconds and should only write after determining there's different data within the ~/.dsctl/metadata file.
Signed-off-by: Roger <ro...@es...>
Acked-by: Roger <ro...@es...>
Modified Paths:
--------------
src/commands.c
src/human_commands.c
src/main.c
src/serial.c
src/usage.c
src/utils.c
src/utils.h
Modified: src/commands.c
===================================================================
--- src/commands.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/commands.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -194,7 +194,10 @@
if (daemon_mode == 0 || osd == 0)
printf("\nReception Status:\n");
-
+
+ /* Send this data to ~/.dsctl/metadata */
+ write_metadata(field[6], field[7]);
+
/* We have 10 parsed fields to print for this command */
for (i = 0; i <= 9; i++)
{
Modified: src/human_commands.c
===================================================================
--- src/human_commands.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/human_commands.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -49,9 +49,9 @@
return;
} */
- if (args[0] == NULL)
+ //if (args[0] == NULL)
dump(fd, stdout);
- else
+ /*else
{
if ((outfile = fopen(args[0], "w")) != NULL)
dump(fd, outfile);
@@ -61,7 +61,7 @@
perror(errorstr);
return;
}
- }
+ }*/
}
/***********************************************************************
@@ -208,7 +208,7 @@
while (daemon_mode != 0) /* simple endless loop */
{
int i = 0;
-
+
if (debug > 0)
printf("osd value == %i\n", osd);
Modified: src/main.c
===================================================================
--- src/main.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/main.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -47,6 +47,7 @@
int debug = DEBUG; /* debug flag for extra output */
int daemon_mode = 0; /* this should get us a daemon mode */
int osd = OSD; /* indicate the user wants ncurses osd */
+int ices_pid = 0;
/***********************************************************************
* the main function. ain't it grand?
@@ -166,7 +167,10 @@
}
}
}
- close(configfile);
+ /* Remove "/config" from HOME enviroment variable */
+ reset_env_var("HOME", "/config");
+
+ fclose(configfile);
closedir(configfolder);
/* process global options */
@@ -197,6 +201,15 @@
cmd_arg_loc += 1;
}
+ else if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--icespid") == 0) /* daemon mode */
+ {
+ ices_pid = atoi(argv[++i]);
+
+ cmd_loc += 2;
+ cmd_arg_loc += 2;
+ }
+
+
else if (strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--ncurses") == 0) /* osd */
{
daemon_mode = 1;
Modified: src/serial.c
===================================================================
--- src/serial.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/serial.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -325,9 +325,9 @@
if (strncmp(string, "CLR", 3) == 0)
timeout.tv_sec = 20;
- if (debug == 1)
+ /*if (debug == 1)
printf("DEBUG retval: %i timeout.tv_sec: %d \n", retval,
- timeout.tv_sec);
+ timeout.tv_sec);*/
retval = (select(maxfd, &set, NULL, NULL, &timeout));
Modified: src/usage.c
===================================================================
--- src/usage.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/usage.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -80,6 +80,12 @@
fprintf(stderr,
" (bcd models are work in progress and bcd396t needs a tester.)\n\n");
+ fprintf(stderr, " -i --icespid Current running Ices's PID. Dsctl will send SIGUSR1 to Ices for\n");
+ fprintf(stderr,
+ " rereading ~/.dsctl/metadata. (This file needs to be stated\n");
+ fprintf(stderr,
+ " within your /etc/ices2/ices-alsa.xml.)\n\n");
+
fprintf(stderr, " -n --ncurses Ncurses display. Implies daemon mode (Experimental)\n\n");
fprintf(stderr,
Modified: src/utils.c
===================================================================
--- src/utils.c 2007-07-18 00:19:19 UTC (rev 124)
+++ src/utils.c 2007-07-18 06:29:26 UTC (rev 125)
@@ -25,6 +25,10 @@
#include <stdlib.h>
#include <string.h>
+/* For kill */
+#include <sys/types.h>
+#include <signal.h>
+
#include "config.h"
#include "utils.h"
@@ -295,7 +299,9 @@
/***********************************************************************
* parse comma seperated values into an array for easy printing.
***********************************************************************/
-/* TODO: Some fields assigned by Uniden are "" (null) and we need to preserve these or else they offset enumating fields */
+/* Some fields assigned by Uniden are "" (null) and we need to preserve
+ * these or else they offset enumating fields. As such, do_parse is
+ * deprecated. "parse_fields" preserves these null fields. */
int do_parse(char *unparsed, char **parsed)
{
int i = 0, strlength = 0;
@@ -478,3 +484,54 @@
return (i);
}
+
+/***********************************************************************
+ * Write Metadata File
+ ***********************************************************************/
+void write_metadata(char *artist_field, char *title_field)
+{
+ char *metadataloc;
+ FILE *metadatafile;
+
+ if (debug > 0)
+ printf("DEBUG write_metadata(): \"%s\" \"%s\"\n", artist_field, title_field);
+
+ /* Check for $HOME/.dsctl/metadata */
+ metadataloc = strcat(getenv("HOME"), "/metadata");
+
+ if ((metadatafile = fopen(metadataloc, "w")) != NULL)
+ {
+ fprintf(metadatafile,
+ "ARTIST=%s\n", artist_field);
+ fprintf(metadatafile,
+ "TITLE=%s\n", title_field);
+ }
+ else /* unable to write a metadata file. if they don't have write permission
+ on their home directory or something else weird */
+ {
+ metadataloc = strcat("write to ", metadataloc);
+ perror(metadataloc);
+ }
+
+ reset_env_var("HOME", "/metadata");
+ fclose(metadatafile);
+
+ /* Find ices pid and send Ices SIGUSR1 so Ices rereads metadata*/
+ if (ices_pid != 0)
+ kill(ices_pid, SIGUSR1);
+
+ return;
+}
+/***********************************************************************
+ * Reset Enviroment Variables
+ ***********************************************************************/
+int reset_env_var(char *env_var, char *remove)
+{
+
+ char *ptr;
+
+ ptr = strstr(getenv(env_var), remove);
+ strcpy(ptr, "\0");
+
+ return (0);
+}
Modified: src/utils.h
===================================================================
--- src/utils.h 2007-07-18 00:19:19 UTC (rev 124)
+++ src/utils.h 2007-07-18 06:29:26 UTC (rev 125)
@@ -26,6 +26,7 @@
extern int scannermodel;
extern int debug;
+extern int ices_pid;
/*
* Uniden's customized Ascii Characters
@@ -109,5 +110,7 @@
//int do_parse(char *unparsed, char **parsed);
int parse_fields(char *unparsed, char **parsed);
int replace_chars(char *bcd_chars, char *common_chars);
+void write_metadata(char *artist_field, char *title_field);
+int reset_env_var(char *env_var, char *remove);
#endif /* _UTILS_H_ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|