gmerlin

cfg_registry.h

00001 /*****************************************************************
00002  * gmerlin - a general purpose multimedia framework and applications
00003  *
00004  * Copyright (c) 2001 - 2012 Members of the Gmerlin project
00005  * gmerlin-general@lists.sourceforge.net
00006  * http://gmerlin.sourceforge.net
00007  *
00008  * This program is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  * *****************************************************************/
00021 
00022 #ifndef __BG_CFG_REGISTRY_H_
00023 #define __BG_CFG_REGISTRY_H_
00024 
00025 #include <gmerlin/parameter.h>
00026 
00059 typedef struct bg_cfg_section_s  bg_cfg_section_t;
00060 
00067 typedef struct bg_cfg_registry_s bg_cfg_registry_t;
00068 
00076 bg_cfg_registry_t * bg_cfg_registry_create();
00077 
00083 void bg_cfg_registry_destroy(bg_cfg_registry_t * reg);
00084 
00085 /* cfg_xml.c */
00086 
00093 void bg_cfg_registry_load(bg_cfg_registry_t * reg, const char * filename);
00094 
00101 void bg_cfg_registry_save(bg_cfg_registry_t * reg, const char * filename);
00102 
00111 int bg_cfg_registry_has_section(bg_cfg_registry_t * reg, const char * name);
00112 
00113 
00114 /* The name and xml tag of the section must be set before */
00115 
00124 void bg_cfg_section_2_xml(const bg_cfg_section_t * section, xmlNodePtr xml_section);
00125 
00135 void bg_cfg_xml_2_section(xmlDocPtr xml_doc, xmlNodePtr xml_section,
00136                           bg_cfg_section_t * section);
00137 
00146 void bg_cfg_section_dump(bg_cfg_section_t * section, const char * filename);
00147 
00148 /*
00149  *  Path looks like "section:subsection:subsubsection"
00150  */
00151 
00163 bg_cfg_section_t * bg_cfg_registry_find_section(bg_cfg_registry_t * reg,
00164                                                 const char * path);
00165 
00175 bg_cfg_section_t * bg_cfg_section_find_subsection(bg_cfg_section_t * section,
00176                                                   const char * name);
00177 
00185 bg_cfg_section_t * bg_cfg_section_create_subsection_at_pos(bg_cfg_section_t * section,
00186                                                            int pos);
00187 
00195 void bg_cfg_section_move_child(bg_cfg_section_t * section, bg_cfg_section_t * child,
00196                                int pos);
00197 
00198 
00208 bg_cfg_section_t * bg_cfg_section_find_subsection_by_index(bg_cfg_section_t * section,
00209                                                            int index);
00210 
00211 
00212 /* 
00213  *  Create/destroy config sections
00214  */
00215 
00222 bg_cfg_section_t * bg_cfg_section_create(const char * name);
00223 
00235 bg_cfg_section_t *
00236 bg_cfg_section_create_from_parameters(const char * name,
00237                                       const bg_parameter_info_t * parameters);
00238 
00249 void bg_cfg_section_create_items(bg_cfg_section_t * section,
00250                                  const bg_parameter_info_t * parameters);
00251 
00257 void bg_cfg_section_destroy(bg_cfg_section_t * section);
00258 
00265 bg_cfg_section_t * bg_cfg_section_copy(const bg_cfg_section_t * src);
00266 
00277 void bg_cfg_section_transfer(bg_cfg_section_t * src, bg_cfg_section_t * dst);
00278 
00285 void bg_cfg_section_transfer_children(bg_cfg_section_t * src, bg_cfg_section_t * dst);
00286 
00293 void bg_cfg_section_add_ref(bg_cfg_section_t * section, bg_cfg_section_t * ref);
00294 
00295 /*
00296  *  Get/Set section names
00297  */
00298 
00305 const char * bg_cfg_section_get_name(bg_cfg_section_t * section);
00306 
00315 char * bg_cfg_section_get_name_translated(bg_cfg_section_t * section);
00316 
00325 void bg_cfg_section_set_name(bg_cfg_section_t * section, const char * name,
00326                              const char * gettext_domain,
00327                              const char * gettext_directory);
00328 
00329 /*
00330  *  Get/Set values
00331  */
00332 
00343 void bg_cfg_section_set_parameter(bg_cfg_section_t * section,
00344                                   const bg_parameter_info_t * info,
00345                                   const bg_parameter_value_t * value);
00346 
00359 int bg_cfg_section_set_parameters_from_string(bg_cfg_section_t * section,
00360                                               const bg_parameter_info_t * info,
00361                                               const char * str);
00362 
00373 void bg_cfg_section_get_parameter(bg_cfg_section_t * section,
00374                                   const bg_parameter_info_t * info,
00375                                   bg_parameter_value_t * value);
00376 
00385 void bg_cfg_section_delete_subsection(bg_cfg_section_t * section,
00386                                       bg_cfg_section_t * subsection);
00387 
00393 void bg_cfg_section_delete_subsections(bg_cfg_section_t * section);
00394 
00395 
00396 /*
00397  *  Type specific get/set functions, which don't require
00398  *  an info structure
00399  */
00400 
00408 void bg_cfg_section_set_parameter_int(bg_cfg_section_t * section,
00409                                       const char * name, int value);
00410 
00418 void bg_cfg_section_set_parameter_float(bg_cfg_section_t * section,
00419                                         const char * name, float value);
00420 
00428 void bg_cfg_section_set_parameter_string(bg_cfg_section_t * section,
00429                                          const char * name, const char * value);
00430 
00438 void bg_cfg_section_set_parameter_time(bg_cfg_section_t * section,
00439                                        const char * name, gavl_time_t value);
00440 
00441 /* Get parameter values, return 0 if no such entry */
00442 
00451 int bg_cfg_section_get_parameter_int(bg_cfg_section_t * section,
00452                                       const char * name, int * value);
00453 
00462 int bg_cfg_section_get_parameter_float(bg_cfg_section_t * section,
00463                                        const char * name, float * value);
00464 
00473 int bg_cfg_section_get_parameter_string(bg_cfg_section_t * section,
00474                                         const char * name, const char ** value);
00475 
00484 int bg_cfg_section_get_parameter_time(bg_cfg_section_t * section,
00485                                       const char * name, gavl_time_t * value);
00486 
00487 
00488 /* Apply all values found in the parameter info */
00489 
00502 void bg_cfg_section_apply(bg_cfg_section_t * section,
00503                           const bg_parameter_info_t * parameters,
00504                           bg_set_parameter_func_t func,
00505                           void * callback_data);
00506 
00518 void bg_cfg_section_apply_noterminate(bg_cfg_section_t * section,
00519                                       const bg_parameter_info_t * infos,
00520                                       bg_set_parameter_func_t func,
00521                                       void * callback_data);
00522 
00536 void bg_cfg_section_get(bg_cfg_section_t * section,
00537                         const bg_parameter_info_t * parameters,
00538                         bg_get_parameter_func_t func,
00539                         void * callback_data);
00540 
00548 int bg_cfg_section_has_subsection(bg_cfg_section_t * section,
00549                                   const char * name);
00550 
00557 void bg_cfg_section_restore_defaults(bg_cfg_section_t * section,
00558                                      const bg_parameter_info_t * info);
00559 
00560 
00561 #endif /* __BG_CFG_REGISTRY_H_ */