pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
output_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2020 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef CRM_OUTPUT__H
11 # define CRM_OUTPUT__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
22 # include <stdbool.h>
23 # include <stdio.h>
24 # include <libxml/tree.h>
25 # include <libxml/HTMLtree.h>
26 
27 # include <glib.h>
28 # include <crm/common/results.h>
29 
30 # define PCMK__API_VERSION "2.3"
31 
32 #if defined(PCMK__WITH_ATTRIBUTE_OUTPUT_ARGS)
33 # define PCMK__OUTPUT_ARGS(ARGS...) __attribute__((output_args(ARGS)))
34 #else
35 # define PCMK__OUTPUT_ARGS(ARGS...)
36 #endif
37 
39 
50 typedef pcmk__output_t * (*pcmk__output_factory_t)(char **argv);
51 
66 typedef int (*pcmk__message_fn_t)(pcmk__output_t *out, va_list args);
67 
89 typedef struct pcmk__message_entry_s {
96  const char *message_id;
97 
106  const char *fmt_name;
107 
114 
120 typedef struct pcmk__supported_format_s {
125  const char *name;
126 
131 
136  GOptionEntry *options;
138 
139 /* The following three blocks need to be updated each time a new base formatter
140  * is added.
141  */
142 
143 extern GOptionEntry pcmk__html_output_entries[];
144 extern GOptionEntry pcmk__log_output_entries[];
145 extern GOptionEntry pcmk__none_output_entries[];
146 extern GOptionEntry pcmk__text_output_entries[];
147 extern GOptionEntry pcmk__xml_output_entries[];
148 
150 pcmk__output_t *pcmk__mk_log_output(char **argv);
153 pcmk__output_t *pcmk__mk_xml_output(char **argv);
154 
155 #define PCMK__SUPPORTED_FORMAT_HTML { "html", pcmk__mk_html_output, pcmk__html_output_entries }
156 #define PCMK__SUPPORTED_FORMAT_LOG { "log", pcmk__mk_log_output, pcmk__log_output_entries }
157 #define PCMK__SUPPORTED_FORMAT_NONE { "none", pcmk__mk_none_output, pcmk__none_output_entries }
158 #define PCMK__SUPPORTED_FORMAT_TEXT { "text", pcmk__mk_text_output, pcmk__text_output_entries }
159 #define PCMK__SUPPORTED_FORMAT_XML { "xml", pcmk__mk_xml_output, pcmk__xml_output_entries }
160 
173  const char *fmt_name;
174 
183  bool quiet;
184 
191  gchar *request;
192 
199  FILE *dest;
200 
207  GHashTable *messages;
208 
216  void *priv;
217 
232  bool (*init) (pcmk__output_t *out);
233 
243  void (*free_priv) (pcmk__output_t *out);
244 
279  void (*finish) (pcmk__output_t *out, crm_exit_t exit_status, bool print,
280  void **copy_dest);
281 
297  void (*reset) (pcmk__output_t *out);
298 
310  void (*register_message) (pcmk__output_t *out, const char *message_id,
311  pcmk__message_fn_t fn);
312 
328  int (*message) (pcmk__output_t *out, const char *message_id, ...);
329 
339  void (*subprocess_output) (pcmk__output_t *out, int exit_status,
340  const char *proc_stdout, const char *proc_stderr);
341 
350  void (*version) (pcmk__output_t *out, bool extended);
351 
364  void (*info) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
365 
378  void (*err) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
379 
388  void (*output_xml) (pcmk__output_t *out, const char *name, const char *buf);
389 
409  void (*begin_list) (pcmk__output_t *out, const char *singular_noun,
410  const char *plural_noun, const char *format, ...)
411  G_GNUC_PRINTF(4, 5);
412 
422  void (*list_item) (pcmk__output_t *out, const char *name, const char *format, ...)
423  G_GNUC_PRINTF(3, 4);
424 
438 
449  void (*end_list) (pcmk__output_t *out);
450 
462  bool (*is_quiet) (pcmk__output_t *out);
463 };
464 
477 int
478 pcmk__call_message(pcmk__output_t *out, const char *message_id, ...);
479 
493 
508 int pcmk__output_new(pcmk__output_t **out, const char *fmt_name,
509  const char *filename, char **argv);
510 
527 int
528 pcmk__register_format(GOptionGroup *group, const char *name,
529  pcmk__output_factory_t create, GOptionEntry *options);
530 
542 void
543 pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table);
544 
550 void
552 
564 void
565 pcmk__register_message(pcmk__output_t *out, const char *message_id,
566  pcmk__message_fn_t fn);
567 
579 void
581 
582 /* Functions that are useful for implementing custom message formatters */
583 
594 void
595 pcmk__indented_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
596 
609 void
610 pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
611 
622 xmlNodePtr
624 
633 void
634 pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node);
635 
644 xmlNodePtr
646 
656 xmlNodePtr
657 pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content);
658 
673 void
674 pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node);
675 
690 void
692 
707 xmlNodePtr
709 
723 xmlNodePtr
724 pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id,
725  const char *class_name, const char *text);
726 
742 void
743 pcmk__html_add_header(const char *name, ...)
744 G_GNUC_NULL_TERMINATED;
745 
746 #define PCMK__OUTPUT_SPACER_IF(out_obj, cond) \
747  if (cond) { \
748  out_obj->info(out_obj, "%s", ""); \
749  }
750 
751 #define PCMK__OUTPUT_LIST_HEADER(out_obj, cond, retcode, title...) \
752  if (retcode == pcmk_rc_no_output) { \
753  PCMK__OUTPUT_SPACER_IF(out_obj, cond); \
754  retcode = pcmk_rc_ok; \
755  out_obj->begin_list(out_obj, NULL, NULL, title); \
756  }
757 
758 #define PCMK__OUTPUT_LIST_FOOTER(out_obj, retcode) \
759  if (retcode == pcmk_rc_ok) { \
760  out_obj->end_list(out_obj); \
761  }
762 
763 #ifdef __cplusplus
764 }
765 #endif
766 
767 #endif
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
void(* end_list)(pcmk__output_t *out)
pcmk__output_t * pcmk__mk_text_output(char **argv)
Definition: output_text.c:248
void void pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2
pcmk__message_fn_t fn
The function to be called for message_id given a match on fmt_name. See comments on pcmk__message_fn_...
int(* message)(pcmk__output_t *out, const char *message_id,...)
void pcmk__html_add_header(const char *name,...) G_GNUC_NULL_TERMINATED
Definition: output_html.c:423
const char * fmt_name
The name of this output formatter.
bool(* is_quiet)(pcmk__output_t *out)
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:139
struct pcmk__message_entry_s pcmk__message_entry_t
pcmk__output_t * pcmk__mk_html_output(char **argv)
Definition: output_html.c:372
xmlNodePtr pcmk__output_xml_peek_parent(pcmk__output_t *out)
Definition: output_xml.c:468
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:422
enum crm_exit_e crm_exit_t
void(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNodePtr pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id, const char *class_name, const char *text)
Definition: output_html.c:407
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table)
Definition: output.c:101
GOptionEntry pcmk__html_output_entries[]
Definition: output_html.c:42
pcmk__output_t * pcmk__mk_log_output(char **argv)
Definition: output_log.c:230
GOptionEntry pcmk__xml_output_entries[]
Definition: output_xml.c:33
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:121
GHashTable * messages
Custom messages that are currently registered on this formatter.
void(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void * priv
Implementation-specific private data.
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:448
GOptionEntry * options
Format-specific command line options. This can be NULL if no command line options should be supported...
pcmk__output_t * pcmk__mk_none_output(char **argv)
Definition: output_none.c:99
const char * fmt_name
The format type this handler is for.
bool quiet
Should this formatter supress most output?
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, GOptionEntry *options)
Definition: output.c:82
void(* free_priv)(pcmk__output_t *out)
bool(* init)(pcmk__output_t *out)
GOptionEntry pcmk__log_output_entries[]
Definition: output_log.c:23
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
void pcmk__indented_printf(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
pcmk__output_factory_t create
A function that creates a pcmk__output_t.
void(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:458
Function and executable result codes.
pcmk__output_t * pcmk__mk_xml_output(char **argv)
Definition: output_xml.c:380
FILE * dest
Where output should be written.
void pcmk__output_free(pcmk__output_t *out)
Definition: output.c:22
void pcmk__unregister_formats(void)
Definition: output.c:114
void void xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name)
Definition: output_xml.c:415
GOptionEntry pcmk__text_output_entries[]
Definition: output_text.c:19
GOptionEntry pcmk__none_output_entries[]
Definition: output_none.c:16
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
const char * name
The name of this output formatter, which should match the fmt_name parameter in some pcmk__output_t s...
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
void(* version)(pcmk__output_t *out, bool extended)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
void pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
Definition: output.c:145
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name)
Definition: output_xml.c:432
void(* reset)(pcmk__output_t *out)
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
Definition: output.c:34
char * name
Definition: pcmk_fence.c:31
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:441
const char * message_id
The message to be handled.
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
struct pcmk__supported_format_s pcmk__supported_format_t