PipeWire: pipewire/properties.h Source File

PipeWire 1.6.4

Loading...
Searching...
No Matches
properties.h
Go to the documentation of this file.
1/* PipeWire */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef PIPEWIRE_PROPERTIES_H
6#define PIPEWIRE_PROPERTIES_H
7
8#include <stdarg.h>
9
10#include <spa/utils/cleanup.h>
11#include <spa/utils/dict.h>
12#include <spa/utils/string.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#ifndef PW_API_PROPERTIES
19#define PW_API_PROPERTIES static inline
20#endif
21
29
34struct pw_properties {
35 struct spa_dict dict;
36 uint32_t flags;
37};
38
39 struct pw_properties *
40 pw_properties_new(const char *key, ...) SPA_SENTINEL;
41
42struct pw_properties *
43 pw_properties_new_dict(const struct spa_dict *dict);
44
45struct pw_properties *
46 pw_properties_new_string(const char *args);
47
48struct pw_properties *
49 pw_properties_new_string_checked(const char *args, size_t size,
50 struct spa_error_location *loc);
51
52struct pw_properties *
53 pw_properties_copy(const struct pw_properties *properties);
54
55int pw_properties_update_keys(struct pw_properties *props,
56 const struct spa_dict *dict, const char * const keys[]);
57int pw_properties_update_ignore(struct pw_properties *props,
58 const struct spa_dict *dict, const char * const ignore[]);
59
60/* Update props with all key/value pairs from dict */
61int pw_properties_update(struct pw_properties *props,
62 const struct spa_dict *dict);
63
64/* Update props with all key/value pairs from str */
65int pw_properties_update_string(struct pw_properties *props,
66 const char *str, size_t size);
67
68int pw_properties_update_string_checked(struct pw_properties *props,
69 const char *str, size_t size, struct spa_error_location *loc);
70
71int pw_properties_add(struct pw_properties *oldprops,
72 const struct spa_dict *dict);
73int pw_properties_add_keys(struct pw_properties *oldprops,
74 const struct spa_dict *dict, const char * const keys[]);
75
76void pw_properties_clear(struct pw_properties *properties);
77
78void
79 pw_properties_free(struct pw_properties *properties);
80
81int
82 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
83
84int
85 pw_properties_setf(struct pw_properties *properties,
86 const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
87int
88 pw_properties_setva(struct pw_properties *properties,
89 const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
90const char *
91 pw_properties_get(const struct pw_properties *properties, const char *key);
92
93int
94 pw_properties_fetch_uint32(const struct pw_properties *properties, const char *key, uint32_t *value);
95
96int
97 pw_properties_fetch_int32(const struct pw_properties *properties, const char *key, int32_t *value);
98
99int
100 pw_properties_fetch_uint64(const struct pw_properties *properties, const char *key, uint64_t *value);
101
102int
103 pw_properties_fetch_int64(const struct pw_properties *properties, const char *key, int64_t *value);
104
105int
106 pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value);
107
108 PW_API_PROPERTIES uint32_t
109 pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
110{
111 uint32_t val = deflt;
112 pw_properties_fetch_uint32(properties, key, &val);
113 return val;
114}
115
116 PW_API_PROPERTIES int32_t
117 pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
118{
119 int32_t val = deflt;
120 pw_properties_fetch_int32(properties, key, &val);
121 return val;
122}
123
124 PW_API_PROPERTIES uint64_t
125 pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
126{
127 uint64_t val = deflt;
128 pw_properties_fetch_uint64(properties, key, &val);
129 return val;
130}
131
132 PW_API_PROPERTIES int64_t
133 pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
134{
135 int64_t val = deflt;
136 pw_properties_fetch_int64(properties, key, &val);
137 return val;
138}
139
140
141 PW_API_PROPERTIES bool
142 pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
143{
144 bool val = deflt;
145 pw_properties_fetch_bool(properties, key, &val);
146 return val;
147}
148
149const char *
150 pw_properties_iterate(const struct pw_properties *properties, void **state);
151
152#define PW_PROPERTIES_FLAG_NL (1<<0)
153#define PW_PROPERTIES_FLAG_RECURSE (1<<1)
154#define PW_PROPERTIES_FLAG_ENCLOSE (1<<2)
155#define PW_PROPERTIES_FLAG_ARRAY (1<<3)
156#define PW_PROPERTIES_FLAG_COLORS (1<<4)
157int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
158
159 PW_API_PROPERTIES bool pw_properties_parse_bool(const char *value) {
160 return spa_atob(value);
161}
162
163 PW_API_PROPERTIES int pw_properties_parse_int(const char *value) {
164 int v;
165 return spa_atoi32(value, &v, 0) ? v: 0;
166}
167
168 PW_API_PROPERTIES int64_t pw_properties_parse_int64(const char *value) {
169 int64_t v;
170 return spa_atoi64(value, &v, 0) ? v : 0;
171}
172
173 PW_API_PROPERTIES uint64_t pw_properties_parse_uint64(const char *value) {
174 uint64_t v;
175 return spa_atou64(value, &v, 0) ? v : 0;
176}
177
178 PW_API_PROPERTIES float pw_properties_parse_float(const char *value) {
179 float v;
180 return spa_atof(value, &v) ? v : 0.0f;
181}
182
183 PW_API_PROPERTIES double pw_properties_parse_double(const char *value) {
184 double v;
185 return spa_atod(value, &v) ? v : 0.0;
186}
187
188/**
189 * \}
190 */
191
192SPA_DEFINE_AUTOPTR_CLEANUP(pw_properties, struct pw_properties, {
193 spa_clear_ptr(*thing, pw_properties_free);
194})
195
196#ifdef __cplusplus
197}
198#endif
199
200#endif /* PIPEWIRE_PROPERTIES_H */
args
uint32_t int int const char va_list args
Definition core.h:434
pw_properties_free
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition properties.c:559
pw_properties_parse_int
PW_API_PROPERTIES int pw_properties_parse_int(const char *value)
Definition properties.h:173
pw_properties_parse_int64
PW_API_PROPERTIES int64_t pw_properties_parse_int64(const char *value)
Definition properties.h:178
pw_properties_new
struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition properties.c:97
pw_properties_parse_float
PW_API_PROPERTIES float pw_properties_parse_float(const char *value)
Definition properties.h:188
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:301
pw_properties_add
int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict)
Add properties.
Definition properties.c:503
pw_properties_parse_bool
PW_API_PROPERTIES bool pw_properties_parse_bool(const char *value)
Definition properties.h:169
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:762
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:434
pw_properties_update
int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition properties.c:478
pw_properties_iterate
const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition properties.c:786
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:132
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:708
pw_properties_setf
int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...)
Set a property value by format.
Definition properties.c:617
pw_properties_parse_double
PW_API_PROPERTIES double pw_properties_parse_double(const char *value)
Definition properties.h:193
pw_properties_get_int64
PW_API_PROPERTIES int64_t pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
Definition properties.h:138
pw_properties_get
const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition properties.c:638
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:346
pw_properties_get_int32
PW_API_PROPERTIES int32_t pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
Definition properties.h:122
pw_properties_set
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition properties.c:586
pw_properties_get_bool
PW_API_PROPERTIES bool pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
Definition properties.h:147
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:405
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:735
pw_properties_get_uint32
PW_API_PROPERTIES uint32_t pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
Definition properties.h:114
pw_properties_clear
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition properties.c:457
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:654
pw_properties_update_string_checked
int pw_properties_update_string_checked(struct pw_properties *props, const char *str, size_t size, struct spa_error_location *loc)
Check str is a well-formed properties JSON string and update the properties on success.
Definition properties.c:327
pw_properties_get_uint64
PW_API_PROPERTIES uint64_t pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
Definition properties.h:130
pw_properties_setva
int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args)
Definition properties.c:592
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:533
pw_properties_copy
struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition properties.c:392
pw_properties_new_string_checked
struct pw_properties * pw_properties_new_string_checked(const char *args, size_t size, struct spa_error_location *loc)
Definition properties.c:367
pw_properties_parse_uint64
PW_API_PROPERTIES uint64_t pw_properties_parse_uint64(const char *value)
Definition properties.h:183
pw_properties_serialize_dict
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition properties.c:915
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:681
spa_atou64
SPA_API_STRING 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:192
spa_atof
SPA_API_STRING bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition string.h:298
spa_atob
SPA_API_STRING bool spa_atob(const char *str)
Convert str to a boolean.
Definition string.h:215
spa_atoi64
SPA_API_STRING 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:167
spa_atoi32
SPA_API_STRING 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:111
spa_atod
SPA_API_STRING bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition string.h:348
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:297
SPA_SENTINEL
#define SPA_SENTINEL
Definition defs.h:307
PW_API_PROPERTIES
#define PW_API_PROPERTIES
Definition properties.h:24
string.h
spa/utils/string.h
pw_properties
Definition properties.h:39
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition properties.h:40
pw_properties::flags
uint32_t flags
extra flags
Definition properties.h:41
spa_dict
Definition dict.h:51
spa_error_location
Definition defs.h:443
dict.h
spa/utils/dict.h