Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Set Timer a function callback (http://www.go4expert.com/forums/set-timer-function-callback-t14260/)

davidhai 29Sep2008 14:17

Set Timer a function callback
 
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 30Sep2008 07:38

Re: Set Timer a function callback
 
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 30Sep2008 20:45

Re: Set Timer a function callback
 
What operating system?
(Looks like unix. What is the function for creating a timer?)
Where is p_old_server coming from.

davidhai 1Oct2008 07:13

Re: Set Timer a function callback
 
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.


All times are GMT +5.5. The time now is 06:35.