PipeWire  0.3.30
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 /* Update props with all key/value pairs from dict */
72 int pw_properties_update(struct pw_properties *props,
73  const struct spa_dict *dict);
74 /* Update props with all key/value pairs from str */
76  const char *str, size_t size);
77 
78 int pw_properties_add(struct pw_properties *oldprops,
79  const struct spa_dict *dict);
80 int pw_properties_add_keys(struct pw_properties *oldprops,
81  const struct spa_dict *dict, const char *keys[]);
82 
83 void pw_properties_clear(struct pw_properties *properties);
84 
85 void
86 pw_properties_free(struct pw_properties *properties);
87 
88 int
89 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
90 
91 int
92 pw_properties_setf(struct pw_properties *properties,
93  const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
94 int
95 pw_properties_setva(struct pw_properties *properties,
96  const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3,0);
97 const char *
98 pw_properties_get(const struct pw_properties *properties, const char *key);
99 
100 const char *
101 pw_properties_iterate(const struct pw_properties *properties, void **state);
102 
103 int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags);
104 
105 static inline bool pw_properties_parse_bool(const char *value) {
106  return spa_atob(value);
107 }
108 
109 static inline int pw_properties_parse_int(const char *value) {
110  int v;
111  return spa_atoi32(value, &v, 0) ? v: 0;
112 }
113 
114 static inline int64_t pw_properties_parse_int64(const char *value) {
115  int64_t v;
116  return spa_atoi64(value, &v, 0) ? v : 0;
117 }
118 
119 static inline uint64_t pw_properties_parse_uint64(const char *value) {
120  uint64_t v;
121  return spa_atou64(value, &v, 0) ? v : 0;
122 }
123 
124 static inline float pw_properties_parse_float(const char *value) {
125  float v;
126  return spa_atof(value, &v) ? v : 0.0f;
127 }
128 
129 static inline double pw_properties_parse_double(const char *value) {
130  double v;
131  return spa_atod(value, &v) ? v : 0.0;
132 }
133 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* PIPEWIRE_PROPERTIES_H */
spa_dict::flags
uint32_t flags
Definition: utils/dict.h:50
pw_properties::flags
uint32_t flags
extra flags
Definition: properties.h:51
SPA_FLAG_CLEAR
#define SPA_FLAG_CLEAR(field, flag)
Definition: defs.h:75
spa_dict_item::key
const char * key
Definition: utils/dict.h:42
pw_properties_update_ignore
SPA_EXPORT int pw_properties_update_ignore(struct pw_properties *props, const struct spa_dict *dict, const char *ignore[])
Definition: properties.c:271
va_end
va_end(args)
spa_json_container_len
int spa_json_container_len(struct spa_json *iter, const char *value, int len)
Definition: json.h:198
pw_properties::pw_properties_new_string
SPA_EXPORT struct pw_properties * pw_properties_new_string(const char *object)
Make a new properties object from the given str.
Definition: properties.c:205
pw_array_check_index
#define pw_array_check_index(a, idx, t)
Check if an item with index idx and type t exist in array.
Definition: array.h:66
spa_json_enter_object
int spa_json_enter_object(struct spa_json *iter, struct spa_json *sub)
Definition: json.h:212
string.h
spa_streq
bool spa_streq(const char *s1, const char *s2)
Definition: string.h:50
SPA_EXPORT
#define SPA_EXPORT
Definition: defs.h:207
spa_json_is_bool
bool spa_json_is_bool(const char *val, int len)
Definition: json.h:286
SPA_ROUND_UP_N
#define SPA_ROUND_UP_N(num, align)
Definition: defs.h:221
impl
Definition: control.c:33
pw_array_for_each
#define pw_array_for_each(pos, array)
Definition: array.h:72
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:204
res
static uint32_t int int res
Definition: core.h:329
array.h
pw_array_get_len
#define pw_array_get_len(a, t)
Get the number of items of type t in array.
Definition: array.h:62
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
spa_dict_item
Definition: utils/dict.h:41
SPA_CONTAINER_OF
#define SPA_CONTAINER_OF(p, t, m)
Definition: defs.h:170
spa_json_is_float
bool spa_json_is_float(const char *val, int len)
Definition: json.h:240
pw_array
Definition: array.h:48
spa_json_is_container
int spa_json_is_container(const char *val, int len)
Definition: json.h:193
pw_properties::pw_properties_setf
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:492
spa_atod
bool spa_atod(const char *str, double *val)
Convert str to a double and store the result in val.
Definition: string.h:257
pw_properties_serialize_dict
SPA_EXPORT int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t flags)
Definition: properties.c:597
pw_array_get_unchecked
#define pw_array_get_unchecked(a, idx, t)
Get the item with index idx and type t from array.
Definition: array.h:64
spa_dict_for_each
#define spa_dict_for_each(item, dict)
Definition: utils/dict.h:58
spa_dict::items
const struct spa_dict_item * items
Definition: utils/dict.h:52
spa_json_is_null
bool spa_json_is_null(const char *val, int len)
Definition: json.h:228
utils.h
pw_properties::pw_properties_new_dict
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
SPA_DICT_FLAG_SORTED
#define SPA_DICT_FLAG_SORTED
items are sorted
Definition: utils/dict.h:49
spa_json_init
void spa_json_init(struct spa_json *iter, const char *data, size_t size)
Definition: json.h:59
pw_properties::pw_properties_update
SPA_EXPORT int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition: properties.c:314
spa_atof
bool spa_atof(const char *str, float *val)
Convert str to a float and store the result in val.
Definition: string.h:233
va_start
va_start(args, message)
spa_dict
Definition: utils/dict.h:48
spa_atoi32
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:73
spa_dict_lookup
const char * spa_dict_lookup(const struct spa_dict *dict, const char *key)
Definition: utils/dict.h:99
spa_json_parse_string
int spa_json_parse_string(const char *val, int len, char *result)
Definition: json.h:314
spa_json_get_string
int spa_json_get_string(struct spa_json *iter, char *res, int maxlen)
Definition: json.h:358
pw_properties::pw_properties_get
const SPA_EXPORT char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:515
spa_dict_item::value
const char * value
Definition: utils/dict.h:43
pw_properties::pw_properties_copy
SPA_EXPORT struct pw_properties * pw_properties_copy(const struct pw_properties *properties)
Copy a properties object.
Definition: properties.c:232
pw_properties::pw_properties_set
SPA_EXPORT int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
Set a property value.
Definition: properties.c:459
spa_json_next
int spa_json_next(struct spa_json *iter, const char **value)
Get the next token.
Definition: json.h:72
spa_dict_lookup_item
const struct spa_dict_item * spa_dict_lookup_item(const struct spa_dict *dict, const char *key)
Definition: utils/dict.h:77
pw_properties::pw_properties_iterate
const SPA_EXPORT char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:540
pw_properties::pw_properties_clear
SPA_EXPORT void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:291
pw_properties_update_string
SPA_EXPORT 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:158
SPA_SENTINEL
#define SPA_SENTINEL
Definition: defs.h:208
pw_properties::pw_properties_add
SPA_EXPORT int pw_properties_add(struct pw_properties *props, const struct spa_dict *dict)
Add properties.
Definition: properties.c:337
SPA_INT_TO_PTR
#define SPA_INT_TO_PTR(u)
Definition: defs.h:175
json.h
spa_atoi64
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:129
impl::this
struct pw_control this
Definition: control.c:34
spa_atou64
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:154
pw_properties::pw_properties_new
SPA_EXPORT struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition: properties.c:100
properties.h
spa_dict::n_items
uint32_t n_items
Definition: utils/dict.h:51
SPA_PTR_TO_INT
#define SPA_PTR_TO_INT(p)
Definition: defs.h:174
pw_properties::pw_properties_add_keys
SPA_EXPORT int pw_properties_add_keys(struct pw_properties *props, const struct spa_dict *dict, const char *keys[])
Add keys.
Definition: properties.c:363
spa_atob
bool spa_atob(const char *str)
Convert str to a boolean.
Definition: string.h:177
args
static uint32_t int int const char va_list args
Definition: core.h:330
spa_json
Definition: json.h:49
pw_properties::pw_properties_update_keys
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:247
pw_properties
Definition: properties.h:49
pw_properties::pw_properties_free
SPA_EXPORT void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:386
pw_properties_setva
int int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args) SPA_PRINTF_FUNC(3
pw_properties_setva
SPA_EXPORT int pw_properties_setva(struct pw_properties *properties, const char *key, const char *format, va_list args)
Definition: properties.c:465
dict.h