[xiph-cvs] cvs commit: ices/src config.h im_oss.c metadata.c metadata.h signals.c

Michael Smith msmith at xiph.org
Sun Sep 23 02:49:04 PDT 2001



msmith      01/09/23 02:49:03

  Modified:    src      config.h im_oss.c metadata.c metadata.h signals.c
  Log:
  Add new way of doing metadata updates - read specified file on SIGUSR1, if
  so configured.

Revision  Changes    Path
1.2       +1 -0      ices/src/config.h

Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- config.h	2001/09/10 02:30:50	1.1
+++ config.h	2001/09/23 09:49:02	1.2
@@ -81,6 +81,7 @@
         /* private */
         int log_id;
         int shutdown;
+    char *metadata_filename;
         cond_t queue_cond;
         mutex_t refcount_lock;
         mutex_t flush_lock;

1.2       +6 -1      ices/src/im_oss.c

Index: im_oss.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_oss.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- im_oss.c	2001/09/10 02:30:52	1.1
+++ im_oss.c	2001/09/23 09:49:03	1.2
@@ -178,6 +178,8 @@
                         device = current->value;
                 else if(!strcmp(current->name, "metadata"))
                         use_metadata = atoi(current->value);
+		else if(!strcmp(current->name, "metadatafilename"))
+			ices_config->metadata_filename = current->value;
                 else
                         LOG_WARN1("Unknown parameter %s for stdinpcm module", current->name);
 
@@ -239,7 +241,10 @@
 
         if(use_metadata)
         {
-		thread_create("im_oss-metadata", metadata_thread, mod, 1);
+        if(ices_config->metadata_filename)
+            thread_create("im_oss-metadata", metadata_thread_signal, mod, 1);
+        else
+		    thread_create("im_oss-metadata", metadata_thread_stdin, mod, 1);
                 LOG_INFO0("Started metadata update thread");
         }
 

1.2       +58 -1     ices/src/metadata.c

Index: metadata.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/metadata.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- metadata.c	2001/09/10 02:30:53	1.1
+++ metadata.c	2001/09/23 09:49:03	1.2
@@ -12,6 +12,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
+#include <unistd.h>
 
 #include "config.h"
 #include "inputmodule.h"
@@ -20,7 +22,9 @@
 #define MODULE "metadata/"
 #include "logging.h"
 
-void *metadata_thread(void *arg)
+volatile int metadata_update_signalled = 0;
+
+void *metadata_thread_stdin(void *arg)
 {
         char buf[1024];
         input_module_t *mod = arg;
@@ -57,4 +61,57 @@
 
         }
 }
+
+void *metadata_thread_signal(void *arg)
+{
+	char buf[1024];
+	input_module_t *mod = arg;
+
+	while(1)
+	{
+		char **md = NULL;
+		int comments = 0;
+        FILE *file;
+
+        while(metadata_update_signalled == 0)
+            sleep(60);
+
+        metadata_update_signalled = 0;
+
+        file = fopen(ices_config->metadata_filename, "r");
+        LOG_WARN2("Failed to open file %s for metadata update: %s", 
+                ices_config->metadata_filename, strerror(errno));
+        if(!file) 
+            continue;
+
+		while(fgets(buf, 1024, file))
+		{
+			if(buf[0] == '\n')
+				break;
+			else
+			{
+				if(buf[strlen(buf)-1] == '\n')
+					buf[strlen(buf)-1] = 0;
+				md = realloc(md, (comments+2)*sizeof(char *));
+				md[comments] = malloc(strlen(buf)+1);
+
+				memcpy(md[comments], buf, strlen(buf)+1);
+				comments++;
+			}
+		}
+
+        fclose(file);
+
+		if(md) /* Don't update if there's nothing there */
+		{
+			md[comments]=0;
+
+			/* Now, let's actually use the new data */
+			LOG_INFO0("Updating metadata");
+			mod->handle_event(mod,EVENT_METADATAUPDATE,md);
+		}
+
+	}
+}
+
 

1.2       +2 -1      ices/src/metadata.h

Index: metadata.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/metadata.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- metadata.h	2001/09/10 02:30:54	1.1
+++ metadata.h	2001/09/23 09:49:03	1.2
@@ -12,7 +12,8 @@
 #ifndef __METADATA_H__
 #define __METADATA_H__
 
-void *metadata_thread(void *arg);
+void *metadata_thread_stdin(void *arg);
+void *metadata_thread_signal(void *arg);
 
 #endif /* __METADATA_H__ */
 

1.2       +11 -0     ices/src/signals.c

Index: signals.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/signals.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- signals.c	2001/09/10 02:30:51	1.1
+++ signals.c	2001/09/23 09:49:03	1.2
@@ -24,6 +24,16 @@
 #define MODULE "signals/"
 #include "logging.h"
 
+extern volatile int metadata_update_signalled;
+
+void signal_usr1_handler(int signum)
+{
+	LOG_INFO0("Metadata update requested");
+    metadata_update_signalled = 1;
+
+	signal(SIGUSR1, signal_usr1_handler);
+}
+
 void signal_hup_handler(int signum)
 {
         LOG_INFO0("Flushing logs");
@@ -55,6 +65,7 @@
 {
         signal(SIGHUP, signal_hup_handler);
         signal(SIGINT, signal_int_handler);
+	signal(SIGUSR1, signal_usr1_handler);
         signal(SIGPIPE, SIG_IGN);
 }
 

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list