PipeWire 0.3.36
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
50 struct spa_dict dict;
51 uint32_t flags;
52};
53
54struct pw_properties *
55pw_properties_new(const char *key, ...) SPA_SENTINEL;
56
57struct pw_properties *
59
60struct pw_properties *
61pw_properties_new_string(const char *args);
62
63struct pw_properties *
64pw_properties_copy(const struct pw_properties *properties);
65
67 const struct spa_dict *dict, const char * const keys[]);
69 const struct spa_dict *dict, const char * const ignore[]);
70
71/* Update props with all key/value pairs from dict */
73 const struct spa_dict *dict);
74/* Update props with all key/value pairs from str */
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
86pw_properties_free(struct pw_properties *properties);
87
88int
89pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
90
91int
93 const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
94int
96 const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
97const char *
98pw_properties_get(const struct pw_properties *properties, const char *key);
99
100const char *
101pw_properties_iterate(const struct pw_properties *properties, void **state);
102
103#define PW_PROPERTIES_FLAG_NL (1<<0)
104int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
105
106static inline bool pw_properties_parse_bool(const char *value) {
107 return spa_atob(value);
108}
109
110static inline int pw_properties_parse_int(const char *value) {
111 int v;
112 return spa_atoi32(value, &v, 0) ? v: 0;
113}
114
115static inline int64_t pw_properties_parse_int64(const char *value) {
116 int64_t v;
117 return spa_atoi64(value, &v, 0) ? v : 0;
118}
119
120static inline uint64_t pw_properties_parse_uint64(const char *value) {
121 uint64_t v;
122 return spa_atou64(value, &v, 0) ? v : 0;
123}
124
125static inline float pw_properties_parse_float(const char *value) {
126 float v;
127 return spa_atof(value, &v) ? v : 0.0f;
128}
129
130static inline double pw_properties_parse_double(const char *value) {
131 double v;
132 return spa_atod(value, &v) ? v : 0.0;
133}
134
139#ifdef __cplusplus
140}
141#endif
142
143#endif /* PIPEWIRE_PROPERTIES_H */
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:364
struct pw_properties * pw_properties_new(const char *key,...) 1
Make a new properties object.
Definition: properties.c:98
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:154
int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict)
Add properties.
Definition: properties.c:319
int int const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:487
int pw_properties_update_ignore(struct pw_properties *props, const struct spa_dict *dict, const char *const ignore[])
Definition: properties.c:259
int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...) 1(3
int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition: properties.c:298
const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:510
struct pw_properties * pw_properties_new_dict(const struct spa_dict *dict)
Make a new properties object from the given dictionary.
Definition: properties.c:126
struct pw_properties * pw_properties_new_string(const char *args)
Make a new properties object from the given str.
Definition: properties.c:197
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition: properties.c:435
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:235
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:277
int int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args) 1(3
int pw_properties_add_keys(struct pw_properties *oldprops, const struct spa_dict *dict, const char *const keys[])
Add keys.
Definition: properties.c:343
struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition: properties.c:222
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition: properties.c:567
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:109
bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:293
bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:269
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:206
bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:213
#define SPA_SENTINEL
Definition: defs.h:211
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:190
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:165
const char * props
Definition: media-session.c:2383
Definition: properties.h:49
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
uint32_t flags
extra flags
Definition: properties.h:51
Definition: utils/dict.h:48