[Freeswitch-svn] [commit] r4347 - in freeswitch/trunk/src: . include

Freeswitch SVN anthm at freeswitch.org
Thu Feb 22 12:38:35 EST 2007


Author: anthm
Date: Thu Feb 22 12:38:34 2007
New Revision: 4347

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_event.c

Log:
add heartbeat event and core uuid

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Thu Feb 22 12:38:34 2007
@@ -477,6 +477,12 @@
 */
 SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *session);
 
+/*! 
+  \brief Retrieve the unique identifier from the core
+  \return a string representing the uuid
+*/
+SWITCH_DECLARE(char *) switch_core_get_uuid(void);
+
 #ifdef SWITCH_DEBUG_RWLOCKS
 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(char *uuid_str,
                                                                            const char *file,

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Thu Feb 22 12:38:34 2007
@@ -747,6 +747,7 @@
 	SWITCH_EVENT_BACKGROUND_JOB		- Background Job
 	SWITCH_EVENT_DETECTED_SPEECH	- Detected Speech
 	SWITCH_EVENT_PRIVATE_COMMAND	- A private command event 
+	SWITCH_EVENT_HEARTBEAT			- Machine is alive
     SWITCH_EVENT_ALL				- All events at once
 </pre>
 
@@ -787,6 +788,7 @@
 	SWITCH_EVENT_BACKGROUND_JOB,
 	SWITCH_EVENT_DETECTED_SPEECH,
 	SWITCH_EVENT_PRIVATE_COMMAND,
+	SWITCH_EVENT_HEARTBEAT,
 	SWITCH_EVENT_ALL
 } switch_event_types_t;
 

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Thu Feb 22 12:38:34 2007
@@ -145,6 +145,7 @@
 	uint32_t no_new_sessions;
 	uint32_t shutting_down;
 	uint8_t running;
+	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
 };
 
 /* Prototypes */
@@ -748,6 +749,11 @@
 	return status;
 }
 
+SWITCH_DECLARE(char *) switch_core_get_uuid(void)
+{
+	return runtime.uuid_str;
+}
+
 SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *session)
 {
 	return session->uuid_str;
@@ -3808,7 +3814,7 @@
 	void *pop;
 	uint32_t itterations = 0;
 	uint8_t trans = 0, nothing_in_queue = 0;
-	uint32_t freq = 1000, target = 1000;
+	uint32_t target = 1000;
 	switch_size_t len = 0, sql_len = SQLLEN;
 	const char *begin_sql = "BEGIN DEFERRED TRANSACTION CORE1;\n";
 	char *end_sql = "END TRANSACTION CORE1";
@@ -3817,13 +3823,15 @@
 	char *sqlbuf = (char *) malloc(sql_len);
 	char *sql;
 	switch_size_t newlen;
-
+	uint32_t loops = 0;
 	
 	if (!runtime.event_db) {
 		runtime.event_db = switch_core_db_handle();
 	}
 	switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool);
 
+
+
 	for(;;) {
 		if (switch_queue_trypop(runtime.sql_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 			sql = (char *) pop;
@@ -3873,10 +3881,42 @@
 			len = 0;
 			*sqlbuf = '\0';
 		}
+
+		if (loops++ >= 5000) {
+			switch_event_t *event;
+			switch_core_time_duration_t duration;
+
+			switch_core_measure_time(switch_core_uptime(), &duration);
+
+			if (switch_event_create(&event, SWITCH_EVENT_HEARTBEAT) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Up-Time", 
+										"%u year%s, "
+										"%u day%s, "
+										"%u hour%s, "
+										"%u minute%s, "
+										"%u second%s, "
+										"%u millisecond%s, "
+										"%u microsecond%s\n",
+										duration.yr, duration.yr == 1 ? "" : "s",
+										duration.day, duration.day == 1 ? "" : "s",
+										duration.hr, duration.hr == 1 ? "" : "s",
+										duration.min, duration.min == 1 ? "" : "s",
+										duration.sec, duration.sec == 1 ? "" : "s",
+										duration.ms, duration.ms == 1 ? "" : "s",
+										duration.mms, duration.mms == 1 ? "" : "s"
+										);
+
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
+				switch_event_fire(&event);
+			}
+			
+			loops = 0;
+		}
 		
 		if (nothing_in_queue) {
-			switch_yield(freq);
-		} 
+			switch_yield(1000);
+		}
 	}
 
 
@@ -4130,6 +4170,7 @@
 	switch_xml_t xml = NULL, cfg = NULL;
 	memset(&runtime, 0, sizeof(runtime));
 	runtime.session_limit = 1000;
+	switch_uuid_t uuid;
 
 	switch_core_set_globals();
 
@@ -4276,6 +4317,11 @@
 	switch_core_hash_init(&runtime.stack_table, runtime.memory_pool);
 #endif
 	runtime.initiated = switch_time_now();
+
+
+	switch_uuid_get(&uuid);
+	switch_uuid_format(runtime.uuid_str, &uuid);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Thu Feb 22 12:38:34 2007
@@ -131,6 +131,7 @@
 	"BACKGROUND_JOB",
 	"DETECTED_SPEECH",
 	"PRIVATE_COMMAND",
+	"HEARTBEAT",
 	"ALL"
 };
 
@@ -811,21 +812,21 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Line-Number", "%d", line);
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Function", "%s", func);
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-File", "%s", switch_cut_path(file));
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Name", "%s", switch_event_name((*event)->event_id));
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Core-UUID", "%s", switch_core_get_uuid());
 	switch_time_exp_lt(&tm, switch_time_now());
 	switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-Local", "%s", date);
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", "%s", date);
 	switch_rfc822_date(date, switch_time_now());
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-GMT", "%s", date);
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", "%s", date);
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", "%s", switch_cut_path(file));
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", "%s", func);
+	switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);
+
 	if ((*event)->subclass) {
-		switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass", "%s", (*event)->subclass->name);
-		switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass-Owner", "%s", (*event)->subclass->owner);
+		switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", "%s", (*event)->subclass->name);
+		switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass-Owner", "%s", (*event)->subclass->owner);
 	}
-	switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Name", "%s", switch_event_name((*event)->event_id));
-
 
 	if (user_data) {
 		(*event)->event_user_data = user_data;



More information about the Freeswitch-svn mailing list