[xiph-cvs] cvs commit: icecast/src stats.c stats.h
Jack Moffitt
jack at xiph.org
Tue Feb 5 22:11:04 PST 2002
jack 02/02/05 22:11:03
Modified: src stats.c stats.h
Log:
A very slightly modified version of oddsocks function to support gui
stats updates. Basically stats_connection() was copied to
stats_callback() (i should probably factor out some of the code here!)
with the change that instead of sending stats to a socket, it sends the
event to a callback function.
Revision Changes Path
1.7 +75 -0 icecast/src/stats.c
Index: stats.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- stats.c 2002/02/04 07:08:52 1.6
+++ stats.c 2002/02/06 06:11:03 1.7
@@ -598,6 +598,81 @@
return NULL;
}
+/* this function is primarily to support gui code needing to get stats updates
+** create a thread with this as the start proc with an arg of the callback function
+** on each stats event the callback will be called with the event
+** and the callback is responsible for copying the data if it needs it after returning
+*/
+void *stats_callback(void *arg)
+{
+ void (*callback)(stats_event_t *event);
+
+ stats_event_t *local_event_queue = NULL;
+ mutex_t local_event_mutex;
+
+ avl_node *node;
+ avl_node *node2;
+ stats_event_t *event;
+ stats_source_t *source;
+
+ callback = arg;
+
+ thread_mutex_create(&local_event_mutex);
+
+ /* we must get the current stats and register for events atomically.
+ ** we don't want to miss any and have inaccurate stats.
+ */
+
+ /* first the global stats */
+ thread_mutex_lock(&_stats_mutex);
+ node = avl_get_first(_stats.global_tree);
+ while (node) {
+ event = _make_event_from_node((stats_node_t *)node->key, NULL);
+ _add_event_to_queue(event, &local_event_queue);
+ node = avl_get_next(node);
+ }
+
+ /* now the stats for each source */
+ node = avl_get_first(_stats.source_tree);
+ while (node) {
+ source = (stats_source_t *)node->key;
+ node2 = avl_get_first(source->stats_tree);
+ while (node2) {
+ event = _make_event_from_node((stats_node_t *)node2->key, source->source);
+ _add_event_to_queue(event, &local_event_queue);
+ node2 = avl_get_next(node2);
+ }
+
+ node = avl_get_next(node);
+ }
+
+ /* now we register to receive future event notices */
+ _register_listener(&local_event_queue, &local_event_mutex);
+
+ thread_mutex_unlock(&_stats_mutex);
+
+ while (global.running == ICE_RUNNING) {
+ thread_mutex_lock(&local_event_mutex);
+ event = _get_event_from_queue(&local_event_queue);
+ if (event != NULL) {
+ callback(event);
+ _free_event(event);
+ } else {
+ thread_mutex_unlock(&local_event_mutex);
+ thread_cond_wait(&_event_signal_cond);
+ continue;
+ }
+
+ thread_mutex_unlock(&local_event_mutex);
+ }
+
+ thread_mutex_destroy(&local_event_mutex);
+
+ thread_exit(0);
+
+ return NULL;
+}
+
typedef struct _source_xml_tag {
char *mount;
xmlNodePtr node;
<p><p>1.2 +1 -0 icecast/src/stats.h
Index: stats.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stats.h 2001/09/10 02:21:50 1.1
+++ stats.h 2002/02/06 06:11:03 1.2
@@ -64,6 +64,7 @@
void stats_event_dec(char *source, char *name);
void *stats_connection(void *arg);
+void *stats_callback(void *arg);
void stats_sendxml(client_t *client);
<p><p><p>--- >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