mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	message-params: Add read/write functions for various simple data types
The following functions have been added: pa_message_params_write_double() - writes a double to a pa_message_params structure pa_message_params_write_int64() - writes an integer to a pa_message_params structure pa_message_params_write_uint64() - writes an unsigned to a pa_message_params structure pa_message_params_write_bool() - writes a boolean to a pa_message_params structure pa_message_params_read_double() - read a double from a parameter list pa_message_params_read_int64() - read an integer from a parameter list pa_message_params_read_uint64() - read an unsigned from a parameter list pa_message_params_read_bool() - read a boolean from a parameter list The patch also improves the doxygen documentation im message-params.h Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
This commit is contained in:
		
							parent
							
								
									ca66388608
								
							
						
					
					
						commit
						8140932afd
					
				
					 3 changed files with 250 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -26,28 +26,68 @@
 | 
			
		|||
#include <pulse/version.h>
 | 
			
		||||
 | 
			
		||||
/** \file
 | 
			
		||||
 * Utility functions for reading and writing message parameters */
 | 
			
		||||
 * Utility functions for reading and writing message parameters.
 | 
			
		||||
 * All read functions return a value from pa_message_params_error_code
 | 
			
		||||
 * and the read value in result (or *result for string functions).
 | 
			
		||||
 * The string read functions read_string() and read_raw() return a pointer
 | 
			
		||||
 * to a sub-string within the parameter list in *result, therefore the
 | 
			
		||||
 * string in *result must not be freed and is only valid within the
 | 
			
		||||
 * message handler callback function. If the string is needed outside
 | 
			
		||||
 * the callback, it must be copied using pa_xstrdup().
 | 
			
		||||
 * When a read function is called, the state pointer is advanced to the
 | 
			
		||||
 * next list element. The variable state points to should be initialized
 | 
			
		||||
 * to NULL before the first call.\n
 | 
			
		||||
 * Write functions operate on a pa_message_params structure which is a
 | 
			
		||||
 * wrapper for pa_strbuf. A parameter list or sub-list is started by a
 | 
			
		||||
 * call to begin_list() and ended by a call to end_list().
 | 
			
		||||
 * A pa_message_params structure must be converted to a string using
 | 
			
		||||
 * pa_message_params_to_string_free() before it can be passed to a
 | 
			
		||||
 * message handler. */
 | 
			
		||||
 | 
			
		||||
PA_C_DECL_BEGIN
 | 
			
		||||
 | 
			
		||||
/** Structure which holds a parameter list. Wrapper for pa_strbuf  \since 15.0 */
 | 
			
		||||
typedef struct pa_message_params pa_message_params;
 | 
			
		||||
 | 
			
		||||
/** Read function return values  \since 15.0 */
 | 
			
		||||
enum pa_message_params_error_code {
 | 
			
		||||
    /** No value (empty element) found for numeric or boolean value */
 | 
			
		||||
    PA_MESSAGE_PARAMS_IS_NULL = -2,
 | 
			
		||||
    /** Error encountered while parsing a value */
 | 
			
		||||
    PA_MESSAGE_PARAMS_PARSE_ERROR = -1,
 | 
			
		||||
    /** End of parameter list reached */
 | 
			
		||||
    PA_MESSAGE_PARAMS_LIST_END = 0,
 | 
			
		||||
    /** Parsing successful */
 | 
			
		||||
    PA_MESSAGE_PARAMS_OK = 1,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/** @{ \name Read functions */
 | 
			
		||||
 | 
			
		||||
/** Read raw data from a parameter list. Used to split a message parameter
 | 
			
		||||
/** Read a boolean from parameter list in c. \since 15.0 */
 | 
			
		||||
int pa_message_params_read_bool(char *c, bool *result, void **state);
 | 
			
		||||
 | 
			
		||||
/** Read a double from parameter list in c. \since 15.0 */
 | 
			
		||||
int pa_message_params_read_double(char *c, double *result, void **state);
 | 
			
		||||
 | 
			
		||||
/** Read an integer from parameter list in c. \since 15.0 */
 | 
			
		||||
int pa_message_params_read_int64(char *c, int64_t *result, void **state);
 | 
			
		||||
 | 
			
		||||
/** Read raw data from parameter list in c. Used to split a message parameter
 | 
			
		||||
 * string into list elements. The string returned in *result must not be freed.  \since 15.0 */
 | 
			
		||||
int pa_message_params_read_raw(char *c, char **result, void **state);
 | 
			
		||||
 | 
			
		||||
/** Read a string from a parameter list. Escaped curly braces and backslashes
 | 
			
		||||
/** Read a string from a parameter list in c. Escaped curly braces and backslashes
 | 
			
		||||
 * will be unescaped. \since 15.0 */
 | 
			
		||||
int pa_message_params_read_string(char *c, const char **result, void **state);
 | 
			
		||||
 | 
			
		||||
/** Read an unsigned integer from parameter list in c. \since 15.0 */
 | 
			
		||||
int pa_message_params_read_uint64(char *c, uint64_t *result, void **state);
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 | 
			
		||||
/** @{ \name Write functions */
 | 
			
		||||
 | 
			
		||||
/** Create a new pa_message_params structure  \since 15.0 */
 | 
			
		||||
/** Create a new pa_message_params structure.  \since 15.0 */
 | 
			
		||||
pa_message_params *pa_message_params_new(void);
 | 
			
		||||
 | 
			
		||||
/** Free a pa_message_params structure.  \since 15.0 */
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +102,17 @@ void pa_message_params_begin_list(pa_message_params *params);
 | 
			
		|||
/** End a list by writing a closing brace.  \since 15.0 */
 | 
			
		||||
void pa_message_params_end_list(pa_message_params *params);
 | 
			
		||||
 | 
			
		||||
/** Append a boolean to parameter list. \since 15.0 */
 | 
			
		||||
void pa_message_params_write_bool(pa_message_params *params, bool value);
 | 
			
		||||
 | 
			
		||||
/** Append a double to parameter list. Precision gives the number of
 | 
			
		||||
 * significant digits. The decimal separator will always be written as
 | 
			
		||||
 * dot, regardless which locale is used. \since 15.0 */
 | 
			
		||||
void pa_message_params_write_double(pa_message_params *params, double value, int precision);
 | 
			
		||||
 | 
			
		||||
/** Append an integer to parameter list. \since 15.0 */
 | 
			
		||||
void pa_message_params_write_int64(pa_message_params *params, int64_t value);
 | 
			
		||||
 | 
			
		||||
/** Append string to parameter list. Curly braces and backslashes will be escaped.  \since 15.0 */
 | 
			
		||||
void pa_message_params_write_string(pa_message_params *params, const char *value);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -70,6 +121,9 @@ void pa_message_params_write_string(pa_message_params *params, const char *value
 | 
			
		|||
 * the string if add_braces is true.  \since 15.0 */
 | 
			
		||||
void pa_message_params_write_raw(pa_message_params *params, const char *value, bool add_braces);
 | 
			
		||||
 | 
			
		||||
/** Append an unsigned integer to parameter list. \since 15.0 */
 | 
			
		||||
void pa_message_params_write_uint64(pa_message_params *params, uint64_t value);
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 | 
			
		||||
PA_C_DECL_END
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue