Review Board 1.7.16


Various updates to the timing API

Review Request #162 - Created Feb. 16, 2009 and submitted

Russell Bryant
/trunk
Reviewers
asterisk-dev
Asterisk
Now that we have multiple timing modules, only being to load one module is causing some usability issues.  So, that inspired this patch.  I am proposing that this patch go in both trunk and 1.6.1.

1) Add module use count handling so that timing modules can be unloaded.

2) Allow multiple timing modules to be loaded, and use the one with the highest priority value.

3) Report which timing module is being use in the "timing test" CLI command, at the request of Tzafrir on the -dev list.

Note: This patch requires the heap implementation from /r/160/.
It compiles.  "timing test" still works and reports the module I would expect to be in use.
/trunk/include/asterisk/timing.h
Revision 176034 New Change
1
/*
1
/*
2
 * Asterisk -- An open source telephony toolkit.
2
 * Asterisk -- An open source telephony toolkit.
3
 *
3
 *
4
 * Copyright (C) 2008, Digium, Inc.
4
 * Copyright (C) 2008 - 2009, Digium, Inc.
5
 *
5
 *
6
 * Kevin P. Fleming <kpfleming@digium.com>
6
 * Kevin P. Fleming <kpfleming@digium.com>

    
   
7
 * Russell Bryant <russell@digium.com>
7
 *
8
 *
8
 * See http://www.asterisk.org for more information about
9
 * See http://www.asterisk.org for more information about
9
 * the Asterisk project. Please do not directly contact
10
 * the Asterisk project. Please do not directly contact
10
 * any of the maintainers of this project for assistance;
11
 * any of the maintainers of this project for assistance;
11
 * the project provides a web site, mailing lists and IRC
12
 * the project provides a web site, mailing lists and IRC
[+20] [20] 6 lines
[+20]
18

    
   
19

   
19
/*!
20
/*!
20
  \file timing.h
21
  \file timing.h
21
  \brief Timing source management
22
  \brief Timing source management
22
  \author Kevin P. Fleming <kpfleming@digium.com>
23
  \author Kevin P. Fleming <kpfleming@digium.com>

    
   
24
  \author Russell Bryant <russell@digium.com>
23

    
   
25

   
24
  Portions of Asterisk require a timing source, a periodic trigger
26
  Portions of Asterisk require a timing source, a periodic trigger
25
  for media handling activities. The functions in this file allow
27
  for media handling activities. The functions in this file allow
26
  a loadable module to provide a timing source for Asterisk and its
28
  a loadable module to provide a timing source for Asterisk and its
27
  modules, so that those modules can request a 'timing handle' when
29
  modules, so that those modules can request a 'timing handle' when
[+20] [20] 25 lines
[+20]
53

    
   
55

   
54
#if defined(__cplusplus) || defined(c_plusplus)
56
#if defined(__cplusplus) || defined(c_plusplus)
55
extern "C" {
57
extern "C" {
56
#endif
58
#endif
57

    
   
59

   
58
enum ast_timing_event {
60
enum ast_timer_event {
59
	AST_TIMING_EVENT_EXPIRED = 1,
61
	AST_TIMING_EVENT_EXPIRED = 1,
60
	AST_TIMING_EVENT_CONTINUOUS = 2,
62
	AST_TIMING_EVENT_CONTINUOUS = 2,
61
};
63
};
62

    
   
64

   
63
/*!
65
/*!
64
 * \brief Timing module interface
66
 * \brief Timing module interface
65
 *
67
 *
66
 * The public API calls for the timing API directly map to this interface.
68
 * The public API calls for the timing API directly map to this interface.
67
 * So, the behavior of these calls should match the documentation of the
69
 * So, the behavior of these calls should match the documentation of the
68
 * public API calls.
70
 * public API calls.
69
 */
71
 */
