PipeWire  0.2.7
properties.h
Go to the documentation of this file.
1 /* PipeWire
2  * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef __PIPEWIRE_PROPERTIES_H__
21 #define __PIPEWIRE_PROPERTIES_H__
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <spa/utils/dict.h>
28 
38 struct pw_properties {
39  struct spa_dict dict;
40 };
41 
42 struct pw_properties *
43 pw_properties_new(const char *key, ...) SPA_SENTINEL;
44 
45 struct pw_properties *
46 pw_properties_new_dict(const struct spa_dict *dict);
47 
48 struct pw_properties *
49 pw_properties_new_string(const char *args);
50 
51 struct pw_properties *
52 pw_properties_copy(const struct pw_properties *properties);
53 
54 struct pw_properties *
55 pw_properties_merge(const struct pw_properties *oldprops,
56  struct pw_properties *newprops);
57 
58 void
59 pw_properties_free(struct pw_properties *properties);
60 
61 int
62 pw_properties_set(struct pw_properties *properties, const char *key, const char *value);
63 
64 int
65 pw_properties_setf(struct pw_properties *properties,
66  const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4);
67 const char *
68 pw_properties_get(const struct pw_properties *properties, const char *key);
69 
70 const char *
71 pw_properties_iterate(const struct pw_properties *properties, void **state);
72 
73 static inline bool pw_properties_parse_bool(const char *value) {
74  return (strcmp(value, "true") == 0 || atoi(value) == 1);
75 }
76 
77 static inline int pw_properties_parse_int(const char *value) {
78  return strtol(value, NULL, 0);
79 }
80 
81 static inline int64_t pw_properties_parse_int64(const char *value) {
82  return strtoll(value, NULL, 0);
83 }
84 
85 static inline uint64_t pw_properties_parse_uint64(const char *value) {
86  return strtoull(value, NULL, 0);
87 }
88 
89 static inline float pw_properties_parse_float(const char *value) {
90  return strtof(value, NULL);
91 }
92 
93 static inline double pw_properties_parse_double(const char *value) {
94  return strtod(value, NULL);
95 }
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* __PIPEWIRE_PROPERTIES_H__ */
pw_properties::pw_properties_iterate
SPA_EXPORT const char * pw_properties_iterate(const struct pw_properties *properties, void **state)
Iterate property values.
Definition: properties.c:386
pw_properties::pw_properties_merge
SPA_EXPORT struct pw_properties * pw_properties_merge(const struct pw_properties *oldprops, struct pw_properties *newprops)
Merge properties into one.
Definition: properties.c:211
impl
Definition: control.c:25
pw_array_for_each
#define pw_array_for_each(pos, array)
Definition: array.h:56
pw_properties::pw_properties_new_string
SPA_EXPORT struct pw_properties * pw_properties_new_string(const char *str)
Make a new properties object from the given str.
Definition: properties.c:149
pw_properties::dict
struct spa_dict dict
Definition: properties.h:39
pw_array
An array object.
Definition: array.h:36
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:338
pw_utils::pw_split_walk
SPA_EXPORT const char * pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state)
Split a string based on delimiters.
Definition: utils.c:40
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:119
pw_array::pw_array_add
static void * pw_array_add(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:98
pw_array::pw_array_get_len
#define pw_array_get_len(a, t)
Get the number of items of type t in array.
Definition: array.h:50
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:183
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:308
pw_properties::pw_properties_get
SPA_EXPORT const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:361
pw_array::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:52
impl::this
struct pw_control this
Definition: control.c:26
pw_properties::pw_properties_new
SPA_EXPORT struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition: properties.c:89
pw_array::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:54
pipewire.h
properties.h
pw_properties
A collection of key/value pairs.
Definition: properties.h:38
pw_properties::pw_properties_free
SPA_EXPORT void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:245
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:315
pw_array::pw_array_init
static void pw_array_init(struct pw_array *arr, size_t extend)
Initialize the array with given extend.
Definition: array.h:62