PipeWire: pipewire/properties.h Source File

PipeWire 0.3.51

properties.h
Go to the documentation of this file.
1/* PipeWire
2 *
3 * Copyright © 2018 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef PIPEWIRE_PROPERTIES_H
26#define PIPEWIRE_PROPERTIES_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdarg.h>
33
34#include <spa/utils/dict.h>
35#include <spa/utils/string.h>
36
49struct pw_properties {
50 struct spa_dict dict;
51 uint32_t flags;
52};
53
54 struct pw_properties *
55 pw_properties_new(const char *key, ...) SPA_SENTINEL;
56
57struct pw_properties *
58 pw_properties_new_dict(const struct spa_dict *dict);
59
60struct pw_properties *
61 pw_properties_new_string(const char *args);
62
63struct pw_properties *
64 pw_properties_copy(const struct pw_properties *properties);
65
66int pw_properties_update_keys(struct pw_properties *props,
67 const struct spa_dict *dict, const char * const keys[]);
68int pw_properties_update_ignore(struct pw_properties *props,
69 const struct spa_dict *dict, const char * const ignore[]);
70
71/* Update props with all key/value pairs from dict */
72int pw_properties_update(struct pw_properties *props,
73 const struct spa_dict *dict);
74/* Update props with all key/value pairs from str */
75int pw_properties_update_string(struct pw_properties *props,
76 const char *str, size_t size);
77
78int pw_properties_add(struct pw_properties *oldprops,
79 const struct spa_dict *dict);
80int pw_properties_add_keys(struct pw_properties *oldprops,
81 const struct spa_dict *dict, const char * const keys[]);
82
83void pw_properties_clear(struct pw_properties *properties);
84
85void
86 pw_properties_free(struct pw_properties *properties);
87
88int
89 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
90
91int
92 pw_properties_setf(struct pw_properties *properties,
93 const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
94int
95 pw_properties_setva(struct pw_properties *properties,
96 const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
97const char *
98 pw_properties_get(const struct pw_properties *properties, const char *key);
99
100int
101 pw_properties_fetch_uint32(const struct pw_properties *properties, const char *key, uint32_t *value);
102
103int
104 pw_properties_fetch_int32(const struct pw_properties *properties, const char *key, int32_t *value);
105
106int
107 pw_properties_fetch_uint64(const struct pw_properties *properties, const char *key, uint64_t *value);
108
109int
110 pw_properties_fetch_int64(const struct pw_properties *properties, const char *key, int64_t *value);
111
112int
113 pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value);
114
115static inline uint32_t
116 pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
117{
118 uint32_t val = deflt;
119 pw_properties_fetch_uint32(properties, key, &val);
120 return val;
121}
122
123static inline int32_t
124 pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
125{
126 int32_t val = deflt;
127 pw_properties_fetch_int32(properties, key, &val);
128 return val;
129}
130
131static inline uint64_t
132 pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
133{
134 uint64_t val = deflt;
135 pw_properties_fetch_uint64(properties, key, &val);
136 return val;
137}
138
139static inline int64_t
140 pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
141{
142 int64_t val = deflt;
143 pw_properties_fetch_int64(properties, key, &val);
144 return val;
145}
146
147
148static inline bool
149 pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
150{
151 bool val = deflt;
152 pw_properties_fetch_bool(properties, key, &val);
153 return val;
154}
155
156const char *
157 pw_properties_iterate(const struct pw_properties *properties, void **state);
158
159#define PW_PROPERTIES_FLAG_NL (1<<0)
160int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
161
162static inline bool pw_properties_parse_bool(const char *value) {
163 return spa_atob(value);
164}
165
166static inline int pw_properties_parse_int(const char *value) {
167 int v;
168 return spa_atoi32(value, &v, 0) ? v: 0;
169}
170
171 static inline int64_t pw_properties_parse_int64(const char *value) {
172 int64_t v;
173 return spa_atoi64(value, &v, 0) ? v : 0;
174}
175
176 static inline uint64_t pw_properties_parse_uint64(const char *value) {
177 uint64_t v;
178 return spa_atou64(value, &v, 0) ? v : 0;
179}
180
181 static inline float pw_properties_parse_float(const char *value) {
182 float v;
183 return spa_atof(value, &v) ? v : 0.0f;
184}
185
186 static inline double pw_properties_parse_double(const char *value) {
187 double v;
188 return spa_atod(value, &v) ? v : 0.0;
189}
190
195#ifdef __cplusplus
196}
197#endif
198
199#endif /* PIPEWIRE_PROPERTIES_H */
pw_properties_free
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:368
pw_properties_new
struct pw_properties * pw_properties_new(const char *key,...) 1
Make a new properties object.
Definition: properties.c:102
pw_properties_update_string
int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size)
Update the properties from the given string, overwriting any existing keys with the new values from s...
Definition: properties.c:158
pw_properties_get_bool
static bool pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
Definition: properties.h:153
pw_properties_parse_int64
static int64_t pw_properties_parse_int64(const char *value)
Definition: properties.h:176
pw_properties_parse_int
static int pw_properties_parse_int(const char *value)
Definition: properties.h:171
pw_properties_add
int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict)
Add properties.
Definition: properties.c:323
pw_properties_get
int int const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:491
pw_properties_parse_bool
static bool pw_properties_parse_bool(const char *value)
Definition: properties.h:167
pw_properties_fetch_bool
int pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value)
Fetch a property as boolean value.
Definition: properties.c:621
pw_properties_update_ignore
int pw_properties_update_ignore(struct pw_properties *props, const struct spa_dict *dict, const char *const ignore[])
Definition: properties.c:263
pw_properties_setf
int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...) 1(3
pw_properties_update
int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition: properties.c:302
pw_properties_iterate
const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:645
pw_properties_new_dict
struct pw_properties * pw_properties_new_dict(const struct spa_dict *dict)
Make a new properties object from the given dictionary.
Definition: properties.c:130
pw_properties_fetch_uint64
int pw_properties_fetch_uint64(const struct pw_properties *properties, const char *key, uint64_t *value)
Fetch a property as uint64_t.
Definition: properties.c:567
pw_properties_parse_float
static float pw_properties_parse_float(const char *value)
Definition: properties.h:186
pw_properties_new_string
struct pw_properties * pw_properties_new_string(const char *args)
Make a new properties object from the given str.
Definition: properties.c:201
pw_properties_get_uint64
static uint64_t pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
Definition: properties.h:136
pw_properties_set
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition: properties.c:439
pw_properties_get_int64
static int64_t pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
Definition: properties.h:144
pw_properties_get_int32
static int32_t pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
Definition: properties.h:128
pw_properties_update_keys
int pw_properties_update_keys(struct pw_properties *props, const struct spa_dict *dict, const char *const keys[])
Copy multiple keys from one property to another.
Definition: properties.c:239
pw_properties_fetch_int64
int pw_properties_fetch_int64(const struct pw_properties *properties, const char *key, int64_t *value)
Fetch a property as int64_t.
Definition: properties.c:594
pw_properties_parse_uint64
static uint64_t pw_properties_parse_uint64(const char *value)
Definition: properties.h:181
pw_properties_clear
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:281
pw_properties_parse_double
static double pw_properties_parse_double(const char *value)
Definition: properties.h:191
pw_properties_fetch_uint32
int pw_properties_fetch_uint32(const struct pw_properties *properties, const char *key, uint32_t *value)
Fetch a property as uint32_t.
Definition: properties.c:513
pw_properties_setva
int int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args) 1(3
pw_properties_add_keys
int pw_properties_add_keys(struct pw_properties *oldprops, const struct spa_dict *dict, const char *const keys[])
Add keys.
Definition: properties.c:347
pw_properties_get_uint32
static uint32_t pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
Definition: properties.h:120
pw_properties_copy
struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition: properties.c:226
pw_properties_serialize_dict
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition: properties.c:702
pw_properties_fetch_int32
int pw_properties_fetch_int32(const struct pw_properties *properties, const char *key, int32_t *value)
Fetch a property as int32_t.
Definition: properties.c:540
spa_atod
static bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:345
spa_atou64
static bool spa_atou64(const char *str, uint64_t *val, int base)
Convert str to an uint64_t with the given base and store the result in val.
Definition: string.h:201
spa_atob
static bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:224
spa_atoi64
static bool spa_atoi64(const char *str, int64_t *val, int base)
Convert str to an int64_t with the given base and store the result in val.
Definition: string.h:176
spa_atoi32
static bool spa_atoi32(const char *str, int32_t *val, int base)
Convert str to an int32_t with the given base and store the result in val.
Definition: string.h:120
spa_atof
static bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:301
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
SPA_SENTINEL
#define SPA_SENTINEL
Definition: defs.h:270
string.h
spa/utils/string.h
pw_properties
Definition: properties.h:53
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:54
pw_properties::flags
uint32_t flags
extra flags
Definition: properties.h:55
spa_dict
Definition: dict.h:59
dict.h
spa/utils/dict.h