Browse Source

Skeleton job control interface

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
36bfb6edbb
2 changed files with 201 additions and 0 deletions
  1. 77
    0
      src/core/job.c
  2. 124
    0
      src/include/gpxe/job.h

+ 77
- 0
src/core/job.c View File

@@ -0,0 +1,77 @@
1
+/*
2
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <string.h>
20
+#include <errno.h>
21
+#include <gpxe/job.h>
22
+
23
+/** @file
24
+ *
25
+ * Job control interfaces
26
+ *
27
+ */
28
+
29
+void done ( struct job_interface *job, int rc ) {
30
+	struct job_interface *dest = job_dest ( job );
31
+
32
+	dest->op->done ( dest, rc );
33
+}
34
+
35
+/****************************************************************************
36
+ *
37
+ * Helper methods
38
+ *
39
+ * These functions are designed to be used as methods in the
40
+ * job_interface_operations table.
41
+ *
42
+ */
43
+
44
+void ignore_done ( struct job_interface *job __unused, int rc __unused ) {
45
+	/* Nothing to do */
46
+}
47
+
48
+void ignore_kill ( struct job_interface *job __unused ) {
49
+	/* Nothing to do */
50
+}
51
+
52
+void ignore_progress ( struct job_interface *job __unused,
53
+		       struct job_progress *progress ) {
54
+	memset ( progress, 0, sizeof ( *progress ) );
55
+}
56
+
57
+/** Null job control interface operations */
58
+struct job_interface_operations null_job_ops = {
59
+	.done		= ignore_done,
60
+	.kill		= ignore_kill,
61
+	.progress	= ignore_progress,
62
+};
63
+
64
+/**
65
+ * Null job control interface
66
+ *
67
+ * This is the interface to which job control interfaces are connected
68
+ * when unplugged.  It will never generate messages, and will silently
69
+ * absorb all received messages.
70
+ */
71
+struct job_interface null_job = {
72
+	.intf = {
73
+		.dest = &null_job.intf,
74
+		.refcnt = null_refcnt,
75
+	},
76
+	.op = &null_job_ops,
77
+};

+ 124
- 0
src/include/gpxe/job.h View File

@@ -0,0 +1,124 @@
1
+#ifndef _GPXE_JOB_H
2
+#define _GPXE_JOB_H
3
+
4
+/** @file
5
+ *
6
+ * Job control interfaces
7
+ *
8
+ */
9
+
10
+#include <stddef.h>
11
+#include <gpxe/interface.h>
12
+
13
+/** Job progress */
14
+struct job_progress {
15
+	/** Amount of operation completed so far
16
+	 *
17
+	 * The units for this quantity are arbitrary.  @c completed
18
+	 * divded by @total should give something which approximately
19
+	 * represents the progress through the operation.  For a
20
+	 * download operation, using byte counts would make sense.
21
+	 */
22
+	unsigned long completed;
23
+	/** Total operation size
24
+	 *
25
+	 * See @c completed.  A zero value means "total size unknown"
26
+	 * and is explcitly permitted; users should take this into
27
+	 * account before calculating @c completed/total.
28
+	 */
29
+	unsigned long total;
30
+};
31
+
32
+struct job_interface;
33
+
34
+/** Job control interface operations */
35
+struct job_interface_operations {
36
+	/** Job completed
37
+	 *
38
+	 * @v job		Job control interface
39
+	 * @v rc		Overall job status code
40
+	 */
41
+	void ( * done ) ( struct job_interface *job, int rc );
42
+	/** Abort job
43
+	 *
44
+	 * @v job		Job control interface
45
+	 */
46
+	void ( * kill ) ( struct job_interface *job );
47
+	/** Get job progress
48
+	 *
49
+	 * @v job		Job control interface
50
+	 * @v progress		Progress data to fill in
51
+	 */
52
+	void ( * progress ) ( struct job_interface *job,
53
+			      struct job_progress *progress );
54
+};
55
+
56
+/** A job control interface */
57
+struct job_interface {
58
+	/** Generic object communication interface */
59
+	struct interface intf;
60
+	/** Operations for received messages */
61
+	struct job_interface_operations *op;
62
+};
63
+
64
+extern struct job_interface null_job;
65
+extern struct job_interface_operations null_job_ops;
66
+
67
+extern void done ( struct job_interface *job, int rc );
68
+
69
+extern void ignore_done ( struct job_interface *job, int rc );
70
+extern void ignore_kill ( struct job_interface *job );
71
+extern void ignore_progress ( struct job_interface *job,
72
+			      struct job_progress *progress );
73
+
74
+/**
75
+ * Initialise a job control interface
76
+ *
77
+ * @v job		Job control interface
78
+ * @v op		Job control interface operations
79
+ * @v refcnt		Job control interface reference counting method
80
+ */
81
+static inline void job_init ( struct job_interface *job,
82
+			       struct job_interface_operations *op,
83
+			       void ( * refcnt ) ( struct interface *intf,
84
+						   int delta ) ) {
85
+	job->intf.dest = &null_job.intf;
86
+	job->intf.refcnt = refcnt;
87
+	job->op = op;
88
+}
89
+
90
+/**
91
+ * Get job control interface from generic object communication interface
92
+ *
93
+ * @v intf		Generic object communication interface
94
+ * @ret job		Job control interface
95
+ */
96
+static inline struct job_interface *
97
+intf_to_job ( struct interface *intf ) {
98
+	return container_of ( intf, struct job_interface, intf );
99
+}
100
+
101
+/**
102
+ * Get destination job control interface
103
+ *
104
+ * @v job		Job control interface
105
+ * @ret dest		Destination interface
106
+ */
107
+static inline struct job_interface *
108
+job_dest ( struct job_interface *job ) {
109
+	return intf_to_job ( job->intf.dest );
110
+}
111
+
112
+/**
113
+ * Stop using a job control interface
114
+ *
115
+ * @v job		Job control interface
116
+ *
117
+ * After calling this method, no further messages will be received via
118
+ * the interface.
119
+ */
120
+static inline void job_nullify ( struct job_interface *job ) {
121
+	job->op = &null_job_ops;
122
+};
123
+
124
+#endif /* _GPXE_JOB_H */

Loading…
Cancel
Save