PipeWire  1.4.11
type.h
Go to the documentation of this file.
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_TYPE_H
6 #define SPA_TYPE_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <spa/utils/defs.h>
13 #include <spa/utils/string.h>
14 
15 #ifndef SPA_API_TYPE
16  #ifdef SPA_API_IMPL
17  #define SPA_API_TYPE SPA_API_IMPL
18  #else
19  #define SPA_API_TYPE static inline
20  #endif
21 #endif
22 
32 enum {
33  /* Basic types */
34  SPA_TYPE_START = 0x00000,
57  /* Pointers */
64  /* Events */
70  /* Commands */
71  SPA_TYPE_COMMAND_START = 0x30000,
76  /* Objects */
77  SPA_TYPE_OBJECT_START = 0x40000,
93  /* vendor extensions */
95 
96  SPA_TYPE_VENDOR_Other = 0x7f000000,
97 };
98 
99 #define SPA_TYPE_INFO_BASE "Spa:"
100 
101 #define SPA_TYPE_INFO_Flags SPA_TYPE_INFO_BASE "Flags"
102 #define SPA_TYPE_INFO_FLAGS_BASE SPA_TYPE_INFO_Flags ":"
104 #define SPA_TYPE_INFO_Enum SPA_TYPE_INFO_BASE "Enum"
105 #define SPA_TYPE_INFO_ENUM_BASE SPA_TYPE_INFO_Enum ":"
106 
107 #define SPA_TYPE_INFO_Pod SPA_TYPE_INFO_BASE "Pod"
108 #define SPA_TYPE_INFO_POD_BASE SPA_TYPE_INFO_Pod ":"
109 
110 #define SPA_TYPE_INFO_Struct SPA_TYPE_INFO_POD_BASE "Struct"
111 #define SPA_TYPE_INFO_STRUCT_BASE SPA_TYPE_INFO_Struct ":"
113 #define SPA_TYPE_INFO_Object SPA_TYPE_INFO_POD_BASE "Object"
114 #define SPA_TYPE_INFO_OBJECT_BASE SPA_TYPE_INFO_Object ":"
116 #define SPA_TYPE_INFO_Pointer SPA_TYPE_INFO_BASE "Pointer"
117 #define SPA_TYPE_INFO_POINTER_BASE SPA_TYPE_INFO_Pointer ":"
118 
119 #define SPA_TYPE_INFO_Interface SPA_TYPE_INFO_POINTER_BASE "Interface"
120 #define SPA_TYPE_INFO_INTERFACE_BASE SPA_TYPE_INFO_Interface ":"
121 
122 #define SPA_TYPE_INFO_Event SPA_TYPE_INFO_OBJECT_BASE "Event"
123 #define SPA_TYPE_INFO_EVENT_BASE SPA_TYPE_INFO_Event ":"
124 
125 #define SPA_TYPE_INFO_Command SPA_TYPE_INFO_OBJECT_BASE "Command"
126 #define SPA_TYPE_INFO_COMMAND_BASE SPA_TYPE_INFO_Command ":"
128 struct spa_type_info {
129  uint32_t type;
130  uint32_t parent;
131  const char *name;
132  const struct spa_type_info *values;
133 };
134 
135 SPA_API_TYPE bool spa_type_is_a(const char *type, const char *parent)
136 {
137  return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0;
138 }
139 
140 SPA_API_TYPE const char *spa_type_short_name(const char *name)
141 {
142  const char *h;
143  if ((h = strrchr(name, ':')) != NULL)
144  name = h + 1;
145  return name;
146 }
148 SPA_API_TYPE uint32_t spa_type_from_short_name(const char *name,
149  const struct spa_type_info *info, uint32_t unknown)
150 {
151  int i;
152  for (i = 0; info[i].name; i++) {
153  if (spa_streq(name, spa_type_short_name(info[i].name)))
154  return info[i].type;
155  }
156  return unknown;
157 }
158 SPA_API_TYPE const char * spa_type_to_name(uint32_t type,
159  const struct spa_type_info *info, const char *unknown)
160 {
161  int i;
162  for (i = 0; info[i].name; i++) {
163  if (info[i].type == type)
164  return info[i].name;
165  }
166  return unknown;
167 }
168 
169 SPA_API_TYPE const char * spa_type_to_short_name(uint32_t type,
170  const struct spa_type_info *info, const char *unknown)
171 {
172  const char *n = spa_type_to_name(type, info, unknown);
173  return n ? spa_type_short_name(n) : NULL;
174 }
175 
180 #ifdef __cplusplus
181 } /* extern "C" */
182 #endif
183 
184 #endif /* SPA_TYPE_H */
Definition: type.h:84
uint32_t type
Definition: type.h:155
Definition: type.h:78
Definition: type.h:41
not part of ABI
Definition: type.h:81
Definition: type.h:58
Definition: type.h:67
spa/utils/string.h
Definition: type.h:52
Definition: type.h:80
Definition: type.h:95
SPA_API_TYPE const char * spa_type_to_name(uint32_t type, const struct spa_type_info *info, const char *unknown)
Definition: type.h:184
Definition: type.h:50
Definition: type.h:57
SPA_API_TYPE uint32_t spa_type_from_short_name(const char *name, const struct spa_type_info *info, uint32_t unknown)
Definition: type.h:174
SPA_API_TYPE const char * spa_type_to_short_name(uint32_t type, const struct spa_type_info *info, const char *unknown)
Definition: type.h:195
Definition: type.h:49
Definition: type.h:74
SPA_API_TYPE const char * spa_type_short_name(const char *name)
Definition: type.h:166
spa/utils/defs.h
Definition: type.h:90
not part of ABI
Definition: type.h:98
Definition: type.h:154
Definition: type.h:101
Definition: type.h:53
not part of ABI
Definition: type.h:75
Definition: type.h:94
Definition: type.h:93
Definition: type.h:54
Definition: type.h:43
Definition: type.h:86
not part of ABI
Definition: type.h:62
not part of ABI
Definition: type.h:69
Definition: type.h:88
uint32_t parent
Definition: type.h:156
Definition: type.h:47
Definition: type.h:66
Definition: type.h:68
Definition: type.h:48
Definition: type.h:87
SPA_API_TYPE bool spa_type_is_a(const char *type, const char *parent)
Definition: type.h:161
Definition: type.h:89
Definition: type.h:61
Definition: type.h:44
#define SPA_API_TYPE
Definition: type.h:26
Definition: type.h:56
Definition: type.h:103
Definition: type.h:45
Definition: type.h:79
Definition: type.h:65
Definition: type.h:85
Definition: type.h:91
const struct spa_type_info * values
Definition: type.h:158
SPA_API_STRING bool spa_streq(const char *s1, const char *s2)
Definition: string.h:51
Definition: type.h:92
Definition: type.h:55
Definition: type.h:73
Definition: type.h:60
Definition: type.h:97
Definition: type.h:46
Definition: type.h:42
Definition: type.h:59
Definition: type.h:72
Definition: type.h:51