Set Timer a function callback

davidhai's Avatar, Join Date: Sep 2008
Newbie Member
Hi everybody,

I am trying to switch from a multicast address to another multicast address. On the bottom of ExecSwitchStreams that perform switch, I want to register a function (ExecSwitchStreamsBack ) so that the program will auto call to after t_time seconds. ExecSwitchStreamsBack will switch back to old multicast address.

Code:
static void ExecSwitchStreams(input_thread_t *p_input, char *p_new_server, int64_t t_time)
{		
	InputClean( p_input, &p_input->input );		
	
	input_source_t *other_input = &p_input->input;		
 
	   /* Create the stream_t */
	   other_input->p_stream = streamAccessNew( other_input->p_access, p_new_server, MY_FALSE );
   
		RegisterTimer ( t_time, p_old_server, ExecSwitchStreamsBack) //  Function to register call ExecSwitchStreamsBack after t_time seconds 
																	// p_old_server is a parameter for ExecSwitchStreamsBack 
  
}

static void ExecSwitchStreamsBack(char *p_old_server )
{
	 // code
}
How can I implement the RegisterTimer like that?

Please give me any ideas to implement this function. Many thanks
davidhai's Avatar, Join Date: Sep 2008
Newbie Member
Quote:
Originally Posted by davidhai
Hi everybody,

I am trying to switch from a multicast address to another multicast address. On the bottom of ExecSwitchStreams that perform switch, I want to register a function (ExecSwitchStreamsBack ) so that the program will auto call to after t_time seconds. ExecSwitchStreamsBack will switch back to old multicast address.

Code:
static void ExecSwitchStreams(input_thread_t *p_input, char *p_new_server, int64_t t_time)
{		
	InputClean( p_input, &p_input->input );		
	
	input_source_t *other_input = &p_input->input;		
 
	   /* Create the stream_t */
	   other_input->p_stream = streamAccessNew( other_input->p_access, p_new_server, MY_FALSE );
   
		RegisterTimer ( t_time, p_old_server, ExecSwitchStreamsBack) //  Function to register call ExecSwitchStreamsBack after t_time seconds 
																	// p_old_server is a parameter for ExecSwitchStreamsBack 
  
}

static void ExecSwitchStreamsBack(char *p_old_server )
{
	 // code
}
How can I implement the RegisterTimer like that?

Please give me any ideas to implement this function. Many thanks
If anybody knows about this problem, please help me to solve it.
oogabooga's Avatar
Ambitious contributor
What operating system?
(Looks like unix. What is the function for creating a timer?)
Where is p_old_server coming from.
davidhai's Avatar, Join Date: Sep 2008
Newbie Member
This is a program that it can run on Unix, Window,Mac Os. On window, I use cygwin to compile source. I have use <time.h> library in my source code.

p_old_server is a static variable that is stored before performing switch.