PipeWire  0.3.29
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
29 extern "C" {
30 #endif
31 
32 #include <stdarg.h>
33 
34 #include <spa/utils/dict.h>
35 #include <spa/utils/string.h>
36 
49 struct 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 
57 struct pw_properties *
58 pw_properties_new_dict(const struct spa_dict *dict);
59 
60 struct pw_properties *
61 pw_properties_new_string(const char *args);
62 
63 struct pw_properties *
64 pw_properties_copy(const struct pw_properties *properties);
65 
67  const struct spa_dict *dict, const char *keys[]);
69  const struct spa_dict *dict, const char *ignore[]);
70 
71 int pw_properties_update(struct pw_properties *oldprops,
72  const struct spa_dict *dict);
74  const char *str, size_t size);
75 
76 int pw_properties_add(struct pw_properties *oldprops,
77  const struct spa_dict *dict);
78 int pw_properties_add_keys(struct pw_properties *oldprops,
79  const struct spa_dict *dict, const char *keys[]);
80 
81 void pw_properties_clear(struct pw_properties *properties);
82 
83 void
84 pw_properties_free(struct pw_properties *properties);
85 
86 int
87 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
88 
89 int
90 pw_properties_setf(struct pw_properties *properties,
91  const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
92 int
93 pw_properties_setva(struct pw_properties *properties,
94  const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
95 const char *
96 pw_properties_get(const struct pw_properties *properties, const char *key);
97 
98 const char *
99 pw_properties_iterate(const struct pw_properties *properties, void **state);
100 
101 int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
102 
103 static inline bool pw_properties_parse_bool(const char *value) {
104  return spa_atob(value);
105 }
106 
107 static inline int pw_properties_parse_int(const char *value) {
108  int v;
109  return spa_atoi32(value, &v, 0) ? v: 0;
110 }
111 
112 static inline int64_t pw_properties_parse_int64(const char *value) {
113  int64_t v;
114  return spa_atoi64(value, &v, 0) ? v : 0;
115 }
116 
117 static inline uint64_t pw_properties_parse_uint64(const char *value) {
118  uint64_t v;
119  return spa_atou64(value, &v, 0) ? v : 0;
120 }
121 
122 static inline float pw_properties_parse_float(const char *value) {
123  float v;
124  return spa_atof(value, &v) ? v : 0.0f;
125 }
126 
127 static inline double pw_properties_parse_double(const char *value) {
128  double v;
129  return spa_atod(value, &v) ? v : 0.0;
130 }
131 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* PIPEWIRE_PROPERTIES_H */
SPA_EXPORT struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition: properties.c:100
int int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3
Definition: properties.h:49
#define SPA_SENTINEL
Definition: defs.h:207
int pw_properties_update_ignore(struct pw_properties *props, const struct spa_dict *dict, const char *ignore[])
Definition: properties.c:263
bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:188
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
SPA_EXPORT struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition: properties.c:224
SPA_EXPORT const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:507
Definition: utils/dict.h:48
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:203
SPA_EXPORT int pw_properties_update_keys(struct pw_properties *props, const struct spa_dict *dict, const char *keys[])
Copy multiple keys from one property to another.
Definition: properties.c:239
SPA_EXPORT int pw_properties_add(struct pw_properties *props, const struct spa_dict *dict)
Add properties.
Definition: properties.c:329
SPA_EXPORT int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...)
Set a property value by format.
Definition: properties.c:484
bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:176
int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition: properties.c:589
SPA_EXPORT int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition: properties.c:451
SPA_EXPORT 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
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:72
SPA_EXPORT int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition: properties.c:306
SPA_EXPORT const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:532
int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size)
Definition: properties.c:150
bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:212
SPA_EXPORT void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:378
SPA_EXPORT void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:283
SPA_EXPORT int pw_properties_add_keys(struct pw_properties *props, const struct spa_dict *dict, const char *keys[])
Add keys.
Definition: properties.c:355
SPA_EXPORT struct pw_properties * pw_properties_new_string(const char *object)
Make a new properties object from the given str.
Definition: properties.c:197
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:128
uint32_t flags
extra flags
Definition: properties.h:51
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:153
static uint32_t int int const char va_list args
Definition: core.h:330