summaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-11-18 00:42:52 +0100
committerLennart Poettering <lennart@poettering.net>2009-11-18 00:42:52 +0100
commit6091827530d6dd43479d6709fb6e9f745c11e900 (patch)
tree3edf7ccdeeb60b634d63e1abcaa8132a6259a331 /job.c
initial commit
Diffstat (limited to 'job.c')
-rw-r--r--job.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/job.c b/job.c
new file mode 100644
index 0000000000..5cd8f73a91
--- /dev/null
+++ b/job.c
@@ -0,0 +1,59 @@
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
+
+#include <assert.h>
+
+#include "macro.h"
+#include "job.h"
+
+Job* job_new(Manager *m, JobType type, Name *name) {
+ Job *j;
+
+ assert(m);
+ assert(type < _JOB_TYPE_MAX);
+ assert(name);
+
+ if (!(j = new0(Job, 1)))
+ return NULL;
+
+ j->manager = m;
+ j->id = m->current_job_id++;
+ j->type = type;
+ j->name = name;
+
+ /* We don't link it here, that's what job_link() is for */
+
+ return j;
+}
+
+int job_link(Job *j) {
+ int r;
+
+ assert(j);
+ assert(!j->linked);
+
+ if ((r = hashmap_put(j->manager->jobs, UINT32_TO_PTR(j->id), j)) < 0)
+ return r;
+
+ j->name->meta.job = j;
+
+ j->linked = true;
+
+ return 0;
+}
+
+void job_free(Job *j) {
+ assert(j);
+
+ /* Detach from next 'bigger' objects */
+
+ if (j->linked) {
+ if (j->name && j->name->meta.job == j)
+ j->name->meta.job = NULL;
+
+ hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
+ }
+
+ /* Free data and next 'smaller' objects */
+
+ free(j);
+}