File: confmodule.h

package info (click to toggle)
cdebconf 0.227
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,552 kB
  • sloc: ansic: 16,568; sh: 549; makefile: 456; sql: 52; perl: 13
file content (117 lines) | stat: -rw-r--r-- 3,511 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
 *
 * @file confmodule.h
 * @brief Configuration module object definition
 *
 */
#ifndef _CONFMODULE_H_
#define _CONFMODULE_H_

#include "common.h"
#include <signal.h>

/*
 *  For full backup sort, questions are not flagged as being seen
 *  as soon as they are displayed, but only when session is over.
 *  The list of displayed questions is managed by a stack, which
 *  is the seen_questions member of the confmodule structure.
 */
enum seen_action {
        STACK_SEEN_ADD,       /*  Add a question to the stack       */
        STACK_SEEN_REMOVE,    /*  Remove a question from the stack  */
        STACK_SEEN_SAVE       /*  Questions are flagged as seen and
                                  removed from the etack */
};

/* Set this in a signal handler to cause confmodule_communicate() to return
 * at the next opportunity.
 */
extern volatile sig_atomic_t signal_received;

/* If SIGCHLD is handled, put the status here. */
extern volatile sig_atomic_t sigchld_status;

struct configuration;
struct template_db;
struct question_db;
struct frontend;

struct confmodule {
	struct configuration *config;
	struct template_db *templates;
	struct question_db *questions;
	struct frontend *frontend;
	pid_t pid;
	int infd, outfd;
	int exitcode;
	int backed_up;
	const char *owner;
	char **seen_questions;
	int number_seen_questions;

	/* methods */
    /*
     * @brief runs a config script, connected to the confmodule
     * @param struct confmodule *mod - confmodule object
     * @param int argc - number of arguments to pass to config script
     * @param char **argv - argument array
     * @return pid_t - pid of config script, -1 if error
     */
	pid_t (*run)(struct confmodule *, int argc, char **argv);

    /**
     * @brief handles communication between a config script and the 
     * confmodule
     * @param struct confmodule *mod - confmodule object
     * @return int - DC_OK, DC_NOTOK
     */
	int (*communicate)(struct confmodule *mod);

    /**
     * @brief process one command
     * @param const char *cmd - command to execute
     * @param char *out - return buffer
     * @param size_t outsize - size of return buffer
     * @return char* - DC_OK, DC_NOTOK + error message
     */
    char* (*process_command)(struct confmodule *mod, char *cmd);

    /**
     * @brief Shuts down the confmodule
     * @param struct confmodule *mod - confmodule object
     * @return int - exit code of the config script
     */
	int (*shutdown)(struct confmodule *mod);

    /**
     * @brief Stack for already seen questions, to help backing up
     * @param struct confmodule *mod - confmodule object
     * @param int action - push, pop or sync values
     * @return int - DC_OK, DC_NOTOK
     */
	int (*update_seen_questions)(struct confmodule *mod, enum seen_action action);

    /**
     * @param struct confmodule *mod - confmodule object
     * @return int - DC_OK, DC_NOTOK
     */
	int (*save)(struct confmodule *mod);
};

/**
 * @brief creates a new confmodule object
 * @param struct configuration *config - configuration parameters
 * @param struct database *db - database object
 * @param struct frontend *frontend - frontend UI object
 * @return struct confmodule * - newly created confmodule
 */
struct confmodule *confmodule_new(struct configuration *,
	struct template_db *, struct question_db *, struct frontend *);

/*
 * @brief destroys a confmodule object
 * @param confmodule *mod - confmodule object to destroy
 */
void confmodule_delete(struct confmodule *mod);

#endif