mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	app: Add functions to swap voicemail function table for testing purposes
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@432556 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		
							
								
								
									
										51
									
								
								main/app.c
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								main/app.c
									
									
									
									
									
								
							| @@ -519,6 +519,57 @@ void ast_vm_unregister(const char *module_name) | ||||
| 	ao2_cleanup(table); | ||||
| } | ||||
|  | ||||
| #ifdef TEST_FRAMEWORK | ||||
| /*! \brief Holding container for the voicemail provider used while testing */ | ||||
| static AO2_GLOBAL_OBJ_STATIC(vm_provider_holder); | ||||
| static int provider_is_swapped = 0; | ||||
|  | ||||
| void ast_vm_test_swap_table_in(const struct ast_vm_functions *vm_table) | ||||
| { | ||||
| 	RAII_VAR(struct ast_vm_functions *, holding_table, NULL, ao2_cleanup); | ||||
| 	RAII_VAR(struct ast_vm_functions *, new_table, NULL, ao2_cleanup); | ||||
|  | ||||
| 	if (provider_is_swapped) { | ||||
| 		ast_log(LOG_ERROR, "Attempted to swap in test function table without swapping out old test table.\n"); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	holding_table = ao2_global_obj_ref(vm_provider); | ||||
|  | ||||
| 	if (holding_table) { | ||||
| 		ao2_global_obj_replace_unref(vm_provider_holder, holding_table); | ||||
| 	} | ||||
|  | ||||
| 	new_table = ao2_alloc_options(sizeof(*new_table), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK); | ||||
| 	if (!new_table) { | ||||
| 		return; | ||||
| 	} | ||||
| 	*new_table = *vm_table; | ||||
|  | ||||
| 	ao2_global_obj_replace_unref(vm_provider, new_table); | ||||
| 	provider_is_swapped = 1; | ||||
| } | ||||
|  | ||||
| void ast_vm_test_swap_table_out(void) | ||||
| { | ||||
| 	RAII_VAR(struct ast_vm_functions *, held_table, NULL, ao2_cleanup); | ||||
|  | ||||
| 	if (!provider_is_swapped) { | ||||
| 		ast_log(LOG_ERROR, "Attempted to swap out test function table, but none is currently installed.\n"); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	held_table = ao2_global_obj_ref(vm_provider_holder); | ||||
| 	if (!held_table) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	ao2_global_obj_replace_unref(vm_provider, held_table); | ||||
| 	ao2_global_obj_release(vm_provider_holder); | ||||
| 	provider_is_swapped = 0; | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /*! \brief The container for the voicemail greeter provider */ | ||||
| static AO2_GLOBAL_OBJ_STATIC(vm_greeter_provider); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user