ConfigManager Class Reference

#include <config_manager.h>

Inheritance diagram for ConfigManager:
Singleton< ConfigManager > zmm::Object

Public Member Functions

 ConfigManager ()
virtual ~ConfigManager ()
zmm::String getConfigFilename ()
 Returns the name of the config file that was used to launch the server.
void load (zmm::String filename)
zmm::String getOption (config_option_t option)
 returns a config option of type String
int getIntOption (config_option_t option)
 returns a config option of type int
bool getBoolOption (config_option_t option)
 returns a config option of type bool
zmm::Ref< DictionarygetDictionaryOption (config_option_t option)
 returns a config option of type Dictionary
zmm::Ref< zmm::Array
< zmm::StringBase > > 
getStringArrayOption (config_option_t option)
 returns a config option of type Array of StringBase
zmm::Ref< ObjectDictionary
< zmm::Object > > 
getObjectDictionaryOption (config_option_t option)
zmm::Ref< AutoscanListgetAutoscanListOption (config_option_t option)
 returns a config option of type AutoscanList
void writeBookmark (zmm::String ip, zmm::String port)
 Creates a html file that is a redirector to the current server i instance.
void retain ()
void release ()
int getRefCount ()

Static Public Member Functions

static void setStaticArgs (zmm::String _filename, zmm::String _userhome, zmm::String _config_dir=_(DEFAULT_CONFIG_HOME), zmm::String _prefix_dir=_(PACKAGE_DATADIR), zmm::String _magic=nil, bool _debug_logging=false)
 sets static configuration parameters that will be used by when the ConfigManager class initializes
static bool isDebugLogging ()
static zmm::Ref< ConfigManagergetInstance ()
static void * operator new (size_t size)
static void operator delete (void *ptr)

Protected Member Functions

zmm::Ref< mxml::Elementmap_from_to (zmm::String from, zmm::String to)
zmm::Ref< mxml::Elementtreat_as (zmm::String mimetype, zmm::String as)
zmm::Ref< mxml::ElementrenderTranscodingSection ()
zmm::Ref< mxml::ElementrenderExtendedRuntimeSection ()
zmm::Ref< mxml::ElementrenderOnlineSection ()
zmm::String createDefaultConfig (zmm::String userhome)
void save ()
void save_text (zmm::String filename, zmm::String content)
void migrate ()
void validate (zmm::String serverhome)
void prepare_udn ()
zmm::String construct_path (zmm::String path)
void prepare_path (zmm::String path, bool needDir=false, bool existenceUnneeded=false)
zmm::String getOption (zmm::String xpath, zmm::String def)
 Returns a config option with the given path, if option does not exist a default value is returned.
int getIntOption (zmm::String xpath, int def)
 same as getOption but returns an integer value of the option
zmm::String getOption (zmm::String xpath)
 Returns a config option with the given path, an exception is raised if option does not exist.
int getIntOption (zmm::String xpath)
 same as getOption but returns an integer value of the option
zmm::Ref< mxml::ElementgetElement (zmm::String xpath)
 Returns a config XML element with the given path, an exception is raised if element does not exist.
zmm::String checkOptionString (zmm::String xpath)
 Checks if the string returned by getOption is valid.
zmm::Ref< DictionarycreateDictionaryFromNodeset (zmm::Ref< mxml::Element > element, zmm::String nodeName, zmm::String keyAttr, zmm::String valAttr, bool tolower=false)
 Creates a dictionary from an XML nodeset.
zmm::Ref< AutoscanListcreateAutoscanListFromNodeset (zmm::Ref< mxml::Element > element, scan_mode_t scanmode)
 Creates an aray of AutoscanDirectory objects from an XML nodeset.
zmm::Ref< zmm::Array
< zmm::StringBase > > 
createArrayFromNodeset (zmm::Ref< mxml::Element > element, zmm::String nodeName, zmm::String attrName)
void dumpOptions ()
virtual void init ()
virtual void shutdown ()
virtual void registerSingleton ()

Protected Attributes

