2 * This file is part of buxton.
4 * Copyright (C) 2013 Intel Corporation
6 * buxton is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
13 * \file backend.h Internal header
14 * This file is used internally by buxton to provide functionality
15 * used by and for the backend
25 #include "buxtonarray.h"
26 #include "buxtondata.h"
27 #include "buxtonstring.h"
32 * Possible backends for Buxton
34 typedef enum BuxtonBackendType {
35 BACKEND_UNSET = 0, /**<No backend set */
36 BACKEND_GDBM, /**<GDBM backend */
37 BACKEND_MEMORY, /**<Memory backend */
44 typedef enum BuxtonLayerType {
45 LAYER_SYSTEM, /**<A system layer*/
46 LAYER_USER, /**<A user layer */
51 * Represents a layer within Buxton
53 * Keys can be stored in various layers within Buxton, using a variety
54 * of backend and configurations. This is all handled transparently and
55 * through a consistent API
57 typedef struct BuxtonLayer {
58 BuxtonString name; /**<Name of the layer*/
59 BuxtonLayerType type; /**<Type of layer */
60 BuxtonBackendType backend; /**<Backend for this layer */
61 uid_t uid; /**<User ID for layers of type LAYER_USER */
62 int priority; /**<Priority of this layer */
63 char *description; /**<Description of this layer */
64 bool readonly; /**<Layer is readonly or not */
68 * Backend manipulation function
69 * @param layer The layer to manipulate or query
70 * @param key The key to manipulate or query
71 * @param data Set or get data, dependant on operation
72 * @param label The key's label
73 * @return a int value, indicating success of the operation or errno
75 typedef int (*module_value_func) (BuxtonLayer *layer, _BuxtonKey *key,
76 BuxtonData *data, BuxtonString *label);
79 * Backend key list function
80 * @param layer The layer to query
81 * @param data Pointer to store BuxtonArray in
82 * @return a boolean value, indicating success of the operation
84 typedef bool (*module_list_func) (BuxtonLayer *layer, BuxtonArray **data);
87 * Backend database creation function
88 * @param layer The layer matching the db to create
89 * @return A Database (not intended to be used from direct functions)
91 typedef void *(*module_db_init_func) (BuxtonLayer *layer);
94 * Destroy (or shutdown) a backend module
96 typedef void (*module_destroy_func) (void);
99 * A data-backend for Buxton
101 * Backends are controlled by Buxton for storing and retrieving data
103 typedef struct BuxtonBackend {
104 void *module; /**<Private handle to the module */
105 module_destroy_func destroy; /**<Destroy method */
106 module_value_func set_value; /**<Set value function */
107 module_value_func get_value; /**<Get value function */
108 module_list_func list_keys; /**<List keys function */
109 module_value_func unset_value; /**<Unset value function */
110 module_db_init_func create_db; /**<DB file creation function */
114 * Stores internal configuration of Buxton
116 typedef struct BuxtonConfig {
117 Hashmap *databases; /**<Database mapping */
118 Hashmap *layers; /**<Global layer configuration */
119 Hashmap *backends; /**<Backend mapping */
123 * Internal controller for Buxton
125 typedef struct BuxtonControl {
126 _BuxtonClient client; /**<Valid client connection */
127 BuxtonConfig config; /**<Valid configuration (unused) */
131 * Module initialisation function
132 * @param backend The backend to initialise
133 * @return A boolean value, representing the success of the operation
135 typedef bool (*module_init_func) (BuxtonBackend *backend)
136 __attribute__((warn_unused_result));
139 * Return a valid backend for the given configuration and layer
140 * @param config A BuxtonControl's configuration
141 * @param layer The layer to query
142 * @return an initialised backend, or NULL if the layer is not found
144 BuxtonBackend *backend_for_layer(BuxtonConfig *config,
146 __attribute__((warn_unused_result));
149 * Initialize layers using the configuration file
150 * @param config A BuxtonControl's configuration
152 void buxton_init_layers(BuxtonConfig *config);
155 * Remove association with backend (free and dlclose)
156 * @param backend A BuxtonBackend to be removed
158 void destroy_backend(BuxtonBackend *backend);
161 * Editor modelines - http://www.wireshark.org/tools/modelines.html
166 * indent-tabs-mode: t
169 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
170 * :indentSize=8:tabSize=8:noTabs=false: