PipeWire  0.3.61
types.h
Go to the documentation of this file.
1 /* Simple Plugin API
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 SPA_DEBUG_TYPES_H
26 #define SPA_DEBUG_TYPES_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 #include <spa/utils/type-info.h>
38 
39 #include <string.h>
40 
41 static inline const struct spa_type_info *spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
42 {
43  const struct spa_type_info *res;
44 
45  if (info == NULL)
46  info = SPA_TYPE_ROOT;
47 
48  while (info && info->name) {
49  if (info->type == SPA_ID_INVALID) {
50  if (info->values && (res = spa_debug_type_find(info->values, type)))
51  return res;
52  }
53  else if (info->type == type)
54  return info;
55  info++;
56  }
57  return NULL;
58 }
59 
60 static inline const char *spa_debug_type_short_name(const char *name)
61 {
62  const char *h;
63  if ((h = strrchr(name, ':')) != NULL)
64  name = h + 1;
65  return name;
66 }
67 
68 static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
69 {
70  if ((info = spa_debug_type_find(info, type)) == NULL)
71  return NULL;
72  return info->name;
73 }
74 
75 static inline const char *spa_debug_type_find_short_name(const struct spa_type_info *info, uint32_t type)
76 {
77  const char *str;
78  if ((str = spa_debug_type_find_name(info, type)) == NULL)
79  return NULL;
81 }
82 
83 static inline uint32_t spa_debug_type_find_type(const struct spa_type_info *info, const char *name)
84 {
85  if (info == NULL)
86  info = SPA_TYPE_ROOT;
87 
88  while (info && info->name) {
89  uint32_t res;
90  if (strcmp(info->name, name) == 0)
91  return info->type;
92  if (info->values && (res = spa_debug_type_find_type(info->values, name)) != SPA_ID_INVALID)
93  return res;
94  info++;
95  }
96  return SPA_ID_INVALID;
97 }
98 
99 static inline const struct spa_type_info *spa_debug_type_find_short(const struct spa_type_info *info, const char *name)
100 {
101  while (info && info->name) {
102  if (strcmp(spa_debug_type_short_name(info->name), name) == 0)
103  return info;
104  if (strcmp(info->name, name) == 0)
105  return info;
106  if (info->type != 0 && info->type == (uint32_t)atoi(name))
107  return info;
108  info++;
109  }
110  return NULL;
111 }
112 
113 static inline uint32_t spa_debug_type_find_type_short(const struct spa_type_info *info, const char *name)
114 {
115  if ((info = spa_debug_type_find_short(info, name)) == NULL)
116  return SPA_ID_INVALID;
117  return info->type;
118 }
123 #ifdef __cplusplus
124 } /* extern "C" */
125 #endif
126 
127 #endif /* SPA_DEBUG_NODE_H */
static uint32_t spa_debug_type_find_type(const struct spa_type_info *info, const char *name)
Definition: types.h:88
static const char * spa_debug_type_find_short_name(const struct spa_type_info *info, uint32_t type)
Definition: types.h:80
static const struct spa_type_info * spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
Definition: types.h:46
static const char * spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
Definition: types.h:73
static const char * spa_debug_type_short_name(const char *name)
Definition: types.h:65
static uint32_t spa_debug_type_find_type_short(const struct spa_type_info *info, const char *name)
Definition: types.h:118
static const struct spa_type_info * spa_debug_type_find_short(const struct spa_type_info *info, const char *name)
Definition: types.h:104
#define SPA_TYPE_ROOT
Definition: type-info.h:46
#define SPA_ID_INVALID
Definition: defs.h:244
spa/utils/string.h
Definition: type.h:162
uint32_t type
Definition: type.h:163
const struct spa_type_info * values
Definition: type.h:166
spa/utils/type-info.h