zmm::Ref< mxml::DocumentrootDoc
zmm::Ref< mxml::Elementroot
zmm::Ref< Dictionarymime_content
zmm::Ref< zmm::Array
< ConfigOption > > 
options
mt_atomic_t _ref_count

Static Protected Attributes

static zmm::String filename = nil
static zmm::String userhome = nil
static zmm::String config_dir = _(DEFAULT_CONFIG_HOME)
static zmm::String prefix_dir = _(PACKAGE_DATADIR)
static zmm::String magic = nil
static bool debug_logging = false
static zmm::Ref< Mutexmutex
static zmm::Ref< ConfigManagerinstance
static bool singletonActive

Detailed Description

Definition at line 201 of file config_manager.h.


Constructor & Destructor Documentation

ConfigManager::ConfigManager (  ) 
ConfigManager::~ConfigManager (  )  [virtual]

Definition at line 80 of file config_manager.cc.

References _, config_dir, DEFAULT_CONFIG_HOME, filename, magic, nil, prefix_dir, and userhome.


Member Function Documentation

String ConfigManager::checkOptionString ( zmm::String  xpath  )  [protected]

Checks if the string returned by getOption is valid.

Parameters:
xpath xpath expression to the XML node

Definition at line 2475 of file config_manager.cc.

References _, _Exception, getOption(), and string_ok().

Referenced by migrate(), prepare_path(), and validate().

String ConfigManager::construct_path ( zmm::String  path  )  [protected]
Ref< Array< StringBase > > ConfigManager::createArrayFromNodeset ( zmm::Ref< mxml::Element element,
zmm::String  nodeName,
zmm::String  attrName 
) [protected]

Definition at line 3110 of file config_manager.cc.

References nil, and string_ok().

Referenced by validate().

Ref< AutoscanList > ConfigManager::createAutoscanListFromNodeset ( zmm::Ref< mxml::Element element,
scan_mode_t  scanmode 
) [protected]

Creates an aray of AutoscanDirectory objects from an XML nodeset.

Parameters:
element starting element of the ndoeset.
scanmode add only directories with the specified scanmode to the array

Definition at line 2905 of file config_manager.cc.

References _, _Exception, BasicScanLevel, check_path(), FullScanLevel, zmm::Exception::getMessage(), getOption(), InotifyScanMode, nil, normalizePath(), string_ok(), TimedScanMode, and zmm::String::toUInt().

Referenced by validate().

String ConfigManager::createDefaultConfig ( zmm::String  userhome  )  [protected]
Ref< Dictionary > ConfigManager::createDictionaryFromNodeset ( zmm::Ref< mxml::Element element,
zmm::String  nodeName,
zmm::String  keyAttr,
zmm::String  valAttr,
bool  tolower = false 
) [protected]

Creates a dictionary from an XML nodeset.

Parameters:
element starting element of the nodeset.
nodeName name of each node in the set
keyAttr attribute name to be used as a key
valAttr attribute name to be used as value

The basic idea is the following: You have a piece of XML that looks like this <some-section> <map from="1" to="2"> <map from="3" to="4"> </some-section>

This function will create a dictionary with the following key:value paris: "1":"2", "3":"4"

Definition at line 2484 of file config_manager.cc.

References nil, string_ok(), and zmm::String::toLower().

Referenced by validate().

void ConfigManager::dumpOptions (  )  [protected]

Definition at line 3082 of file config_manager.cc.

References CFG_MAX, getBoolOption(), getIntOption(), getOption(), and log_debug.

Ref< AutoscanList > ConfigManager::getAutoscanListOption ( config_option_t  option  ) 

returns a config option of type AutoscanList

Parameters:
option to retrieve

Definition at line 3172 of file config_manager.cc.

References options.

bool ConfigManager::getBoolOption ( config_option_t  option  ) 

returns a config option of type bool

Parameters:
option option to retrieve.

Definition at line 3145 of file config_manager.cc.

References options.

Referenced by dumpOptions(), validate(), and writeBookmark().

zmm::String ConfigManager::getConfigFilename (  )  [inline]

Returns the name of the config file that was used to launch the server.

Definition at line 209 of file config_manager.h.

