[Freeswitch-branches] [commit] r3256 - freeswitch/branches/knhor/wip/mod_conference

Freeswitch SVN knhor at freeswitch.org
Thu Nov 2 00:25:47 EST 2006


Author: knhor
Date: Thu Nov  2 00:25:46 2006
New Revision: 3256

Modified:
   freeswitch/branches/knhor/wip/mod_conference/mod_conference.c

Log:
refine the conf_api_member_cmd_t api functions so that they do not need the conference pointer and member id arguments. use some of the api functions in caller dtmf control functions so that event information is generated

Modified: freeswitch/branches/knhor/wip/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	Thu Nov  2 00:25:46 2006
@@ -248,13 +248,25 @@
 static void launch_conference_record_thread(conference_obj_t *conference, char *path);
 
 typedef int (*conf_api_args_cmd_t)(conference_obj_t*, switch_stream_handle_t*, int, char**);
-typedef int (*conf_api_member_cmd_t)(conference_obj_t*, conference_member_t*, int, switch_stream_handle_t*, void*);
+typedef int (*conf_api_member_cmd_t)(conference_member_t*, switch_stream_handle_t*, void*);
 typedef int (*conf_api_text_cmd_t)(conference_obj_t*, switch_stream_handle_t*, char*);
 
 static void conference_member_itterator(conference_obj_t *conference,
 										switch_stream_handle_t *stream,
 										conf_api_member_cmd_t pfncallback,
 										void *data);
+static int conference_function_api_mute(conference_member_t *member,
+										switch_stream_handle_t *stream,
+										void *data);
+static int conference_function_api_unmute(conference_member_t *member,
+										switch_stream_handle_t *stream,
+										void *data);
+static int conference_function_api_deaf(conference_member_t *member,
+										switch_stream_handle_t *stream,
+										void *data);
+static int conference_function_api_undeaf(conference_member_t *member,
+										switch_stream_handle_t *stream,
+										void *data);
 
 /* Return a Distinct ID # */
 static uint32_t next_member_id(void)
@@ -789,7 +801,9 @@
 	char msg[512];
 
 	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
