diff options
author | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-17 15:48:59 +0200 |
---|---|---|
committer | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-29 10:17:02 +0200 |
commit | b850b0df10ac722da3f299873276001026d99cc7 (patch) | |
tree | 33556c4c419cc995a91a45a503b70b5cc5fc1ae3 | |
parent | 9f9e6d2a3491c351a1570ebab331a225d257c177 (diff) |
Reports: Add prepare() method
Some report types may wish to manipulate their operation pointers
before they are taken into use by the main program. Add a mechanism
for implementing this.
Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
-rw-r--r-- | report_ops.h | 4 | ||||
-rw-r--r-- | reports.c | 25 |
2 files changed, 22 insertions, 7 deletions
diff --git a/report_ops.h b/report_ops.h index cc983ca..482ab27 100644 --- a/report_ops.h +++ b/report_ops.h @@ -8,6 +8,10 @@ struct wakeup_irq; struct report_ops { const char *name; + + /* No other method may be called or address taken before this */ + int (*prepare)(struct report_ops *); + int (*check_options)(struct program_options *); int (*check_output)(struct program_options *, void *); @@ -42,11 +42,21 @@ void list_report_formats_to_stderr(void) struct report_ops *get_report_ops(const char *name) { - const struct report_ops **ops_it; + struct report_ops **ops_it; + + for (ops_it = (struct report_ops **)(&report_ops_head)+1 ; + *ops_it ; ++ops_it) { - for (ops_it = (&report_ops_head)+1 ; *ops_it ; ++ops_it) { - /* All formats must export all of the asserted ops */ + /* Compare name */ assert((*ops_it)->name); + if (strcmp((*ops_it)->name, name)) + continue; + + /* Prepare for use */ + if ((*ops_it)->prepare && -1 == (*ops_it)->prepare(*ops_it)) + return NULL; + + /* Check mandatory operations */ assert((*ops_it)->check_output); assert((*ops_it)->open_report_file); assert((*ops_it)->close_report_file); @@ -65,9 +75,10 @@ struct report_ops *get_report_ops(const char *name) assert((*ops_it)->wakeup_cpu_header); assert((*ops_it)->wakeup_single_irq); assert((*ops_it)->wakeup_end_cpu); - /* Compare name */ - if (!strcmp((*ops_it)->name, name)) - return (struct report_ops *)*ops_it; + + return *ops_it; } - return NULL; + + fprintf(stderr, "Report style %s does not exist\n", name); + return ptrerror(NULL); } |