[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3612 - in GNUnet/src: applications/fs/uritrack include
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3612 - in GNUnet/src: applications/fs/uritrack include |
Date: |
Thu, 2 Nov 2006 10:49:53 -0800 (PST) |
Author: grothoff
Date: 2006-11-02 10:49:49 -0800 (Thu, 02 Nov 2006)
New Revision: 3612
Added:
GNUnet/src/applications/fs/uritrack/callbacks.c
GNUnet/src/applications/fs/uritrack/callbacks.h
Modified:
GNUnet/src/applications/fs/uritrack/Makefile.am
GNUnet/src/applications/fs/uritrack/file_info.c
GNUnet/src/include/gnunet_uritrack_lib.h
Log:
uritr
Modified: GNUnet/src/applications/fs/uritrack/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/uritrack/Makefile.am 2006-11-02 14:31:56 UTC
(rev 3611)
+++ GNUnet/src/applications/fs/uritrack/Makefile.am 2006-11-02 18:49:49 UTC
(rev 3612)
@@ -4,7 +4,8 @@
libgnuneturitrack.la
libgnuneturitrack_la_SOURCES = \
- file_info.c
+ file_info.c \
+ callbacks.c callbacks.h
libgnuneturitrack_la_LIBADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/util/libgnunetutil.la
Added: GNUnet/src/applications/fs/uritrack/callbacks.c
===================================================================
--- GNUnet/src/applications/fs/uritrack/callbacks.c 2006-11-02 14:31:56 UTC
(rev 3611)
+++ GNUnet/src/applications/fs/uritrack/callbacks.c 2006-11-02 18:49:49 UTC
(rev 3612)
@@ -0,0 +1,160 @@
+/*
+ This file is part of GNUnet.
+ (C) 2006 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/uritrack/callbacks.c
+ * @brief callbacks for URI tracking
+ * @author Christian Grothoff
+ */
+
+#include "gnunet_directories.h"
+#include "gnunet_util.h"
+#include "gnunet_uritrack_lib.h"
+#include "platform.h"
+
+/**
+ * @brief Struct for URITRACK callback.
+ */
+typedef struct {
+ struct GE_Context * ectx;
+
+ struct GC_Configuration * cfg;
+
+ ECRS_SearchProgressCallback iterator;
+
+ void * closure;
+
+ struct PTHREAD * init;
+
+ int abort_init;
+} Callback;
+
+static struct MUTEX * lock;
+
+static Callback ** callbacks;
+
+static unsigned int callbacks_size;
+
+static int init_iterator(const ECRS_FileInfo * fi,
+ const HashCode512 * key,
+ int isRoot,
+ void * closure) {
+ Callback * c = closure;
+
+ c->iterator(fi,
+ key,
+ isRoot,
+ c->closure);
+ if (c->abort_init)
+ return SYSERR;
+ return OK;
+}
+
+static void * init_thread(void * arg) {
+ Callback * c = arg;
+ URITRACK_listURIs(c->ectx,
+ c->cfg,
+ YES,
+ &init_iterator,
+ arg);
+ return NULL;
+}
+
+/**
+ * Register a handler that is called whenever
+ * a URI is tracked. If URIs are already in
+ * the database, the callback will be called
+ * for all existing URIs as well.
+ */
+int URITRACK_registerTrackCallback(struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ ECRS_SearchProgressCallback iterator,
+ void * closure) {
+ Callback * c;
+
+ c = MALLOC(sizeof(Callback));
+ c->ectx = ectx;
+ c->cfg = cfg;
+ c->iterator = iterator;
+ c->closure = closure;
+ c->abort_init = NO;
+ c->init = PTHREAD_CREATE(&init_thread,
+ c,
+ 16 * 1024);
+ MUTEX_LOCK(lock);
+ GROW(callbacks,
+ callbacks_size,
+ callbacks_size + 1);
+ callbacks[callbacks_size-1] = c;
+ MUTEX_UNLOCK(lock);
+ return OK;
+}
+
+/**
+ * Unregister a URI callback.
+ */
+int URITRACK_unregisterTrackCallback(ECRS_SearchProgressCallback iterator,
+ void * closure) {
+ int i;
+ void * unused;
+ Callback * c;
+
+ MUTEX_LOCK(lock);
+ for (i=0;i<callbacks_size;i++) {
+ c = callbacks[i];
+ if ( (c->iterator == iterator) &&
+ (c->closure == closure) ) {
+ c->abort_init = YES;
+ PTHREAD_JOIN(c->init, &unused);
+ callbacks[i] = callbacks[callbacks_size-1];
+ FREE(c);
+ MUTEX_UNLOCK(lock);
+ return OK;
+ }
+ }
+ MUTEX_UNLOCK(lock);
+ return SYSERR;
+}
+
+/**
+ * Internal notification about new tracked URI.
+ */
+void URITRACK_internal_notify(const ECRS_FileInfo * fi) {
+ int i;
+
+ MUTEX_LOCK(lock);
+ for (i=0;i<callbacks_size;i++)
+ callbacks[i]->iterator(fi,
+ NULL,
+ NO,
+ callbacks[i]->closure);
+ MUTEX_UNLOCK(lock);
+}
+
+void __attribute__ ((constructor)) gnunet_uritrack_ltdl_init() {
+ lock = MUTEX_CREATE(NO);
+}
+
+void __attribute__ ((destructor)) gnunet_uritrack_ltdl_fini() {
+ MUTEX_DESTROY(lock);
+ lock = NULL;
+}
+
+/* end of callbacks.c */
Added: GNUnet/src/applications/fs/uritrack/callbacks.h
===================================================================
--- GNUnet/src/applications/fs/uritrack/callbacks.h 2006-11-02 14:31:56 UTC
(rev 3611)
+++ GNUnet/src/applications/fs/uritrack/callbacks.h 2006-11-02 18:49:49 UTC
(rev 3612)
@@ -0,0 +1,35 @@
+/*
+ This file is part of GNUnet.
+ (C) 2006 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/uritrack/callbacks.h
+ * @brief callbacks for URI tracking
+ * @author Christian Grothoff
+ */
+
+#ifndef URITRACK_CALLBACKS_H
+#define URITRACK_CALLBACKS_H
+
+/**
+ * Internal notification about new tracked URI.
+ */
+void URITRACK_internal_notify(const ECRS_FileInfo * fi);
+
+#endif
Modified: GNUnet/src/applications/fs/uritrack/file_info.c
===================================================================
--- GNUnet/src/applications/fs/uritrack/file_info.c 2006-11-02 14:31:56 UTC
(rev 3611)
+++ GNUnet/src/applications/fs/uritrack/file_info.c 2006-11-02 18:49:49 UTC
(rev 3612)
@@ -32,6 +32,7 @@
#include "gnunet_util.h"
#include "gnunet_uritrack_lib.h"
#include "platform.h"
+#include "callbacks.h"
#define DEBUG_FILE_INFO NO
@@ -178,6 +179,7 @@
IPC_SEMAPHORE_DESTROY(sem);
FREE(data);
FREE(suri);
+ URITRACK_internal_notify(fi);
}
/**
Modified: GNUnet/src/include/gnunet_uritrack_lib.h
===================================================================
--- GNUnet/src/include/gnunet_uritrack_lib.h 2006-11-02 14:31:56 UTC (rev
3611)
+++ GNUnet/src/include/gnunet_uritrack_lib.h 2006-11-02 18:49:49 UTC (rev
3612)
@@ -82,6 +82,23 @@
ECRS_SearchProgressCallback iterator,
void * closure); /* file_info.c */
+/**
+ * Register a handler that is called whenever
+ * a URI is tracked. If URIs are already in
+ * the database, the callback will be called
+ * for all existing URIs as well.
+ */
+int URITRACK_registerTrackCallback(struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ ECRS_SearchProgressCallback iterator,
+ void * closure); /* callbacks.c */
+
+/**
+ * Unregister a URI callback.
+ */
+int URITRACK_unregisterTrackCallback(ECRS_SearchProgressCallback iterator,
+ void * closure); /* callbacks.c */
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3612 - in GNUnet/src: applications/fs/uritrack include,
grothoff <=