changeset 628:e1c6f45f5fcd

Improvements to usability, still work ongoing
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 14 Dec 2010 11:53:48 +0900
parents 330be61dbf43
children 7ae66129fd73
files freeDiameter/main.c include/freeDiameter/freeDiameter.h
diffstat 2 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/freeDiameter/main.c	Tue Dec 14 11:53:24 2010 +0900
+++ b/freeDiameter/main.c	Tue Dec 14 11:53:48 2010 +0900
@@ -45,6 +45,7 @@
 static int main_cmdline(int argc, char *argv[]);
 static void main_version(void);
 static void main_help( void );
+static int signal_framework_ready(void);
 
 /* The static configuration structure */
 static struct fd_config conf;
@@ -117,6 +118,7 @@
 	
 	/* Now, just wait for events */
 	TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
+	CHECK_FCT( signal_framework_ready() );
 	while (1) {
 		int code; size_t sz; void * data;
 		CHECK_FCT_DO(  fd_event_get(fd_g_config->cnf_main_ev, &code, &sz, &data),  break  );
@@ -349,3 +351,30 @@
 	
 	return;
 }
+
+
+/* Signal extensions when the framework is completly initialized */
+static int             is_ready = 0;
+static pthread_mutex_t is_ready_mtx = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  is_ready_cnd = PTHREAD_COND_INITIALIZER;
+static int signal_framework_ready(void)
+{
+	TRACE_ENTRY("");
+	CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
+	is_ready = 1;
+	CHECK_POSIX( pthread_cond_broadcast( &is_ready_cnd ) );
+	CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
+	return 0;
+}
+int fd_wait_initialization_complete(void)
+{
+	TRACE_ENTRY("");
+	CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
+	pthread_cleanup_push( fd_cleanup_mutex, &is_ready_mtx );
+	while (!is_ready) {
+		CHECK_POSIX( pthread_cond_wait( &is_ready_cnd, &is_ready_mtx ) );
+	}
+	pthread_cleanup_pop( 0 );
+	CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
+	return 0;
+}
--- a/include/freeDiameter/freeDiameter.h	Tue Dec 14 11:53:24 2010 +0900
+++ b/include/freeDiameter/freeDiameter.h	Tue Dec 14 11:53:48 2010 +0900
@@ -675,6 +675,17 @@
 const char * fd_ev_str(int event);
 
 
+/* The following function does not really use events, but it may be used 
+by extensions that need to start an action when the framework is fully initialized. 
+This function will block until all initializations are performed in the daemon.
+It is meant to be used as follow by extensions:
+ - in initialization callback, create a new thread.
+ - this new thread calls this function.
+ - when the function returns, the thread can start working and using all framework features.
+*/
+int fd_wait_initialization_complete(void);
+
+
 /***************************************/
 /*   Endpoints lists helpers           */
 /***************************************/
"Welcome to our mercurial repository"