mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	Merge "app_queue.c: Extract some functions for simpler code."
This commit is contained in:
		
							
								
								
									
										149
									
								
								apps/app_queue.c
									
									
									
									
									
								
							
							
						
						
									
										149
									
								
								apps/app_queue.c
									
									
									
									
									
								
							| @@ -6990,6 +6990,55 @@ static int publish_queue_member_pause(struct call_queue *q, struct member *membe | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| /*! | ||||
|  * \internal | ||||
|  * \brief Set the pause status of the specific queue member. | ||||
|  * | ||||
|  * \param q Which queue the member belongs. | ||||
|  * \param mem Queue member being paused/unpaused. | ||||
|  * \param reason Why is this happening (Can be NULL/empty for no reason given.) | ||||
|  * \param paused Set to 1 if the member is being paused or 0 to unpause. | ||||
|  * | ||||
|  * \pre The q is locked on entry. | ||||
|  * | ||||
|  * \return Nothing | ||||
|  */ | ||||
| static void set_queue_member_pause(struct call_queue *q, struct member *mem, const char *reason, int paused) | ||||
| { | ||||
| 	if (mem->paused == paused) { | ||||
| 		ast_debug(1, "%spausing already-%spaused queue member %s:%s\n", | ||||
| 			(paused ? "" : "un"), (paused ? "" : "un"), q->name, mem->interface); | ||||
| 	} | ||||
|  | ||||
| 	if (mem->realtime) { | ||||
| 		if (update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0")) { | ||||
| 			ast_log(LOG_WARNING, "Failed %spause update of realtime queue member %s:%s\n", | ||||
| 				(paused ? "" : "un"), q->name, mem->interface); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	mem->paused = paused; | ||||
| 	ast_devstate_changed(mem->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE, | ||||
| 		AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, mem->interface); | ||||
|  | ||||
| 	if (queue_persistent_members) { | ||||
| 		dump_queue_members(q); | ||||
| 	} | ||||
|  | ||||
| 	if (is_member_available(q, mem)) { | ||||
| 		ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, | ||||
| 			"Queue:%s_avail", q->name); | ||||
| 	} else if (!num_available_members(q)) { | ||||
| 		ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE, | ||||
| 			"Queue:%s_avail", q->name); | ||||
| 	} | ||||
|  | ||||
| 	ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), | ||||
| 		"%s", S_OR(reason, "")); | ||||
|  | ||||
| 	publish_queue_member_pause(q, mem, reason); | ||||
| } | ||||
|  | ||||
| static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused) | ||||
| { | ||||
| 	int found = 0; | ||||
| @@ -7003,55 +7052,30 @@ static int set_member_paused(const char *queuename, const char *interface, const | ||||
| 			struct member *mem; | ||||
|  | ||||
| 			if ((mem = interface_exists(q, interface))) { | ||||
| 				if (mem->paused == paused) { | ||||
| 					ast_debug(1, "%spausing already-%spaused queue member %s:%s\n", (paused ? "" : "un"), (paused ? "" : "un"), q->name, interface); | ||||
| 				/* | ||||
| 				 * Before we do the PAUSE/UNPAUSE, log if this was a | ||||
| 				 * PAUSEALL/UNPAUSEALL but only on the first found entry. | ||||
| 				 */ | ||||
| 				++found; | ||||
| 				if (found == 1 | ||||
| 					&& ast_strlen_zero(queuename)) { | ||||
| 					/* | ||||
| 					 * XXX In all other cases, we use the queue name, | ||||
| 					 * but since this affects all queues, we cannot. | ||||
| 					 */ | ||||
| 					ast_queue_log("NONE", "NONE", mem->membername, | ||||
| 						(paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", ""); | ||||
| 				} | ||||
|  | ||||
| 				if (mem->realtime) { | ||||
| 					if (update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0")) { | ||||
| 						ast_log(LOG_WARNING, "Failed %spausing realtime queue member %s:%s\n", (paused ? "" : "un"), q->name, interface); | ||||
| 						ao2_ref(mem, -1); | ||||
| 						ao2_unlock(q); | ||||
| 						queue_t_unref(q, "Done with iterator"); | ||||
| 						continue; | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				mem->paused = paused; | ||||
| 				ast_devstate_changed(mem->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE, | ||||
| 					AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, mem->interface); | ||||
| 				found++; | ||||
|  | ||||
| 				/* Before we do the PAUSE/UNPAUSE log, if this was a PAUSEALL/UNPAUSEALL, log that here, but only on the first found entry. */ | ||||
| 				if (found == 1) { | ||||
|  | ||||
| 					/* XXX In all other cases, we use the membername, but since this affects all queues, we cannot */ | ||||
| 					if (ast_strlen_zero(queuename)) { | ||||
| 						ast_queue_log("NONE", "NONE", interface, (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", ""); | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				if (queue_persistent_members) { | ||||
| 					dump_queue_members(q); | ||||
| 				} | ||||
|  | ||||
| 				if (is_member_available(q, mem)) { | ||||
| 					ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name); | ||||
| 				} else if (!num_available_members(q)) { | ||||
| 					ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name); | ||||
| 				} | ||||
|  | ||||
| 				ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), "%s", S_OR(reason, "")); | ||||
|  | ||||
| 				publish_queue_member_pause(q, mem, reason); | ||||
| 				set_queue_member_pause(q, mem, reason, paused); | ||||
| 				ao2_ref(mem, -1); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (!ast_strlen_zero(queuename) && !strcasecmp(queuename, q->name)) { | ||||
| 			ao2_unlock(q); | ||||
| 			queue_t_unref(q, "Done with iterator"); | ||||
| 			break; | ||||
| 			if (!ast_strlen_zero(queuename)) { | ||||
| 				ao2_unlock(q); | ||||
| 				queue_t_unref(q, "Done with iterator"); | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		ao2_unlock(q); | ||||
| @@ -7097,6 +7121,31 @@ static int set_member_penalty_help_members(struct call_queue *q, const char *int | ||||
| 	return foundinterface; | ||||
| } | ||||
|  | ||||
| /*! | ||||
|  * \internal | ||||
|  * \brief Set the ringinuse value of the specific queue member. | ||||
|  * | ||||
|  * \param q Which queue the member belongs. | ||||
|  * \param mem Queue member being set. | ||||
|  * \param ringinuse Set to 1 if the member is called when inuse. | ||||
|  * | ||||
|  * \pre The q is locked on entry. | ||||
|  * | ||||
|  * \return Nothing | ||||
|  */ | ||||
| static void set_queue_member_ringinuse(struct call_queue *q, struct member *mem, int ringinuse) | ||||
| { | ||||
| 	if (mem->realtime) { | ||||
| 		update_realtime_member_field(mem, q->name, realtime_ringinuse_field, | ||||
| 			ringinuse ? "1" : "0"); | ||||
| 	} | ||||
|  | ||||
| 	mem->ringinuse = ringinuse; | ||||
|  | ||||
| 	ast_queue_log(q->name, "NONE", mem->interface, "RINGINUSE", "%d", ringinuse); | ||||
| 	queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem)); | ||||
| } | ||||
|  | ||||
| static int set_member_ringinuse_help_members(struct call_queue *q, const char *interface, int ringinuse) | ||||
| { | ||||
| 	struct member *mem; | ||||
| @@ -7105,17 +7154,7 @@ static int set_member_ringinuse_help_members(struct call_queue *q, const char *i | ||||
| 	ao2_lock(q); | ||||
| 	if ((mem = interface_exists(q, interface))) { | ||||
| 		foundinterface++; | ||||
| 		if (mem->realtime) { | ||||
| 			char rtringinuse[80]; | ||||
|  | ||||
| 			sprintf(rtringinuse, "%i", ringinuse); | ||||
| 			update_realtime_member_field(mem, q->name, realtime_ringinuse_field, rtringinuse); | ||||
| 		} | ||||
|  | ||||
| 		mem->ringinuse = ringinuse; | ||||
|  | ||||
| 		ast_queue_log(q->name, "NONE", interface, "RINGINUSE", "%d", ringinuse); | ||||
| 		queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem)); | ||||
| 		set_queue_member_ringinuse(q, mem, ringinuse); | ||||
| 		ao2_ref(mem, -1); | ||||
| 	} | ||||
| 	ao2_unlock(q); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user