References filename.

Ref< Dictionary > ConfigManager::getDictionaryOption ( config_option_t  option  ) 

returns a config option of type Dictionary

Parameters:
option option to retrieve.

Definition at line 3150 of file config_manager.cc.

References options.

Ref< Element > ConfigManager::getElement ( zmm::String  xpath  )  [protected]

Returns a config XML element with the given path, an exception is raised if element does not exist.

Parameters:
xpath option xpath.

The xpath parameter has XPath syntax. "/path/to/element" will return the text value of the given "element" element

Definition at line 2434 of file config_manager.cc.

References root.

Referenced by prepare_path(), and validate().

static zmm::Ref<ConfigManager > Singleton< ConfigManager >::getInstance (  )  [inline, static, inherited]
int ConfigManager::getIntOption ( zmm::String  xpath  )  [protected]

same as getOption but returns an integer value of the option

Definition at line 2426 of file config_manager.cc.

References getOption(), and zmm::String::toInt().

int ConfigManager::getIntOption ( zmm::String  xpath,
int  def 
) [protected]

same as getOption but returns an integer value of the option

Definition at line 2403 of file config_manager.cc.

References getOption(), and zmm::String::toInt().

int ConfigManager::getIntOption ( config_option_t  option  ) 

returns a config option of type int

Parameters:
option option to retrieve.

Definition at line 3140 of file config_manager.cc.

References options.

Referenced by dumpOptions(), migrate(), and validate().

Ref< ObjectDictionary< zmm::Object > > ConfigManager::getObjectDictionaryOption ( config_option_t  option  ) 

Definition at line 3160 of file config_manager.cc.

References options.

String ConfigManager::getOption ( zmm::String  xpath  )  [protected]

Returns a config option with the given path, an exception is raised if option does not exist.

Parameters:
xpath option xpath.

The xpath parameter has XPath syntax. Currently only two xpath constructs are supported: "/path/to/option" will return the text value of the given "option" element "/path/to/option/attribute::attr" will return the value of the attribute "attr"

Todo:
is this ok?

Definition at line 2413 of file config_manager.cc.

References _, _Exception, nil, root, and trim_string().

String ConfigManager::getOption ( zmm::String  xpath,
zmm::String  def 
) [protected]

Returns a config option with the given path, if option does not exist a default value is returned.

Parameters:
xpath option xpath
def default value if option not found

the name parameter has the XPath syntax. Currently only two xpath constructs are supported: "/path/to/option" will return the text value of the given "option" element "/path/to/option/attribute::attr" will return the value of the attribute "attr"

Definition at line 2350 of file config_manager.cc.

References _, _Exception, zmm::String::c_str(), XPath::getAxis(), XPath::getAxisPart(), XPath::getPathPart(), XPath::getSpec(), log_debug, nil, root, split_string(), string_ok(), and trim_string().

String ConfigManager::getOption ( config_option_t  option  ) 

returns a config option of type String

Parameters:
option option to retrieve.

Definition at line 3135 of file config_manager.cc.

References options.

Referenced by checkOptionString(), construct_path(), createAutoscanListFromNodeset(), dumpOptions(), getIntOption(), migrate(), prepare_udn(), validate(), and writeBookmark().

int Object::getRefCount (  )  [inherited]

Definition at line 78 of file object.cc.

References zmm::Object::_ref_count, and atomic_get().

Ref< Array< StringBase > > ConfigManager::getStringArrayOption ( config_option_t  option  ) 

returns a config option of type Array of StringBase

Parameters:
option option to retrieve.

Definition at line 3155 of file config_manager.cc.

References options.

virtual void Singleton< ConfigManager >::init (  )  [inline, protected, virtual, inherited]

Definition at line 87 of file singleton.h.

static bool ConfigManager::isDebugLogging (  )  [inline, static]

Definition at line 258 of file config_manager.h.

References debug_logging.

Referenced by _log_debug(), and _print_backtrace().

void ConfigManager::load ( zmm::String  filename  ) 

Definition at line 2337 of file config_manager.cc.

