Bläddra i källkod

[interface] Add intf_poke() helper

Reduce the cost of implementing object methods which convey no
information beyond the fact that the method has been called.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 år sedan
förälder
incheckning
81c80c8ba9
2 ändrade filer med 30 tillägg och 0 borttagningar
  1. 25
    0
      src/core/interface.c
  2. 5
    0
      src/include/ipxe/interface.h

+ 25
- 0
src/core/interface.c Visa fil

@@ -311,3 +311,28 @@ void intf_restart ( struct interface *intf, int rc ) {
311 311
 	 */
312 312
 	intf->desc = desc;
313 313
 }
314
+
315
+/**
316
+ * Poke an object interface
317
+ *
318
+ * @v intf		Object interface
319
+ * @v type		Operation type
320
+ *
321
+ * This is a helper function to implement methods which take no
322
+ * parameters and return nothing.
323
+ */
324
+void intf_poke ( struct interface *intf,
325
+		 void ( type ) ( struct interface *intf ) ) {
326
+	struct interface *dest;
327
+	intf_poke_TYPE ( void * ) *op =
328
+		intf_get_dest_op_untyped ( intf, type, &dest );
329
+	void *object = intf_object ( dest );
330
+
331
+	if ( op ) {
332
+		op ( object );
333
+	} else {
334
+		/* Default is to do nothing */
335
+	}
336
+
337
+	intf_put ( dest );
338
+}

+ 5
- 0
src/include/ipxe/interface.h Visa fil

@@ -145,6 +145,11 @@ extern void intf_close ( struct interface *intf, int rc );
145 145
 extern void intf_shutdown ( struct interface *intf, int rc );
146 146
 extern void intf_restart ( struct interface *intf, int rc );
147 147
 
148
+extern void intf_poke ( struct interface *intf,
149
+			void ( type ) ( struct interface *intf ) );
150
+#define intf_poke_TYPE( object_type ) \
151
+	typeof ( void ( object_type ) )
152
+
148 153
 extern struct interface_descriptor null_intf_desc;
149 154
 extern struct interface null_intf;
150 155
 

Laddar…
Avbryt
Spara