-		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR);
+//		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR);
+		conference_function_api_mute(member, NULL, NULL);
+		conference_function_api_deaf(member, NULL, NULL);
 		if (member->conference->muted_sound) {
 			conference_member_play_file(member, member->conference->muted_sound, 0);
 		} else {
@@ -797,7 +811,8 @@
 			conference_member_say(member->conference, member, msg, 0);
 		}
 	} else {
-		switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
+//		switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
+		conference_function_api_unmute(member, NULL, NULL);
 		if (member->conference->unmuted_sound) {
 			conference_member_play_file(member, member->conference->unmuted_sound, 0);
 		} else {
@@ -812,7 +827,9 @@
 	char msg[512];
 
 	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
-		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
+//		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
+		conference_function_api_mute(member, NULL, NULL);
+		conference_function_api_deaf(member, NULL, NULL);
 		if (member->conference->muted_sound) {
 			conference_member_play_file(member, member->conference->muted_sound, 0);
 		} else {
@@ -821,6 +838,8 @@
 		}
 	} else {
 		switch_set_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
+		conference_function_api_unmute(member, NULL, NULL);
+		conference_function_api_undeaf(member, NULL, NULL);
 		if (member->conference->unmuted_sound) {
 			conference_member_play_file(member, member->conference->unmuted_sound, 0);
 		} else {
@@ -1592,7 +1611,7 @@
 		switch_mutex_lock(conference->member_mutex);
 
 		for (member = conference->members; member; member = member->next) {
-			pfncallback(conference,member,member->id,stream,data);
+			pfncallback(member,stream,data);
 		}
 		switch_mutex_unlock(conference->member_mutex);
 	}
@@ -1670,44 +1689,47 @@
 	switch_mutex_unlock(conference->member_mutex);
 }
 
-static int conference_function_api_mute(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_mute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
 		if (member->conference->muted_sound) {
 			conference_member_play_file(member, member->conference->muted_sound, 0);
 		}
-		stream->write_function(stream, "OK mute %u\n", id);
+		if(stream != NULL) {
+			stream->write_function(stream, "OK mute %u\n", member->id);
+		}
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 			switch_channel_t *channel = switch_core_session_get_channel(member->session);
 			switch_channel_event_set_data(channel, event);
 
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "mute-member");
 			switch_event_fire(&event);
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_unmute(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_unmute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
-		stream->write_function(stream, "OK unmute %u\n", id);
+		if(stream != NULL) {
+			stream->write_function(stream, "OK unmute %u\n", member->id);
+		}
 		if (member->conference->unmuted_sound) {
 			conference_member_play_file(member, member->conference->unmuted_sound, 0);
 		}
@@ -1715,76 +1737,77 @@
 			switch_channel_t *channel = switch_core_session_get_channel(member->session);
 			switch_channel_event_set_data(channel, event);
 
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unmute-member");
 			switch_event_fire(&event);
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_deaf(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_deaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		switch_clear_flag_locked(member, MFLAG_CAN_HEAR);
-		stream->write_function(stream, "OK deaf %u\n", id);
+		if(stream != NULL) {
+			stream->write_function(stream, "OK deaf %u\n", member->id);
+		}
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 			switch_channel_t *channel = switch_core_session_get_channel(member->session);
 			switch_channel_event_set_data(channel, event);
 
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "deaf-member");
 			switch_event_fire(&event);
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_undeaf(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_undeaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		switch_set_flag_locked(member, MFLAG_CAN_HEAR);
-		stream->write_function(stream, "OK undeaf %u\n", id);
+		if(stream != NULL) {
+			stream->write_function(stream, "OK undeaf %u\n", member->id);
+		}
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 			switch_channel_t *channel = switch_core_session_get_channel(member->session);
 			switch_channel_event_set_data(channel, event);
 
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "undeaf-member");
 			switch_event_fire(&event);
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_kick(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_kick(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		switch_mutex_lock(member->flag_mutex);
@@ -1792,30 +1815,31 @@
 		switch_set_flag(member, MFLAG_KICKED);
 		switch_mutex_unlock(member->flag_mutex);
 
-		stream->write_function(stream, "OK kicked %u\n", id);
+		if(stream != NULL) {
+			stream->write_function(stream, "OK kicked %u\n", member->id);
+		}
 
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 			switch_channel_t *channel = switch_core_session_get_channel(member->session);
 			switch_channel_event_set_data(channel, event);
 
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "kick-member");
 			switch_event_fire(&event);
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_energy(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_energy(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		if (data) {
@@ -1824,15 +1848,17 @@
 			switch_mutex_unlock(member->flag_mutex);
 		}
 
-		stream->write_function(stream, "Energy %u=%d\n", id, member->energy_level);
+		if(stream != NULL) {
+			stream->write_function(stream, "Energy %u=%d\n", member->id, member->energy_level);
+		}
 
 		if (data) {
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 				switch_channel_t *channel = switch_core_session_get_channel(member->session);
 				switch_channel_event_set_data(channel, event);
 
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "energy-level-member");
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Energy-Level", "%d", member->energy_level);
 
@@ -1840,18 +1866,17 @@
 			}
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_volume_in(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_volume_in(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		if (data) {
@@ -1861,14 +1886,16 @@
 			switch_mutex_unlock(member->flag_mutex);
 		}
 
-		stream->write_function(stream, "Volume IN %u=%d\n", id, member->volume_in_level);
+		if(stream != NULL) {
+			stream->write_function(stream, "Volume IN %u=%d\n", member->id, member->volume_in_level);
+		}
 		if (data) {
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 				switch_channel_t *channel = switch_core_session_get_channel(member->session);
 				switch_channel_event_set_data(channel, event);
 
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-in-member");
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_in_level);
 
@@ -1876,18 +1903,17 @@
 			}
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
 	return err;
 }
 
-static int conference_function_api_volume_out(conference_obj_t *conference, conference_member_t *member, int id, switch_stream_handle_t *stream, void *data)
+static int conference_function_api_volume_out(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	int err = 0;
 
-	if (member != NULL || (member = conference_member_get(conference, id))) {
+	if (member != NULL) {
 		switch_event_t *event;
 
 		if (data) {
@@ -1897,15 +1923,17 @@
 			switch_mutex_unlock(member->flag_mutex);
 		}
 
-		stream->write_function(stream, "Volume OUT %u=%d\n", id, member->volume_out_level);
+		if(stream != NULL) {
+			stream->write_function(stream, "Volume OUT %u=%d\n", member->id, member->volume_out_level);
+		}
 
 		if (data) {
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 				switch_channel_t *channel = switch_core_session_get_channel(member->session);
 				switch_channel_event_set_data(channel, event);
 
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-out-member");
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_out_level);
 
@@ -1913,7 +1941,6 @@
 			}
 		}
 	} else {
-		stream->write_function(stream, "Non-Existant ID %u\n", id);
 		err = 1;
 	}
 
@@ -2423,13 +2450,18 @@
 										 conference_member_itterator(conference, stream, conf_function_api_commands[i].pfnapicmd, argv[argn+2]);
 									} else {
 										conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_function_api_commands[i].pfnapicmd;
+										conference_member_t *member = conference_member_get(conference, id);
 
-										if (pfn(conference, NULL, id, stream, argv[argn+2]) != 0) {
-											// command returned error, so show syntax usage
-											stream->write_function(stream,conf_function_api_commands[i].psyntax);
+										if (member != NULL) {
+											pfn(conference_member_get(conference, id), stream, argv[argn+2]);
+										} else {
+											if (id == 0) {
+												stream->write_function(stream,conf_function_api_commands[i].psyntax);
+											} else {
+												stream->write_function(stream, "Non-Existant ID %u\n", id);
 											}
+										}
 									}
-
 								}
 								break;
 							case 2:	// commands that deals with all text after command



More information about the Freeswitch-branches mailing list