References _, _Exception, nil, root, and rootDoc.

Referenced by ConfigManager().

Ref< Element > ConfigManager::map_from_to ( zmm::String  from,
zmm::String  to 
) [protected]

Definition at line 168 of file config_manager.cc.

References _.

Referenced by createDefaultConfig().

void ConfigManager::migrate (  )  [protected]
void Object::operator delete ( void *  ptr  )  [static, inherited]

Definition at line 87 of file object.cc.

References FREE.

void * Object::operator new ( size_t  size  )  [static, inherited]

Definition at line 83 of file object.cc.

References MALLOC.

void ConfigManager::prepare_path ( zmm::String  path,
bool  needDir = false,
bool  existenceUnneeded = false 
) [protected]

Definition at line 2294 of file config_manager.cc.

References check_path_ex(), checkOptionString(), construct_path(), getElement(), and nil.

Referenced by validate().

void ConfigManager::prepare_udn (  )  [protected]

Definition at line 2263 of file config_manager.cc.

References _, getOption(), log_info, nil, root, save(), uuid_generate(), and uuid_unparse().

Referenced by ConfigManager().

virtual void Singleton< ConfigManager >::registerSingleton (  )  [inline, protected, virtual, inherited]

Definition at line 94 of file singleton.h.

void Object::release (  )  [inherited]
Ref< Element > ConfigManager::renderExtendedRuntimeSection (  )  [protected]
zmm::Ref<mxml::Element> ConfigManager::renderOnlineSection (  )  [protected]

Referenced by createDefaultConfig(), and migrate().

zmm::Ref<mxml::Element> ConfigManager::renderTranscodingSection (  )  [protected]

Referenced by createDefaultConfig(), and migrate().

void Object::retain (  )  [inherited]
void ConfigManager::save (  )  [protected]

Definition at line 2309 of file config_manager.cc.

References filename, rootDoc, and save_text().

Referenced by migrate(), and prepare_udn().

void ConfigManager::save_text ( zmm::String  filename,
zmm::String  content 
) [protected]

Definition at line 2314 of file config_manager.cc.

References _, _Exception, zmm::String::c_str(), zmm::String::length(), NULL, and XML_HEADER.

Referenced by createDefaultConfig(), and save().

void ConfigManager::setStaticArgs ( zmm::String  _filename,
zmm::String  _userhome,
zmm::String  _config_dir = _(DEFAULT_CONFIG_HOME),
zmm::String  _prefix_dir = _(PACKAGE_DATADIR),
zmm::String  _magic = nil,
bool  _debug_logging = false 
) [static]

sets static configuration parameters that will be used by when the ConfigManager class initializes

Definition at line 89 of file config_manager.cc.

References config_dir, debug_logging, filename, magic, prefix_dir, and userhome.

Referenced by main().

virtual void Singleton< ConfigManager >::shutdown (  )  [inline, protected, virtual, inherited]

Definition at line 88 of file singleton.h.

Ref< Element > ConfigManager::treat_as ( zmm::String  mimetype,
zmm::String  as 
) [protected]

Definition at line 176 of file config_manager.cc.

References _.

Referenced by createDefaultConfig(), and migrate().

void ConfigManager::validate ( zmm::String  serverhome  )  [protected]

Todo:
clean up the construct path / prepare path mess

Definition at line 900 of file config_manager.cc.

