/* Free data and next 'smaller' objects */
free(j);
}
+
+void job_dump(Job *j, FILE*f) {
+
+ static const char* const job_type_table[_JOB_TYPE_MAX] = {
+ [JOB_START] = "START",
+ [JOB_STOP] = "STOP",
+ [JOB_VERIFY_STARTED] = "VERIFY_STARTED",
+ [JOB_RELOAD] = "RELOAD",
+ [JOB_RESTART] = "RESTART",
+ [JOB_TRY_RESTART] = "TRY_RESTART",
+ [JOB_RESTART_FINISH] = "RESTART_FINISH"
+ };
+
+ static const char* const job_state_table[_JOB_STATE_MAX] = {
+ [JOB_WAITING] = "WAITING",
+ [JOB_RUNNING] = "RUNNING",
+ [JOB_DONE] = "DONE"
+ };
+
+ assert(j);
+ assert(f);
+
+ fprintf(f, "Job %u: %s → %s in state %s\n",
+ j->id,
+ name_id(j->name),
+ job_type_table[j->type],
+ job_state_table[j->state]);
+}
Job* job_new(Manager *m, JobType type, Name *name);
int job_link(Job *job);
void job_free(Job *job);
+void job_dump(Job *j, FILE*f);
#endif
goto finish;
}
- if ((r = manager_add_job(m, JOB_START, milestone, JOB_REPLACE, &job)) < 0) {
- fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r));
- goto finish;
- }
+ manager_dump_names(m, stdout);
+
+ /* if ((r = manager_add_job(m, JOB_START, milestone, JOB_REPLACE, &job)) < 0) { */
+ /* fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r)); */
+ /* goto finish; */
+ /* } */
retval = 0;
*_ret = ret;
return 0;
}
+
+void manager_dump_jobs(Manager *s, FILE *f) {
+ void *state;
+ Job *j;
+
+ assert(s);
+ assert(f);
+
+ HASHMAP_FOREACH(j, s->jobs, state)
+ job_dump(j, f);
+}
+
+void manager_dump_names(Manager *s, FILE *f) {
+ void *state;
+ Name *n;
+
+ assert(s);
+ assert(f);
+
+ HASHMAP_FOREACH(n, s->names, state)
+ name_dump(n, f);
+}
#include <stdbool.h>
#include <inttypes.h>
+#include <stdio.h>
typedef struct Manager Manager;
int manager_load_name(Manager *m, const char *name, Name **_ret);
int manager_add_job(Manager *m, JobType job, Name *name, JobMode mode, Job **_ret);
+void manager_dump_names(Manager *s, FILE *f);
+void manager_dump_jobs(Manager *s, FILE *f);
+
#endif
Name *other;
assert(name);
- assert(s);
/* Frees the set and makes sure we are dropped from the
* inverse pointers */
return 0;
}
+
+const char* name_id(Name *n) {
+ assert(n);
+
+ return set_first(n->meta.names);
+}
+
+void name_dump(Name *n, FILE *f) {
+
+ static const char* const state_table[_NAME_STATE_MAX] = {
+ [NAME_STUB] = "STUB",
+ [NAME_LOADED] = "LOADED",
+ [NAME_FAILED] = "FAILED"
+ };
+
+ assert(n);
+
+ fprintf(stderr,
+ "Name %s (%s), state %s\n",
+ name_id(n),
+ n->meta.description ? n->meta.description : name_id(n),
+ state_table[n->meta.state]);
+
+ if (n->meta.job) {
+ fprintf(f, "\t▶ ");
+ job_dump(n->meta.job, f);
+ }
+}
typedef enum NameState {
NAME_STUB,
NAME_LOADED,
- NAME_FAILED
+ NAME_FAILED,
+ _NAME_STATE_MAX
} NameState;
typedef enum NameDependency {
int name_link(Name *name);
int name_merge(Name *name, Name *other);
int name_augment(Name *n);
+const char* name_id(Name *n);
+
+void name_dump(Name *n, FILE *f);
#endif