PipeWire  0.3.66
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
9 extern "C" {
10 #endif
11 
12 #include <stdarg.h>
13 
14 #include <spa/utils/dict.h>
15 #include <spa/utils/string.h>
16 
29 struct pw_properties {
30  struct spa_dict dict;
31  uint32_t flags;
32 };
33 
34 struct pw_properties *
35 pw_properties_new(const char *key, ...) SPA_SENTINEL;
36 
37 struct pw_properties *
38 pw_properties_new_dict(const struct spa_dict *dict);
39 
40 struct pw_properties *
41 pw_properties_new_string(const char *args);
42 
43 struct pw_properties *
44 pw_properties_copy(const struct pw_properties *properties);
45 
47  const struct spa_dict *dict, const char * const keys[]);
49  const struct spa_dict *dict, const char * const ignore[]);
50 
51 /* Update props with all key/value pairs from dict */
52 int pw_properties_update(struct pw_properties *props,
53  const struct spa_dict *dict);
54 /* Update props with all key/value pairs from str */
56  const char *str, size_t size);
57 
58 int pw_properties_add(struct pw_properties *oldprops,
59  const struct spa_dict *dict);
60 int pw_properties_add_keys(struct pw_properties *oldprops,
61  const struct spa_dict *dict, const char * const keys[]);
62 
63 void pw_properties_clear(struct pw_properties *properties);
64 
65 void
66 pw_properties_free(struct pw_properties *properties);
67 
68 int
69 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
70 
71 int
72 pw_properties_setf(struct pw_properties *properties,
73  const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
74 int
75 pw_properties_setva(struct pw_properties *properties,
76  const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
77 const char *
78 pw_properties_get(const struct pw_properties *properties, const char *key);
79 
80 int
81 pw_properties_fetch_uint32(const struct pw_properties *properties, const char *key, uint32_t *value);
82 
83 int
84 pw_properties_fetch_int32(const struct pw_properties *properties, const char *key, int32_t *value);
85 
86 int
87 pw_properties_fetch_uint64(const struct pw_properties *properties, const char *key, uint64_t *value);
88 
89 int
90 pw_properties_fetch_int64(const struct pw_properties *properties, const char *key, int64_t *value);
91 
92 int
93 pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value);
94 
95 static inline uint32_t
96 pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
97 {
98  uint32_t val = deflt;
99  pw_properties_fetch_uint32(properties, key, &val);
100  return val;
101 }
102 
103 static inline int32_t
104 pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
105 {
106  int32_t val = deflt;
107  pw_properties_fetch_int32(properties, key, &val);
108  return val;
109 }
110 
111 static inline uint64_t
112 pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
113 {
114  uint64_t val = deflt;
115  pw_properties_fetch_uint64(properties, key, &val);
116  return val;
117 }
118 
119 static inline int64_t
120 pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
121 {
122  int64_t val = deflt;
123  pw_properties_fetch_int64(properties, key, &val);
124  return val;
125 }
126 
127 
128 static inline bool
129 pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
130 {
131  bool val = deflt;
132  pw_properties_fetch_bool(properties, key, &val);
133  return val;
134 }
135 
136 const char *
137 pw_properties_iterate(const struct pw_properties *properties, void **state);
138 
139 #define PW_PROPERTIES_FLAG_NL (1<<0)
140 int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
141 
142 static inline bool pw_properties_parse_bool(const char *value) {
143  return spa_atob(value);
144 }
145 
146 static inline int pw_properties_parse_int(const char *value) {
147  int v;
148  return spa_atoi32(value, &v, 0) ? v: 0;
149 }
150 
151 static inline int64_t pw_properties_parse_int64(const char *value) {
152  int64_t v;
153  return spa_atoi64(value, &v, 0) ? v : 0;
154 }
155 
156 static inline uint64_t pw_properties_parse_uint64(const char *value) {
157  uint64_t v;
158  return spa_atou64(value, &v, 0) ? v : 0;
159 }
160 
161 static inline float pw_properties_parse_float(const char *value) {
162  float v;
163  return spa_atof(value, &v) ? v : 0.0f;
164 }
165 
166 static inline double pw_properties_parse_double(const char *value) {
167  double v;
168  return spa_atod(value, &v) ? v : 0.0;
169 }
170 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* PIPEWIRE_PROPERTIES_H */
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:348
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:138
static bool pw_properties_get_bool(const struct pw_properties *properties, const char *key, bool deflt)
Definition: properties.h:133
static int64_t pw_properties_parse_int64(const char *value)
Definition: properties.h:156
static int pw_properties_parse_int(const char *value)
Definition: properties.h:151
int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict)
Add properties.
Definition: properties.c:303
static bool pw_properties_parse_bool(const char *value)
Definition: properties.h:147
int pw_properties_fetch_bool(const struct pw_properties *properties, const char *key, bool *value)
Fetch a property as boolean value.
Definition: properties.c:601
int pw_properties_update_ignore(struct pw_properties *props, const struct spa_dict *dict, const char *const ignore[])
Definition: properties.c:243
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:282
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:547
static float pw_properties_parse_float(const char *value)
Definition: properties.h:166
struct pw_properties * pw_properties_new(const char *key,...) 1
Make a new properties object.
Definition: properties.c:82
static uint64_t pw_properties_get_uint64(const struct pw_properties *properties, const char *key, uint64_t deflt)
Definition: properties.h:116
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition: properties.c:419
struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition: properties.c:206
struct pw_properties * pw_properties_new_string(const char *args)
Make a new properties object from the given str.
Definition: properties.c:181
static int64_t pw_properties_get_int64(const struct pw_properties *properties, const char *key, int64_t deflt)
Definition: properties.h:124
static int32_t pw_properties_get_int32(const struct pw_properties *properties, const char *key, int32_t deflt)
Definition: properties.h:108
struct pw_properties * pw_properties_new_dict(const struct spa_dict *dict)
Make a new properties object from the given dictionary.
Definition: properties.c:110
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:219
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:574
static uint64_t pw_properties_parse_uint64(const char *value)
Definition: properties.h:161
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:261
const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:625
static double pw_properties_parse_double(const char *value)
Definition: properties.h:171
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:493
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:327
static uint32_t pw_properties_get_uint32(const struct pw_properties *properties, const char *key, uint32_t deflt)
Definition: properties.h:100
int int const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:471
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition: properties.c:682
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:520
static bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:337
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
static bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:204
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
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
static bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:287
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:273
#define SPA_SENTINEL
Definition: defs.h:283
spa/utils/string.h
Definition: properties.h:33
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34
uint32_t flags
extra flags
Definition: properties.h:35
Definition: utils/dict.h:39
spa/utils/dict.h