References _, _Exception, zmm::String::c_str(), CFG_IMPORT_AUTOSCAN_TIMED_LIST, CFG_IMPORT_FILESYSTEM_CHARSET, CFG_IMPORT_HIDDEN_FILES, CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_CASE_SENSITIVE, CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_LIST, CFG_IMPORT_MAPPINGS_IGNORE_UNKNOWN_EXTENSIONS, CFG_IMPORT_MAPPINGS_MIMETYPE_TO_CONTENTTYPE_LIST, CFG_IMPORT_MAPPINGS_MIMETYPE_TO_UPNP_CLASS_LIST, CFG_IMPORT_METADATA_CHARSET, CFG_IMPORT_PLAYLIST_CHARSET, CFG_IMPORT_SCRIPTING_VIRTUAL_LAYOUT_TYPE, CFG_SERVER_ALIVE_INTERVAL, CFG_SERVER_APPEND_PRESENTATION_URL_TO, CFG_SERVER_BOOKMARK_FILE, CFG_SERVER_CUSTOM_HTTP_HEADERS, CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_CONTENT_LIST, CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_ENABLED, CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_STRING, CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_STRING_MODE_PREPEND, CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_SUPPRESS_CDS_UPDATES, CFG_SERVER_HIDE_PC_DIRECTORY, CFG_SERVER_HOME, CFG_SERVER_IP, CFG_SERVER_MANUFACTURER_URL, CFG_SERVER_MODEL_DESCRIPTION, CFG_SERVER_MODEL_NAME, CFG_SERVER_MODEL_NUMBER, CFG_SERVER_NAME, CFG_SERVER_NETWORK_INTERFACE, CFG_SERVER_PORT, CFG_SERVER_PRESENTATION_URL, CFG_SERVER_SERIAL_NUMBER, CFG_SERVER_SERVEDIR, CFG_SERVER_STORAGE_CACHING_ENABLED, CFG_SERVER_STORAGE_DRIVER, CFG_SERVER_TMPDIR, CFG_SERVER_UDN, CFG_SERVER_UI_ACCOUNT_LIST, CFG_SERVER_UI_ACCOUNTS_ENABLED, CFG_SERVER_UI_DEFAULT_ITEMS_PER_PAGE, CFG_SERVER_UI_ENABLED, CFG_SERVER_UI_ITEMS_PER_PAGE_DROPDOWN, CFG_SERVER_UI_POLL_INTERVAL, CFG_SERVER_UI_POLL_WHEN_IDLE, CFG_SERVER_UI_SESSION_TIMEOUT, CFG_SERVER_UI_SHOW_TOOLTIPS, CFG_SERVER_UPNP_TITLE_AND_DESC_STRING_LIMIT, CFG_SERVER_WEBROOT, check_path(), checkOptionString(), CONFIG_XML_VERSION, CONTENT_TYPE_AVI, CONTENT_TYPE_DVD, CONTENT_TYPE_FLAC, CONTENT_TYPE_JPG, CONTENT_TYPE_MP3, CONTENT_TYPE_MP4, CONTENT_TYPE_MPEG, CONTENT_TYPE_OGG, CONTENT_TYPE_PCM, CONTENT_TYPE_PLAYLIST, createArrayFromNodeset(), createAutoscanListFromNodeset(), createDictionaryFromNodeset(), DEFAULT_ACCOUNTS_EN_VALUE, DEFAULT_ALIVE_INTERVAL, DEFAULT_BOOKMARK_FILE, DEFAULT_CASE_SENSITIVE_EXTENSION_MAPPINGS, DEFAULT_COMMON_SCRIPT, DEFAULT_DVD_SCRIPT, DEFAULT_EXTEND_PROTOCOLINFO, DEFAULT_FALLBACK_CHARSET, DEFAULT_FILESYSTEM_CHARSET, DEFAULT_HIDDEN_FILES_VALUE, DEFAULT_HIDE_PC_DIRECTORY, DEFAULT_IGNORE_UNKNOWN_EXTENSIONS, DEFAULT_IMPORT_SCRIPT, DEFAULT_INTERNAL_CHARSET, DEFAULT_ITEMS_PER_PAGE_1, DEFAULT_ITEMS_PER_PAGE_2, DEFAULT_ITEMS_PER_PAGE_3, DEFAULT_ITEMS_PER_PAGE_4, DEFAULT_JS_CHARSET, DEFAULT_JS_DIR, DEFAULT_LAYOUT_TYPE, DEFAULT_MARK_PLAYED_CONTENT_AUDIO, DEFAULT_MARK_PLAYED_CONTENT_IMAGE, DEFAULT_MARK_PLAYED_CONTENT_VIDEO, DEFAULT_MARK_PLAYED_ITEMS_ENABLED, DEFAULT_MARK_PLAYED_ITEMS_STRING, DEFAULT_MARK_PLAYED_ITEMS_STRING_MODE, DEFAULT_MARK_PLAYED_ITEMS_SUPPRESS_CDS_UPDATES, DEFAULT_MYSQL_ENABLED, DEFAULT_PLAYLIST_CREATE_LINK, DEFAULT_PLAYLISTS_SCRIPT, DEFAULT_POLL_INTERVAL, DEFAULT_POLL_WHEN_IDLE_VALUE, DEFAULT_PRES_URL_APPENDTO_ATTR, DEFAULT_SESSION_TIMEOUT, DEFAULT_SQLITE_ENABLED, DEFAULT_STORAGE_CACHING_ENABLED, DEFAULT_TMPDIR, DEFAULT_UI_EN_VALUE, DEFAULT_UI_SHOW_TOOLTIPS_VALUE, DEFAULT_UPNP_STRING_LIMIT, DESC_FRIENDLY_NAME, DESC_MANUFACTURER_URL, DESC_MODEL_DESCRIPTION, DESC_MODEL_NAME, DESC_MODEL_NUMBER, DESC_SERIAL_NUMBER, DIR_SEPARATOR, getBoolOption(), getElement(), getIntOption(), getOption(), InotifyScanMode, log_debug, log_info, log_warning, magic, migrate(), mime_content, NEW_AUTOSCANLIST_OPTION, NEW_BOOL_OPTION, NEW_DICT_OPTION, NEW_INT_OPTION, NEW_OPTION, NEW_STRARR_OPTION, nil, NULL, prefix_dir, prepare_path(), root, rootDoc, SET_AUTOSCANLIST_OPTION, SET_BOOL_OPTION, SET_DICT_OPTION, SET_INT_OPTION, SET_OPTION, SET_STRARR_OPTION, string_ok(), Inotify::supported(), TimedScanMode, zmm::String::toInt(), validateYesNo(), and YES.

