• Main Page
  • Classes
  • Files
  • File List
  • File Members

src/libmcs/mcs.h

Go to the documentation of this file.
00001 /*
00002  * This is mcs; a modular configuration system.
00003  *
00004  * Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are
00008  * met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice,
00011  *    this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * 3. The name of the author may not be used to endorse or promote products
00018  *    derived from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00021  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
00024  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00026  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00028  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef __LIBMCS_MCS_H__
00034 #define __LIBMCS_MCS_H__
00035 
00036 #include <unistd.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <sys/stat.h>
00040 #include <sys/types.h>
00041 #include <dirent.h>
00042 #include <stdio.h>
00043 #include <limits.h>
00044 #include <stdarg.h>
00045 #include <errno.h>
00046 
00047 #ifndef __WIN32__
00048 #include <dlfcn.h>
00049 #endif
00050 
00051 #include <mowgli.h>
00052 
00053 #ifdef _MCS_CORE
00054 # include <libmcs/mcs_config.h>
00055 #endif
00056 
00058 typedef enum {
00059         MCS_FAIL, 
00060         MCS_OK    
00061 } mcs_response_t;
00062 
00064 typedef struct mcs_handle_ mcs_handle_t;
00065 
00079 typedef struct {
00080         void *handle; 
00093         const char *name;
00094 
00095         /* constructors and destructors */
00096 
00110         mcs_handle_t *(*mcs_new)(char *domain);
00111 
00121         void (*mcs_destroy)(mcs_handle_t *handle);
00122 
00123         /* retrieval */
00124 
00133         mcs_response_t (*mcs_get_string)(mcs_handle_t *handle,
00134                                          const char *section,
00135                                          const char *key,
00136                                          char **value);
00137 
00146         mcs_response_t (*mcs_get_int)(mcs_handle_t *handle,
00147                                       const char *section,
00148                                       const char *key,
00149                                       int *value);
00150 
00159         mcs_response_t (*mcs_get_bool)(mcs_handle_t *handle,
00160                                        const char *section,
00161                                        const char *key,
00162                                        int *value);
00163 
00172         mcs_response_t (*mcs_get_float)(mcs_handle_t *handle,
00173                                         const char *section,
00174                                         const char *key,
00175                                         float *value);
00176 
00185         mcs_response_t (*mcs_get_double)(mcs_handle_t *handle,
00186                                          const char *section,
00187                                          const char *key,
00188                                          double *value);
00189 
00190         /* setting data */
00191 
00200         mcs_response_t (*mcs_set_string)(mcs_handle_t *handle,
00201                                          const char *section,
00202                                          const char *key,
00203                                          const char *value);
00204 
00213         mcs_response_t (*mcs_set_int)(mcs_handle_t *handle,
00214                                       const char *section,
00215                                       const char *key,
00216                                       int value);
00217 
00226         mcs_response_t (*mcs_set_bool)(mcs_handle_t *handle,
00227                                        const char *section,
00228                                        const char *key,
00229                                        int value);
00230 
00239         mcs_response_t (*mcs_set_float)(mcs_handle_t *handle,
00240                                         const char *section,
00241                                         const char *key,
00242                                         float value);
00243 
00252         mcs_response_t (*mcs_set_double)(mcs_handle_t *handle,
00253                                          const char *section,
00254                                          const char *key,
00255                                          double value);
00256 
00257         /* unset */
00258 
00266         mcs_response_t (*mcs_unset_key)(mcs_handle_t *handle,
00267                                         const char *section,
00268                                         const char *key);
00269 
00270         /* key request */
00271 
00278         mowgli_queue_t *(*mcs_get_keys)(mcs_handle_t *handle,
00279                                     const char *section);
00280 
00281         /* sections request */
00282 
00288         mowgli_queue_t *(*mcs_get_sections)(mcs_handle_t *handle);
00289 } mcs_backend_t;
00290 
00294 struct mcs_handle_ {
00295         mowgli_object_t object;  
00296         mcs_backend_t *base;     
00297         void *mcs_priv_handle;   
00298 };
00299 
00300 /*
00301  * These functions have to do with initialization of the
00302  * library.
00303  */
00304 
00305 extern void  mcs_init(void);
00306 extern void  mcs_fini(void);
00307 extern char *mcs_version(void);
00308 extern void  mcs_handle_class_init(void);
00309  
00310 /*
00311  * These functions have to do with registration of MCS backends.
00312  */
00313 extern mcs_response_t mcs_backend_register(mcs_backend_t *backend);
00314 extern mcs_response_t mcs_backend_unregister(mcs_backend_t *backend);
00315 extern mowgli_queue_t *   mcs_backend_get_list(void);
00316 extern const char *       mcs_backend_select(void);
00317 
00318 /*
00319  * These functions provide the public interface for creating and closing MCS
00320  * handles.
00321  *
00322  * Please note that if a handle is not closed, the data may not be saved to
00323  * disk.
00324  */
00325 extern mcs_handle_t *mcs_new(char *domain);
00326 extern void mcs_destroy(mcs_handle_t *handle);
00327 
00328 /*
00329  * These functions provide the public interface for querying and setting data.
00330  */
00331 /* retrieval */
00332 extern mcs_response_t mcs_get_string(mcs_handle_t *handle,
00333                                  const char *section,
00334                                  const char *key,
00335                                  char **value);
00336 
00337 extern mcs_response_t mcs_get_int(mcs_handle_t *handle,
00338                               const char *section,
00339                               const char *key,
00340                               int *value);
00341 
00342 extern mcs_response_t mcs_get_bool(mcs_handle_t *handle,
00343                                const char *section,
00344                                const char *key,
00345                                int *value);
00346 
00347 extern mcs_response_t mcs_get_float(mcs_handle_t *handle,
00348                                 const char *section,
00349                                 const char *key,
00350                                 float *value);
00351 
00352 extern mcs_response_t mcs_get_double(mcs_handle_t *handle,
00353                                  const char *section,
00354                                  const char *key,
00355                                  double *value);
00356 
00357 /* setting data */
00358 extern mcs_response_t mcs_set_string(mcs_handle_t *handle,
00359                                  const char *section,
00360                                  const char *key,
00361                                  const char *value);
00362 
00363 extern mcs_response_t mcs_set_int(mcs_handle_t *handle,
00364                               const char *section,
00365                               const char *key,
00366                               int value);
00367 
00368 extern mcs_response_t mcs_set_bool(mcs_handle_t *handle,
00369                                const char *section,
00370                                const char *key,
00371                                int value);
00372 
00373 extern mcs_response_t mcs_set_float(mcs_handle_t *handle,
00374                                 const char *section,
00375                                 const char *key,
00376                                 float value);
00377 
00378 extern mcs_response_t mcs_set_double(mcs_handle_t *handle,
00379                                  const char *section,
00380                                  const char *key,
00381                                  double value);
00382 
00383 /* unset */
00384 extern mcs_response_t mcs_unset_key(mcs_handle_t *handle,
00385                                 const char *section,
00386                                 const char *key);
00387 
00388 /* key request */
00389 extern mowgli_queue_t *mcs_get_keys(mcs_handle_t *handle,
00390                                 const char *section);
00391 
00392 extern mowgli_queue_t *mcs_get_sections(mcs_handle_t *handle);
00393 
00394 /*
00395  * These functions have to do with the plugin loader.
00396  */
00397 extern void mcs_load_plugins(void);
00398 extern void mcs_unload_plugins(mowgli_queue_t *l);
00399 
00400 /*
00401  * These functions are utility functions.
00402  */
00403 extern size_t mcs_strnlen(const char *str, size_t len);
00404 extern char * mcs_strndup(const char *str, size_t len);
00405 extern int mcs_create_directory(const char *path, mode_t mode);
00406 extern size_t mcs_strlcat(char *dest, const char *src, size_t count);
00407 extern size_t mcs_strlcpy(char *dest, const char *src, size_t count);
00408 
00409 #endif

Generated on Sun Oct 30 2011 for libmcs by  doxygen 1.7.1