pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
output.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.2"
31 
33 
44 typedef pcmk__output_t * (*pcmk__output_factory_t)(char **argv);
45 
60 typedef int (*pcmk__message_fn_t)(pcmk__output_t *out, va_list args);
61 
73 typedef struct pcmk__message_entry_s {
80  const char *message_id;
81 
90  const char *fmt_name;
91 
98 
104 typedef struct pcmk__supported_format_s {
109  const char *name;
110 
115 
120  GOptionEntry *options;
122 
123 /* The following three blocks need to be updated each time a new base formatter
124  * is added.
125  */
126 
127 extern GOptionEntry pcmk__html_output_entries[];
128 extern GOptionEntry pcmk__log_output_entries[];
129 extern GOptionEntry pcmk__none_output_entries[];
130 extern GOptionEntry pcmk__text_output_entries[];
131 extern GOptionEntry pcmk__xml_output_entries[];
132 
134 pcmk__output_t *pcmk__mk_log_output(char **argv);
137 pcmk__output_t *pcmk__mk_xml_output(char **argv);
138 
139 #define PCMK__SUPPORTED_FORMAT_HTML { "html", pcmk__mk_html_output, pcmk__html_output_entries }
140 #define PCMK__SUPPORTED_FORMAT_LOG { "log", pcmk__mk_log_output, pcmk__log_output_entries }
141 #define PCMK__SUPPORTED_FORMAT_NONE { "none", pcmk__mk_none_output, pcmk__none_output_entries }
142 #define PCMK__SUPPORTED_FORMAT_TEXT { "text", pcmk__mk_text_output, pcmk__text_output_entries }
143 #define PCMK__SUPPORTED_FORMAT_XML { "xml", pcmk__mk_xml_output, pcmk__xml_output_entries }
144 
157  const char *fmt_name;
158 
165  gchar *request;
166 
175 
182  FILE *dest;
183 
190  GHashTable *messages;
191 
199  void *priv;
200 
215  bool (*init) (pcmk__output_t *out);
216 
226  void (*free_priv)(pcmk__output_t *out);
227 
262  void (*finish) (pcmk__output_t *out, crm_exit_t exit_status, bool print,
263  void **copy_dest);
264 
280  void (*reset) (pcmk__output_t *out);
281 
293  void (*register_message) (pcmk__output_t *out, const char *message_id,
294  pcmk__message_fn_t fn);
295 
311  int (*message) (pcmk__output_t *out, const char *message_id, ...);
312 
322  void (*subprocess_output) (pcmk__output_t *out, int exit_status,
323  const char *proc_stdout, const char *proc_stderr);
324 
333  void (*version) (pcmk__output_t *out, bool extended);
334 
347  void (*info) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
348 
361  void (*err) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
362 
371  void (*output_xml) (pcmk__output_t *out, const char *name, const char *buf);
372 
392  void (*begin_list) (pcmk__output_t *out, const char *singular_noun,
393  const char *plural_noun, const char *format, ...)
394  G_GNUC_PRINTF(4, 5);
395 
405  void (*list_item) (pcmk__output_t *out, const char *name, const char *format, ...)
406  G_GNUC_PRINTF(3, 4);
407 
421 
432  void (*end_list) (pcmk__output_t *out);
433 };
434 
447 int
448 pcmk__call_message(pcmk__output_t *out, const char *message_id, ...);
449 
463 
478 int pcmk__output_new(pcmk__output_t **out, const char *fmt_name,
479  const char *filename, char **argv);
480 
497 int
498 pcmk__register_format(GOptionGroup *group, const char *name,
499  pcmk__output_factory_t create, GOptionEntry *options);
500 
512 void
513 pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table);
514 
520 void
522 
534 void
535 pcmk__register_message(pcmk__output_t *out, const char *message_id,
536  pcmk__message_fn_t fn);
537 
549 void
551 
552 /* Functions that are useful for implementing custom message formatters */
553 
564 void
565 pcmk__indented_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
566 
579 void
580 pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
581 
592 xmlNodePtr
594 
603 void
604 pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node);
605 
614 xmlNodePtr
615 pcmk__output_create_xml_node(pcmk__output_t *out, const char *name);
616 
626 xmlNodePtr
627 pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content);
628 
643 void
644 pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node);
645 
660 void
662 
677 xmlNodePtr
679 
693 xmlNodePtr
694 pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id,
695  const char *class_name, const char *text);
696 
713 void
714 pcmk__html_add_header(xmlNodePtr parent, const char *name, ...)
716 
717 #ifdef __cplusplus
718 }
719 #endif
720 
721 #endif
pcmk__output_t * pcmk__mk_none_output(char **argv)
Definition: output_none.c:93
bool(* init)(pcmk__output_t *out)
Definition: output.h:215
pcmk__output_t * pcmk__mk_html_output(char **argv)
Definition: output_html.c:355
pcmk__output_t * pcmk__mk_text_output(char **argv)
Definition: output_text.c:238
void G_GNUC_NULL_TERMINATED
Definition: output.h:715
pcmk__output_t * pcmk__mk_xml_output(char **argv)
Definition: output_xml.c:320
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_...
Definition: output.h:96
Definition: output.h:73
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:397
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name)
Definition: output_xml.c:371
void pcmk__output_free(pcmk__output_t *out)
Definition: output.c:19
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.h:293
const char * fmt_name
The name of this output formatter.
Definition: output.h:157
struct pcmk__supported_format_s pcmk__supported_format_t
void(* reset)(pcmk__output_t *out)
Definition: output.h:280
void void pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2
void(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Definition: output.h:361
xmlNodePtr pcmk__output_xml_peek_parent(pcmk__output_t *out)
Definition: output_xml.c:407
bool supports_quiet
Does this formatter support a special quiet mode?
Definition: output.h:174
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, GOptionEntry *options)
Definition: output.c:77
int(* message)(pcmk__output_t *out, const char *message_id,...)
Definition: output.h:311
enum crm_exit_e crm_exit_t
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:389
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
Definition: output.h:44
GHashTable * messages
Custom messages that are currently registered on this formatter.
Definition: output.h:190
void * priv
Implementation-specific private data.
Definition: output.h:199
struct pcmk__message_entry_s pcmk__message_entry_t
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:116
void(* end_list)(pcmk__output_t *out)
Definition: output.h:432
GOptionEntry * options
Format-specific command line options. This can be NULL if no command line options should be supported...
Definition: output.h:120
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
Definition: output.h:392
const char * fmt_name
The format type this handler is for.
Definition: output.h:90
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
Definition: output.h:60
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
Definition: output.h:322
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table)
Definition: output.c:96
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:380
pcmk__output_factory_t create
A function that creates a pcmk__output_t.
Definition: output.h:114
GOptionEntry pcmk__none_output_entries[]
Definition: output_none.c:15
Function and executable result codes.
void pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
Definition: output.c:140
FILE * dest
Where output should be written.
Definition: output.h:182
void pcmk__html_add_header(xmlNodePtr parent, const char *name,...)
Definition: output_html.c:405
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
Definition: output.h:420
void(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Definition: output.h:347
GOptionEntry pcmk__text_output_entries[]
Definition: output_text.c:18
const char * name
The name of this output formatter, which should match the fmt_name parameter in some pcmk__output_t s...
Definition: output.h:109
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
Definition: output.h:262
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:387
void(* free_priv)(pcmk__output_t *out)
Definition: output.h:226
gchar * request
A copy of the request that generated this output.
Definition: output.h:165
void pcmk__indented_printf(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
This structure contains everything that makes up a single output formatter.
Definition: output.h:153
void void xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name)
Definition: output_xml.c:354
void(* version)(pcmk__output_t *out, bool extended)
Definition: output.h:333
GOptionEntry pcmk__html_output_entries[]
Definition: output_html.c:41
GOptionEntry pcmk__log_output_entries[]
Definition: output_log.c:22
void pcmk__unregister_formats(void)
Definition: output.c:109
void(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
Definition: output.h:371
GOptionEntry pcmk__xml_output_entries[]
Definition: output_xml.c:27
pcmk__output_t * pcmk__mk_log_output(char **argv)
Definition: output_log.c:220
char * name
Definition: pcmk_fence.c:30
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:361
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:134
const char * message_id
The message to be handled.
Definition: output.h:80
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
Definition: output.c:31
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
Definition: output.h:405