pacemaker  2.0.2-debe490
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 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 
26 # include <glib.h>
27 # include <crm/common/results.h>
28 
29 # define PCMK__API_VERSION "1.0"
30 
31 /* Add to the long_options block in each tool to get the formatted output
32  * command line options added. Then call pcmk__parse_output_args to handle
33  * them.
34  */
35 # define PCMK__OUTPUT_OPTIONS(fmts) \
36  { "output-as", required_argument, NULL, 0, \
37  "Specify the format for output, one of: " fmts \
38  }, \
39  { "output-to", required_argument, NULL, 0, \
40  "Specify the destination for formatted output, \"-\" for stdout or a filename" \
41  }
42 
44 
55 typedef pcmk__output_t * (*pcmk__output_factory_t)(char **argv);
56 
71 typedef int (*pcmk__message_fn_t)(pcmk__output_t *out, va_list args);
72 
84 typedef struct pcmk__message_entry_s {
91  const char *message_id;
92 
101  const char *fmt_name;
102 
109 
110 /* Basic formatters everything supports. This block needs to be updated every
111  * time a new base formatter is added.
112  */
114 pcmk__output_t *pcmk__mk_xml_output(char **argv);
115 
128  char *fmt_name;
129 
136  char *request;
137 
146 
153  FILE *dest;
154 
161  GHashTable *messages;
162 
170  void *priv;
171 
186  bool (*init) (pcmk__output_t *out);
187 
197  void (*free_priv)(pcmk__output_t *out);
198 
214  void (*finish) (pcmk__output_t *out, crm_exit_t exit_status);
215 
231  void (*reset) (pcmk__output_t *out);
232 
244  void (*register_message) (pcmk__output_t *out, const char *message_id,
245  pcmk__message_fn_t fn);
246 
262  int (*message) (pcmk__output_t *out, const char *message_id, ...);
263 
273  void (*subprocess_output) (pcmk__output_t *out, int exit_status,
274  const char *proc_stdout, const char *proc_stderr);
275 
288  void (*info) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
289 
298  void (*output_xml) (pcmk__output_t *out, const char *name, const char *buf);
299 
318  void (*begin_list) (pcmk__output_t *out, const char *name,
319  const char *singular_noun, const char *plural_noun);
320 
329  void (*list_item) (pcmk__output_t *out, const char *name, const char *content);
330 
341  void (*end_list) (pcmk__output_t *out);
342 };
343 
356 int
357 pcmk__call_message(pcmk__output_t *out, const char *message_id, ...);
358 
372 void pcmk__output_free(pcmk__output_t *out, crm_exit_t exit_status);
373 
388 int pcmk__output_new(pcmk__output_t **out, const char *fmt_name,
389  const char *filename, char **argv);
390 
404 bool
405 pcmk__parse_output_args(const char *argname, char *argvalue, char **output_ty,
406  char **output_dest);
407 
417 int
418 pcmk__register_format(const char *fmt_name, pcmk__output_factory_t create);
419 
420 
432 void
433 pcmk__register_message(pcmk__output_t *out, const char *message_id,
434  pcmk__message_fn_t fn);
435 
447 void
449 
450 /* Functions that are useful for implementing custom message formatters */
451 
462 void
463 pcmk__indented_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
464 
473 void
474 pcmk__xml_add_node(pcmk__output_t *out, xmlNodePtr node);
475 
490 void
491 pcmk__xml_push_parent(pcmk__output_t *out, xmlNodePtr node);
492 
507 void
509 
510 #ifdef __cplusplus
511 }
512 #endif
513 
514 #endif
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status)
Definition: output.h:214
bool(* init)(pcmk__output_t *out)
Definition: output.h:186
pcmk__output_t * pcmk__mk_text_output(char **argv)
Definition: output_text.c:172
void void pcmk__xml_add_node(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:230
pcmk__output_t * pcmk__mk_xml_output(char **argv)
Definition: output_xml.c:200
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:107
Definition: output.h:84
void pcmk__output_free(pcmk__output_t *out, crm_exit_t exit_status)
Definition: output.c:19
void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
Definition: output.h:298
void pcmk__xml_push_parent(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:240
char * fmt_name
The name of this output formatter.
Definition: output.h:128
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.h:244
void(* reset)(pcmk__output_t *out)
Definition: output.h:231
bool supports_quiet
Does this formatter support a special quiet mode?
Definition: output.h:145
int(* message)(pcmk__output_t *out, const char *message_id,...)
Definition: output.h:262
void pcmk__xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:250
enum crm_exit_e crm_exit_t
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
Definition: output.h:55
void(* list_item)(pcmk__output_t *out, const char *name, const char *content)
Definition: output.h:329
GHashTable * messages
Custom messages that are currently registered on this formatter.
Definition: output.h:161
void * priv
Implementation-specific private data.
Definition: output.h:170
struct pcmk__message_entry_s pcmk__message_entry_t
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:117
char * request
A copy of the request that generated this output.
Definition: output.h:136
void(* end_list)(pcmk__output_t *out)
Definition: output.h:341
void(* begin_list)(pcmk__output_t *out, const char *name, const char *singular_noun, const char *plural_noun)
Definition: output.h:318
const char * fmt_name
The format type this handler is for.
Definition: output.h:101
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
Definition: output.h:71
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
Definition: output.h:273
bool pcmk__parse_output_args(const char *argname, char *argvalue, char **output_ty, char **output_dest)
Definition: output.c:85
int pcmk__register_format(const char *fmt_name, pcmk__output_factory_t create)
Definition: output.c:103
Function and executable result codes.
void pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
Definition: output.c:141
FILE * dest
Where output should be written.
Definition: output.h:153
void(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Definition: output.h:288
void(* free_priv)(pcmk__output_t *out)
Definition: output.h:197
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:124
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:135
const char * message_id
The message to be handled.
Definition: output.h:91
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
Definition: output.c:33