|
|
@@ -3,23 +3,116 @@
|
|
3
|
3
|
|
|
4
|
4
|
/** @file
|
|
5
|
5
|
*
|
|
6
|
|
- * Object communication interfaces
|
|
|
6
|
+ * Object interfaces
|
|
7
|
7
|
*
|
|
8
|
8
|
*/
|
|
9
|
9
|
|
|
10
|
10
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
11
|
11
|
|
|
|
12
|
+#include <stddef.h>
|
|
12
|
13
|
#include <ipxe/refcnt.h>
|
|
13
|
14
|
|
|
14
|
|
-/** An object communication interface */
|
|
|
15
|
+/** An object interface operation */
|
|
|
16
|
+struct interface_operation {
|
|
|
17
|
+ /** Operation type */
|
|
|
18
|
+ void *type;
|
|
|
19
|
+ /** Implementing method */
|
|
|
20
|
+ void *func;
|
|
|
21
|
+};
|
|
|
22
|
+
|
|
|
23
|
+/**
|
|
|
24
|
+ * Define an object interface operation
|
|
|
25
|
+ *
|
|
|
26
|
+ * @v op_type Operation type
|
|
|
27
|
+ * @v object_type Implementing method's expected object type
|
|
|
28
|
+ * @v op_func Implementing method
|
|
|
29
|
+ * @ret op Object interface operation
|
|
|
30
|
+ */
|
|
|
31
|
+#define INTF_OP( op_type, object_type, op_func ) { \
|
|
|
32
|
+ .type = op_type, \
|
|
|
33
|
+ .func = ( ( ( ( typeof ( op_func ) * ) NULL ) == \
|
|
|
34
|
+ ( ( op_type ## _TYPE ( object_type ) * ) NULL ) ) \
|
|
|
35
|
+ ? op_func : op_func ), \
|
|
|
36
|
+ }
|
|
|
37
|
+
|
|
|
38
|
+/** An object interface descriptor */
|
|
|
39
|
+struct interface_descriptor {
|
|
|
40
|
+ /** Offset of interface within containing object */
|
|
|
41
|
+ size_t offset;
|
|
|
42
|
+ /** Number of interface operations */
|
|
|
43
|
+ unsigned int num_op;
|
|
|
44
|
+ /** Object interface operations */
|
|
|
45
|
+ struct interface_operation *op;
|
|
|
46
|
+ /** Offset to pass-through interface, if present */
|
|
|
47
|
+ ssize_t passthru_offset;
|
|
|
48
|
+};
|
|
|
49
|
+
|
|
|
50
|
+#define intf_offset( object_type, intf ) \
|
|
|
51
|
+ ( ( ( ( typeof ( ( ( object_type * ) NULL )->intf ) * ) NULL ) \
|
|
|
52
|
+ == ( ( struct interface * ) NULL ) ) \
|
|
|
53
|
+ ? offsetof ( object_type, intf ) \
|
|
|
54
|
+ : offsetof ( object_type, intf ) )
|
|
|
55
|
+
|
|
|
56
|
+/**
|
|
|
57
|
+ * Define an object interface descriptor
|
|
|
58
|
+ *
|
|
|
59
|
+ * @v object_type Containing object data type
|
|
|
60
|
+ * @v intf Interface name (i.e. field within object data type)
|
|
|
61
|
+ * @v operations Object interface operations array
|
|
|
62
|
+ * @ret desc Object interface descriptor
|
|
|
63
|
+ */
|
|
|
64
|
+#define INTF_DESC( object_type, intf, operations ) { \
|
|
|
65
|
+ .offset = intf_offset ( object_type, intf ), \
|
|
|
66
|
+ .op = operations, \
|
|
|
67
|
+ .num_op = ( sizeof ( operations ) / \
|
|
|
68
|
+ sizeof ( operations[0] ) ), \
|
|
|
69
|
+ .passthru_offset = 0, \
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+/**
|
|
|
73
|
+ * Define an object interface descriptor with pass-through interface
|
|
|
74
|
+ *
|
|
|
75
|
+ * @v object_type Containing object data type
|
|
|
76
|
+ * @v intf Interface name (i.e. field within object data type)
|
|
|
77
|
+ * @v operations Object interface operations array
|
|
|
78
|
+ * @v passthru Pass-through interface name
|
|
|
79
|
+ * @ret desc Object interface descriptor
|
|
|
80
|
+ */
|
|
|
81
|
+#define INTF_DESC_PASSTHRU( object_type, intf, operations, passthru ) { \
|
|
|
82
|
+ .offset = offsetof ( object_type, intf ), \
|
|
|
83
|
+ .op = operations, \
|
|
|
84
|
+ .num_op = ( sizeof ( operations ) / \
|
|
|
85
|
+ sizeof ( operations[0] ) ), \
|
|
|
86
|
+ .passthru_offset = ( intf_offset ( object_type, passthru ) - \
|
|
|
87
|
+ intf_offset ( object_type, intf ) ), \
|
|
|
88
|
+ }
|
|
|
89
|
+
|
|
|
90
|
+/**
|
|
|
91
|
+ * Define an object interface descriptor for a pure-interface object
|
|
|
92
|
+ *
|
|
|
93
|
+ * @v operations Object interface operations array
|
|
|
94
|
+ * @ret desc Object interface descriptor
|
|
|
95
|
+ *
|
|
|
96
|
+ * A pure-interface object is an object that consists solely of a
|
|
|
97
|
+ * single interface.
|
|
|
98
|
+ */
|
|
|
99
|
+#define INTF_DESC_PURE( operations ) { \
|
|
|
100
|
+ .offset = 0, \
|
|
|
101
|
+ .op = operations, \
|
|
|
102
|
+ .num_op = ( sizeof ( operations ) / \
|
|
|
103
|
+ sizeof ( operations[0] ) ), \
|
|
|
104
|
+ .passthru_offset = 0, \
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+/** An object interface */
|
|
15
|
108
|
struct interface {
|
|
16
|
|
- /** Destination interface
|
|
|
109
|
+ /** Destination object interface
|
|
17
|
110
|
*
|
|
18
|
|
- * When messages are sent via this interface, they will be
|
|
19
|
|
- * delivered to the destination interface.
|
|
|
111
|
+ * When the containing object invokes an operation on this
|
|
|
112
|
+ * interface, it will be executed by the destination object.
|
|
20
|
113
|
*
|
|
21
|
114
|
* This pointer may never be NULL. When the interface is
|
|
22
|
|
- * unplugged, it should point to a null interface.
|
|
|
115
|
+ * unplugged, it should point to the null interface.
|
|
23
|
116
|
*/
|
|
24
|
117
|
struct interface *dest;
|
|
25
|
118
|
/** Reference counter
|
|
|
@@ -28,31 +121,99 @@ struct interface {
|
|
28
|
121
|
* object, this field may be NULL.
|
|
29
|
122
|
*/
|
|
30
|
123
|
struct refcnt *refcnt;
|
|
|
124
|
+ /** Interface descriptor */
|
|
|
125
|
+ struct interface_descriptor *desc;
|
|
31
|
126
|
};
|
|
32
|
127
|
|
|
|
128
|
+extern void intf_plug ( struct interface *intf, struct interface *dest );
|
|
|
129
|
+extern void intf_plug_plug ( struct interface *a, struct interface *b );
|
|
|
130
|
+extern void intf_unplug ( struct interface *intf );
|
|
|
131
|
+extern void intf_nullify ( struct interface *intf );
|
|
|
132
|
+extern struct interface * intf_get ( struct interface *intf );
|
|
|
133
|
+extern void intf_put ( struct interface *intf );
|
|
|
134
|
+extern void * __attribute__ (( pure )) intf_object ( struct interface *intf );
|
|
|
135
|
+extern void * intf_get_dest_op_untyped ( struct interface *intf, void *type,
|
|
|
136
|
+ struct interface **dest );
|
|
|
137
|
+
|
|
|
138
|
+extern void intf_close ( struct interface *intf, int rc );
|
|
|
139
|
+#define intf_close_TYPE( object_type ) \
|
|
|
140
|
+ typeof ( void ( object_type, int rc ) )
|
|
|
141
|
+
|
|
|
142
|
+extern void intf_shutdown ( struct interface *intf, int rc );
|
|
|
143
|
+extern void intf_restart ( struct interface *intf, int rc );
|
|
|
144
|
+
|
|
|
145
|
+extern struct interface_descriptor null_intf_desc;
|
|
|
146
|
+extern struct interface null_intf;
|
|
|
147
|
+
|
|
33
|
148
|
/**
|
|
34
|
|
- * Increment reference count on an interface
|
|
|
149
|
+ * Initialise an object interface
|
|
35
|
150
|
*
|
|
36
|
|
- * @v intf Interface
|
|
37
|
|
- * @ret intf Interface
|
|
|
151
|
+ * @v intf Object interface
|
|
|
152
|
+ * @v desc Object interface descriptor
|
|
|
153
|
+ * @v refcnt Containing object reference counter, or NULL
|
|
38
|
154
|
*/
|
|
39
|
|
-static inline __attribute__ (( always_inline )) struct interface *
|
|
40
|
|
-intf_get ( struct interface *intf ) {
|
|
41
|
|
- ref_get ( intf->refcnt );
|
|
42
|
|
- return intf;
|
|
|
155
|
+static inline void intf_init ( struct interface *intf,
|
|
|
156
|
+ struct interface_descriptor *desc,
|
|
|
157
|
+ struct refcnt *refcnt ) {
|
|
|
158
|
+ intf->dest = &null_intf;
|
|
|
159
|
+ intf->refcnt = refcnt;
|
|
|
160
|
+ intf->desc = desc;
|
|
43
|
161
|
}
|
|
44
|
162
|
|
|
45
|
163
|
/**
|
|
46
|
|
- * Decrement reference count on an interface
|
|
|
164
|
+ * Initialise a static object interface
|
|
47
|
165
|
*
|
|
48
|
|
- * @v intf Interface
|
|
|
166
|
+ * @v descriptor Object interface descriptor
|
|
49
|
167
|
*/
|
|
50
|
|
-static inline __attribute__ (( always_inline )) void
|
|
51
|
|
-intf_put ( struct interface *intf ) {
|
|
52
|
|
- ref_put ( intf->refcnt );
|
|
53
|
|
-}
|
|
|
168
|
+#define INTF_INIT( descriptor ) { \
|
|
|
169
|
+ .dest = &null_intf, \
|
|
|
170
|
+ .refcnt = NULL, \
|
|
|
171
|
+ .desc = &(descriptor), \
|
|
|
172
|
+ }
|
|
|
173
|
+
|
|
|
174
|
+/**
|
|
|
175
|
+ * Get object interface destination and operation method
|
|
|
176
|
+ *
|
|
|
177
|
+ * @v intf Object interface
|
|
|
178
|
+ * @v type Operation type
|
|
|
179
|
+ * @ret dest Destination interface
|
|
|
180
|
+ * @ret func Implementing method, or NULL
|
|
|
181
|
+ */
|
|
|
182
|
+#define intf_get_dest_op( intf, type, dest ) \
|
|
|
183
|
+ ( ( type ## _TYPE ( void * ) * ) \
|
|
|
184
|
+ intf_get_dest_op_untyped ( intf, type, dest ) )
|
|
|
185
|
+
|
|
|
186
|
+/**
|
|
|
187
|
+ * Find debugging colourisation for an object interface
|
|
|
188
|
+ *
|
|
|
189
|
+ * @v intf Object interface
|
|
|
190
|
+ * @ret col Debugging colourisation
|
|
|
191
|
+ *
|
|
|
192
|
+ * Use as the first argument to DBGC() or equivalent macro.
|
|
|
193
|
+ */
|
|
|
194
|
+#define INTF_COL( intf ) intf_object ( intf )
|
|
|
195
|
+
|
|
|
196
|
+/** printf() format string for INTF_DBG() */
|
|
|
197
|
+#define INTF_FMT "%p+%zx"
|
|
54
|
198
|
|
|
55
|
|
-extern void plug ( struct interface *intf, struct interface *dest );
|
|
56
|
|
-extern void plug_plug ( struct interface *a, struct interface *b );
|
|
|
199
|
+/**
|
|
|
200
|
+ * printf() arguments for representing an object interface
|
|
|
201
|
+ *
|
|
|
202
|
+ * @v intf Object interface
|
|
|
203
|
+ * @ret args printf() argument list corresponding to INTF_FMT
|
|
|
204
|
+ */
|
|
|
205
|
+#define INTF_DBG( intf ) intf_object ( intf ), (intf)->desc->offset
|
|
|
206
|
+
|
|
|
207
|
+/** printf() format string for INTF_INTF_DBG() */
|
|
|
208
|
+#define INTF_INTF_FMT INTF_FMT "->" INTF_FMT
|
|
|
209
|
+
|
|
|
210
|
+/**
|
|
|
211
|
+ * printf() arguments for representing an object interface pair
|
|
|
212
|
+ *
|
|
|
213
|
+ * @v intf Object interface
|
|
|
214
|
+ * @v dest Destination object interface
|
|
|
215
|
+ * @ret args printf() argument list corresponding to INTF_INTF_FMT
|
|
|
216
|
+ */
|
|
|
217
|
+#define INTF_INTF_DBG( intf, dest ) INTF_DBG ( intf ), INTF_DBG ( dest )
|
|
57
|
218
|
|
|
58
|
219
|
#endif /* _IPXE_INTERFACE_H */
|