70
struct ast_timing_functions {
72
struct ast_timing_interface {

    
   
73
	const char *name;

    
   
74
	/*! This handles the case where multiple timing modules are loaded.

    
   
75
	 *  The highest priority timing interface available will be used. */

    
   
76
	unsigned int priority;
71
	int (*timer_open)(void);
77
	int (*timer_open)(void);
72
	void (*timer_close)(int handle);
78
	void (*timer_close)(int handle);
73
	int (*timer_set_rate)(int handle, unsigned int rate);
79
	int (*timer_set_rate)(int handle, unsigned int rate);
74
	void (*timer_ack)(int handle, unsigned int quantity);
80
	void (*timer_ack)(int handle, unsigned int quantity);
75
	int (*timer_enable_continuous)(int handle);
81
	int (*timer_enable_continuous)(int handle);
76
	int (*timer_disable_continuous)(int handle);
82
	int (*timer_disable_continuous)(int handle);
77
	enum ast_timing_event (*timer_get_event)(int handle);
83
	enum ast_timer_event (*timer_get_event)(int handle);
78
	unsigned int (*timer_get_max_rate)(int handle);
84
	unsigned int (*timer_get_max_rate)(int handle);
79
};
85
};
80

    
   
86

   
81
/*!
87
/*!
82
 * \brief Install a set of timing functions.
88
 * \brief Register a set of timing functions.
83
 *
89
 *
84
 * \param funcs An instance of the \c ast_timing_functions structure with pointers
90
 * \param funcs An instance of the \c ast_timing_interfaces structure with pointers
85
 *        to the functions provided by the timing implementation.
91
 *        to the functions provided by the timing implementation.
86
 *
92
 *
87
 * \retval NULL failure 
93
 * \retval NULL failure 
88
 * \retval non-Null handle to be passed to ast_uninstall_timing_functions() on success
94
 * \retval non-Null handle to be passed to ast_unregister_timing_interface() on success
89
 */
95
 */
90
void *ast_install_timing_functions(struct ast_timing_functions *funcs);
96
#define ast_register_timing_interface(i) _ast_register_timing_interface(i, ast_module_info->self)

    
   
97
void *_ast_register_timing_interface(struct ast_timing_interface *funcs,

    
   
98
		struct ast_module *mod);
91

    
   
99

   
92
/*!
100
/*!
93
 * \brief Uninstall a previously-installed set of timing functions.
101
 * \brief Unregister a previously registered timing interface.
94
 *
102
 *
95
 * \param handle The handle returned from a prior successful call to
103
 * \param handle The handle returned from a prior successful call to
96
 *        ast_install_timing_functions().
104
 *        ast_register_timing_interface().
97
 *
105
 *
98
 * \return nothing
106
 * \retval 0 success

    
   
107
 * \retval non-zero failure
99
 */
108
 */
100
void ast_uninstall_timing_functions(void *handle);
109
int ast_unregister_timing_interface(void *handle);
101

    
   
110

   
102
/*!
111
/*!
103
 * \brief Open a timing fd
112
 * \brief Open a timing fd
104
 *
113
 *
105
 * \retval -1 error, with errno set
114
 * \retval -1 error, with errno set
[+20] [20] 69 lines
[+20] [+] int ast_timer_disable_continuous(int handle);
175
 * After poll() indicates that there is input on the timing fd, this will
184
 * After poll() indicates that there is input on the timing fd, this will
176
 * be called to find out what triggered it.
185
 * be called to find out what triggered it.
177
 *
186
 *
178
 * \return which event triggered the timing fd
187
 * \return which event triggered the timing fd
179
 */
188
 */
180
enum ast_timing_event ast_timer_get_event(int handle);
189
enum ast_timer_event ast_timer_get_event(int handle);
181

    
   
190

   
182
/*!
191
/*!
183
 * \brief Get maximum rate supported for a timing handle
192
 * \brief Get maximum rate supported for a timing handle
184
 *
193
 *
185
 * \param handle timing fd returned by timer_open()
194
 * \param handle timing fd returned by timer_open()
[+20] [20] 10 lines
/trunk/main/Makefile
Revision 176034 New Change
 
/trunk/main/channel.c
Revision 176034 New Change
 
/trunk/main/timing.c
Revision 176034 New Change
 
/trunk/res/res_timing_dahdi.c
Revision 176034 New Change
 
/trunk/res/res_timing_pthread.c
Revision 176034 New Change
 
/trunk/res/res_timing_timerfd.c
Revision 176034 New Change
 
  1. /trunk/include/asterisk/timing.h: Loading...
  2. /trunk/main/Makefile: Loading...
  3. /trunk/main/channel.c: Loading...
  4. /trunk/main/timing.c: Loading...
  5. /trunk/res/res_timing_dahdi.c: Loading...
  6. /trunk/res/res_timing_pthread.c: Loading...
  7. /trunk/res/res_timing_timerfd.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.