PipeWire: pipewire/properties.h Source File

PipeWire 1.2.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#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <stdarg.h>
13
14#include <spa/utils/cleanup.h>
15#include <spa/utils/dict.h>
16#include <spa/utils/string.h>
17
30struct pw_properties {
31 struct spa_dict dict;
32 uint32_t flags;
33};
34
35 struct pw_properties *
36 pw_properties_new(const char *key, ...) SPA_SENTINEL;
37
38struct pw_properties *
39 pw_properties_new_dict(const struct spa_dict *dict);
40
41struct pw_properties *
42 pw_properties_new_string(const char *args);
43
44struct pw_properties *
45 pw_properties_new_string_checked(const char *args, size_t size,
46 struct spa_error_location *loc);
47
48struct pw_properties *
49 pw_properties_copy(const struct pw_properties *properties);
50
51int pw_properties_update_keys(struct pw_properties *props,
52 const struct spa_dict *dict, const char * const keys[]);
53int pw_properties_update_ignore(struct pw_properties *props,
54 const struct spa_dict *dict, const char * const ignore[]);
55
56/* Update props with all key/value pairs from dict */
57int pw_properties_update(struct pw_properties *props,
58 const struct spa_dict *dict);
59
60/* Update props with all key/value pairs from str */
61int pw_properties_update_string(struct pw_properties *props,
62 const char *str, size_t size);
63
64int pw_properties_update_string_checked(struct pw_properties *props,
65 const char *str, size_t size, struct spa_error_location *loc);
66
67int pw_properties_add(struct pw_properties *oldprops,
68 const struct spa_dict *dict);
69int pw_properties_add_keys(struct pw_properties *oldprops,
70 const struct spa_dict *dict, const char * const keys[]);
71
72void pw_properties_clear(struct pw_properties *properties);
73
74void
75 pw_properties_free(struct pw_properties *properties);
76
77int
78 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
79
80int
81 pw_properties_setf(struct pw_properties *properties,
82 const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
83int
84 pw_properties_setva(struct pw_properties *properties,
85 const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
86const char *
87 pw_properties_get(const struct pw_properties *properties, const char *key);
88
89int
90 pw_properties_fetch_uint32(const struct pw_properties *properties, const char *key, uint32_t *value);
91
92int
93 pw_properties_fetch_int32(const struct pw_properties *properties, const char *key, int32_t *value);
94
95int
96 pw_properties_fetch_uint64(const struct pw_properties *properties, const char *key, uint64_t *value);
97
98int
99 pw_properties_fetch_int64(const struct pw_properties *properties, const char *key, int64_t *value);
100
101int
102 pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value);
103
104static inline uint32_t
105 pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
106{
107 uint32_t val = deflt;
108 pw_properties_fetch_uint32(properties, key, &val);
109 return val;
110}
111
112static inline int32_t
113 pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
114{
115 int32_t val = deflt;
116 pw_properties_fetch_int32(properties, key, &val);
117 return val;
118}
119
120static inline uint64_t
121 pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
122{
123 uint64_t val = deflt;
124 pw_properties_fetch_uint64(properties, key, &val);
125 return val;
126}
127
128static inline int64_t
129 pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
130{
131 int64_t val = deflt;
132 pw_properties_fetch_int64(properties, key, &val);
133 return val;
134}
135
136
137static inline bool
138 pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
139{
140 bool val = deflt;
141 pw_properties_fetch_bool(properties, key, &val);
142 return val;
143}
144
145const char *
146 pw_properties_iterate(const struct pw_properties *properties, void **state);
147
148#define PW_PROPERTIES_FLAG_NL (1<<0)
149#define PW_PROPERTIES_FLAG_RECURSE (1<<1)
150#define PW_PROPERTIES_FLAG_ENCLOSE (1<<2)
151#define PW_PROPERTIES_FLAG_ARRAY (1<<3)
152#define PW_PROPERTIES_FLAG_COLORS (1<<4)
153 int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
154
155 static inline bool pw_properties_parse_bool(const char *value) {
156 return spa_atob(value);
157}
158
159 static inline int pw_properties_parse_int(const char *value) {
160 int v;
161 return spa_atoi32(value, &v, 0) ? v: 0;
162}
163
164 static inline int64_t pw_properties_parse_int64(const char *value) {
165 int64_t v;
166 return spa_atoi64(value, &v, 0) ? v : 0;
167}
168
169static inline uint64_t pw_properties_parse_uint64(const char *value) {
170 uint64_t v;
171 return spa_atou64(value, &v, 0) ? v : 0;
172}
173
174static inline float pw_properties_parse_float(const char *value) {
175 float v;
176 return spa_atof(value, &v) ? v : 0.0f;
177}
178
179static inline double pw_properties_parse_double(const char *value) {
180 double v;
181 return spa_atod(value, &v) ? v : 0.0;
182}
183
188SPA_DEFINE_AUTOPTR_CLEANUP(pw_properties, struct pw_properties, {
189 spa_clear_ptr(*thing, pw_properties_free);
190})
191
192#ifdef __cplusplus
193}
194#endif
195
196#endif /* PIPEWIRE_PROPERTIES_H */
pw_properties_free
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition properties.c:562
pw_properties_new
struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition properties.c:96
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:304
pw_properties_get_bool
static bool pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
Definition properties.h:142
pw_properties_parse_int64
static int64_t pw_properties_parse_int64(const char *value)
Definition properties.h:173
pw_properties_parse_int
static int pw_properties_parse_int(const char *value)
Definition properties.h:168
pw_properties_add
int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict)
Add properties.
Definition properties.c:506
pw_properties_parse_bool
static bool pw_properties_parse_bool(const char *value)
Definition properties.h:164
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:765
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:437
pw_properties_update
int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition properties.c:481
pw_properties_iterate
const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition properties.c:789
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:131
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:711
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:620
pw_properties_parse_float
static float pw_properties_parse_float(const char *value)
Definition properties.h:183
pw_properties_get
const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition properties.c:641
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:349
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:125
pw_properties_set
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition properties.c:589
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:133
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:117
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:408
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:738
pw_properties_parse_uint64
static uint64_t pw_properties_parse_uint64(const char *value)
Definition properties.h:178
pw_properties_clear
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition properties.c:460
pw_properties_parse_double
static double pw_properties_parse_double(const char *value)
Definition properties.h:188
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:657
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:330
pw_properties_setva
int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args)
Definition properties.c:595
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:536
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:109
pw_properties_copy
struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition properties.c:395
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:370
pw_properties_serialize_dict
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition properties.c:920
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:684
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:337
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:181
spa_atob
static bool spa_atob(const char *str)
Convert str to a boolean.
Definition string.h:204
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:156
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:100
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:287
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:295
SPA_SENTINEL
#define SPA_SENTINEL
Definition defs.h:305
string.h
spa/utils/string.h
pw_properties
Definition properties.h:34
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition properties.h:35
pw_properties::flags
uint32_t flags
extra flags
Definition properties.h:36
spa_dict
Definition dict.h:39
spa_error_location
Definition defs.h:414
dict.h
spa/utils/dict.h