Project

General

Profile

Actions

Feature #9939

open

Consider exposing configuration as an API

Added by Roel Standaert over 2 years ago. Updated about 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
Start date:
03/16/2022
Due date:
% Done:

0%

Estimated time:

Description

At the moment we read configuration from XML files (wt_config.xml), and wthttp command line arguments.

These are kept in classes that are not part of the public API.

We often get questions asking how to retrieve these configuration options in code, however, where the answer is a rather unsatisfying "if there's no WServer function that allows you to check it you'll have to parse the XML or command line arguments yourself".

Often enough there's the need to set those configuration options in code as well, for example when the user has their own configuration system for the rest of their software, where the answer has been "you'll have to write those out as a string or a file".

I think we should have a configuration class that is exposed in the API, that has a function to read it from XML, but also allows to set the options in plain old C++ code. We could similarly expose one for wthttp specifically. This one would only be usable if the user is using wthttp, but it doesn't really make sense to use anything else.

Actions #1

Updated by Roel Standaert about 2 years ago

The public interface of the Configuration class would probably be something like this:

class Configuration {
public:
  //! Create default configuration
  Configuration();

  /*!
   * \brief Create configuration from XML file
   *
   * Equivalent to:
   * 
   * ```cpp
   * Configuration configuration;
   * configuration.loadXml(xmlFile, applicationPath);
   * ```
   */
   explicit Configuration(const std::string& xmlFile, const std::string& applicationPath);

   //! Load configuration from XML file
   void loadXml(const std::string& xmlFile, const std::string& applicationPath);

   // In the future, we may perhaps have a function to write the configuration to XML

   // Getters and setters for all of the various configuration options
};
Actions

Also available in: Atom PDF