PipeWire  0.3.33
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;
80  return spa_debug_type_short_name(str);
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 
103 #ifdef __cplusplus
104 } /* extern "C" */
105 #endif
106 
107 #endif /* SPA_DEBUG_NODE_H */
spa_debug_type_find_short_name
const char * spa_debug_type_find_short_name(const struct spa_type_info *info, uint32_t type)
Definition: types.h:75
spa_type_info::type
uint32_t type
Definition: build-12775836/doc/spa/utils/type.h:138
name
const char * name
Definition: media-session.c:2379
string.h
spa_type_info
Definition: build-12775836/doc/spa/utils/type.h:137
spa_type_info::name
const char * name
Definition: build-12775836/doc/spa/utils/type.h:140
type-info.h
SPA_TYPE_ROOT
#define SPA_TYPE_ROOT
Definition: utils/type-info.h:40
spa_type_info::values
const struct spa_type_info * values
Definition: build-12775836/doc/spa/utils/type.h:141
SPA_ID_INVALID
#define SPA_ID_INVALID
Definition: defs.h:182
spa_debug_type_short_name
const char * spa_debug_type_short_name(const char *name)
Definition: types.h:60
spa_debug_type_find
const struct spa_type_info * spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
Definition: types.h:41
spa_debug_type_find_type
uint32_t spa_debug_type_find_type(const struct spa_type_info *info, const char *name)
Definition: types.h:83
spa_debug_type_find_name
const char * spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
Definition: types.h:68