Referenced by ConfigManager().

void ConfigManager::writeBookmark ( zmm::String  ip,
zmm::String  port 
)

Creates a html file that is a redirector to the current server i instance.

Definition at line 2440 of file config_manager.cc.

References _, _Exception, zmm::String::c_str(), CFG_SERVER_BOOKMARK_FILE, CFG_SERVER_UI_ENABLED, construct_path(), filename, getBoolOption(), getOption(), http_redirect_to(), zmm::String::length(), and NULL.


Field Documentation

mt_atomic_t zmm::Object::_ref_count [protected, inherited]
String ConfigManager::config_dir = _(DEFAULT_CONFIG_HOME) [static, protected]
bool ConfigManager::debug_logging = false [static, protected]

Definition at line 288 of file config_manager.h.

Referenced by isDebugLogging(), and setStaticArgs().

String ConfigManager::filename = nil [static, protected]
zmm::Ref<ConfigManager > Singleton< ConfigManager >::instance [static, protected, inherited]

Definition at line 91 of file singleton.h.

String ConfigManager::magic = nil [static, protected]

Definition at line 287 of file config_manager.h.

Referenced by createDefaultConfig(), setStaticArgs(), validate(), and ~ConfigManager().

Definition at line 293 of file config_manager.h.

Referenced by validate().

zmm::Ref<Mutex> Singleton< ConfigManager >::mutex [static, protected, inherited]

Reimplemented from zmm::Object.

Definition at line 90 of file singleton.h.

String ConfigManager::prefix_dir = _(PACKAGE_DATADIR) [static, protected]

Definition at line 286 of file config_manager.h.

Referenced by createDefaultConfig(), setStaticArgs(), validate(), and ~ConfigManager().

Definition at line 290 of file config_manager.h.

Referenced by load(), save(), and validate().

bool Singleton< ConfigManager >::singletonActive [static, protected, inherited]

Definition at line 92 of file singleton.h.

String ConfigManager::userhome = nil [static, protected]

Definition at line 284 of file config_manager.h.

Referenced by ConfigManager(), setStaticArgs(), and ~ConfigManager().


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 20:16:56 2010 for MediaTomb by  doxygen 1.6.1