File: database.h

package info (click to toggle)
cdebconf 0.182
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,668 kB
  • sloc: ansic: 16,289; sh: 547; makefile: 438; sql: 52; perl: 13
file content (139 lines) | stat: -rw-r--r-- 4,201 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
 *
 * @file database.h
 * @brief Database class definition
 *
 */
#ifndef _DATABASE_H_
#define _DATABASE_H_

#include "constants.h"

/* Debconf database interfaces */

struct configuration;
struct template;
struct template_db;
struct question;
struct question_db;

#define DC_LOADTEMPLATE_NONE  (0)
#define DC_LOADTEMPLATE_MERGE (1<<0)

/**
 * @brief Methods for a template database module
 */
struct template_db_module {
    int (*initialize)(struct template_db *db, struct configuration *cfg);
    int (*shutdown)(struct template_db *db);
    int (*load)(struct template_db *db);
    int (*reload)(struct template_db *db);
    int (*save)(struct template_db *db);
    int (*set)(struct template_db *db, struct template *t);
    struct template *(*get)(struct template_db *db, const char *name);
    int (*remove)(struct template_db *, const char *name);
    int (*lock)(struct template_db *, const char *name);
    int (*unlock)(struct template_db *, const char *name);
    struct template *(*iterate)(struct template_db *db, void **iter);
    int (*accept)(struct template_db *, const char *name, const char *type);
};

/**
 * @brief Methods for a question database module
 */
struct question_db_module {
    int (*initialize)(struct question_db *db, struct configuration *cfg);
    int (*shutdown)(struct question_db *db);
    int (*load)(struct question_db *db);
    int (*save)(struct question_db *db);
    int (*set)(struct question_db *, struct question *q);
    struct question *(*get)(struct question_db *db, const char *name);
    int (*disown)(struct question_db *, const char *name, const char *owner);
    int (*disownall)(struct question_db *, const char *owner);
    int (*remove)(struct question_db *, const char *name);
    int (*lock)(struct question_db *, const char *name);
    int (*unlock)(struct question_db *, const char *name);
    int (*is_visible)(struct question_db *, const char *name, const char *priority);
    struct question *(*iterate)(struct question_db *, void **iter);
    int (*accept)(struct question_db *, const char *name, const char *type);
};

/**
 * @brief Template database object
 */
struct template_db {
    /** db module name */
    char *modname;
    /** db module handle */
    void *handle;
    /** configuration data */
    struct configuration *config;
    /** config path - base of instance configuration */
    char configpath[DEBCONF_MAX_CONFIGPATH_LEN];
    /** private data */
    void *data; 

    /** methods */
    struct template_db_module methods;
};

/**
 * @brief Question database object
 */
struct question_db {
    /** db module name */
    char *modname;
    /** db module handle */
    void *handle;
    /** configuration data */
    struct configuration *config;
    /** config path - base of instance configuration */
    char configpath[DEBCONF_MAX_CONFIGPATH_LEN];
    /** private data */
    void *data; 
    /** template database */
    struct template_db *tdb;

    /** methods */
    struct question_db_module methods;
};

/**
 * @brief Create a new template db object
 * @param cfg configuration
 * @param instance Name of instance (NULL for default)
 * @return Newly created db object
 */
struct template_db *template_db_new(struct configuration *cfg, const char *instance);

/**
 * @brief Destroy a template db oject
 * @param db Object to destroy
 */
void template_db_delete(struct template_db *db);

/**
 * @brief Loads all the templates from a file
 * @param tdb template database object
 * @param qdb question database object
 * @param filename file to load templates from
 * @param owner owner of the templates
 */
void template_db_loadfile(struct template_db *tdb, struct question_db *qdb, const char *filename, const char *owner, int flagsb);

/**
 * @brief Create a new question db object
 * @param cfg configuration
 * @param tdb associated template database object
 * @param instance Name of instance (NULL for default)
 * @return Newly created db object
 */
struct question_db *question_db_new(struct configuration *cfg, struct template_db *tdb, const char *instance);

/**
 * @brief Destroy a question db oject
 * @param db Object to destroy
 */
void question_db_delete(struct question_db *db);

#endif