softwarecontainer  0.18.0-739e8d7 2017-05-04
configdefinition.h
1 /*
2  * Copyright (C) 2016-2017 Pelagicore AB
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  *
17  * For further information see LICENSE
18  */
19 
20 #pragma once
21 
22 #include "softwarecontainer-common.h"
23 #include "configtypes.h"
24 
25 
26 namespace softwarecontainer {
27 
28 /*
29  * Used for the group-key combination that makes configs unique
30  */
31 typedef std::pair<std::string, std::string> UniqueKey;
32 
33 /*
34  * Defines configs, as group and key, to be considered mandatory by Config
35  *
36  * A call to ConfigDefinition::mandatory will return an object of this type which is
37  * intended to be used when creating a Config object.
38  *
39  * Normally, code external to ConfigDefinition should not create objects of type
40  * MandatoryConfigs, but it is available for e.g test code that needs to explicitly
41  * control the content.
42  */
43 typedef std::vector<UniqueKey> MandatoryConfigs;
44 
45 /*
46  * Maps a dependee config to a list of dependencies. This is passed to Config
47  * on creation.
48  */
49 typedef std::map<UniqueKey, std::vector<UniqueKey>> ConfigDependencies;
50 
51 /*
52  * Maps a config to a ConfigType. This is passed to Config on creation.
53  */
54 typedef std::map<UniqueKey, ConfigType> TypeMap;
55 
56 /*
57  * Used internally by ConfigDefinition to mark configs to be mandatory or optional
58  */
59 typedef bool MandatoryFlag;
60 
61 
63 {
64 public:
65  // Illegal values used as initial command line option values to check if user
66  // set them or not
67  static const std::string SC_CONFIG_PATH_INITIAL_VALUE;
68  static const int SHUTDOWN_TIMEOUT_INITIAL_VALUE;
69  static const std::string SERVICE_MANIFEST_DIR_INITIAL_VALUE;
70  static const std::string DEFAULT_SERVICE_MANIFEST_DIR_INITIAL_VALUE;
71  static const bool USE_SESSION_BUS_INITIAL_VALUE;
72 
73  // Config group "SoftwareContainer"
74  static const std::string SC_GROUP;
75 
76  // Config keys for SoftwareContainer group
77  static const std::string SC_USE_SESSION_BUS_KEY;
78  static const std::string SC_SHUTDOWN_TIMEOUT_KEY;
79  static const std::string SC_SHARED_MOUNTS_DIR_KEY;
80  static const std::string SC_LXC_CONFIG_PATH_KEY;
81  static const std::string SC_SERVICE_MANIFEST_DIR_KEY;
82  static const std::string SC_DEFAULT_SERVICE_MANIFEST_DIR_KEY;
83 
84 #ifdef ENABLE_NETWORKGATEWAY
85  static const std::string SC_CREATE_BRIDGE_KEY;
86  static const std::string SC_BRIDGE_DEVICE_KEY;
87  static const std::string SC_BRIDGE_IP_KEY;
88  static const std::string SC_BRIDGE_NETADDR_KEY;
89  static const std::string SC_BRIDGE_NETMASK_KEY;
90  static const std::string SC_BRIDGE_NETMASK_BITLENGTH_KEY;
91 #endif
92 
93  static MandatoryConfigs mandatory();
94  static ConfigDependencies dependencies();
95  static TypeMap typeMap();
96  static MandatoryFlag convertDefineToFlag(bool definition);
97 };
98 
99 } // namespace softwarecontainer
Developers guide to adding a config item: