Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyTemplate.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: DobbyTemplate.h
21 *
22 */
23#ifndef DOBBYTEMPLATE_H
24#define DOBBYTEMPLATE_H
25
26// Some ctemplate classes have a variable that triggers the -Wshadow gcc warning.
27// However it is benign, therefore we temporary disable the warning here.
28#pragma GCC diagnostic push
29# pragma GCC diagnostic ignored "-Wshadow"
30# include <ctemplate/template.h>
31#pragma GCC diagnostic pop
32
33#include <pthread.h>
34
35#include <memory>
36#include <string>
37#include <list>
38
39
40class IDobbySettings;
41
42
43// -----------------------------------------------------------------------------
52{
53private:
55 static void cleanUp();
56
57private:
58 const ctemplate::TemplateString mTemplateKey;
59 const std::unique_ptr<ctemplate::TemplateCache> mTemplateCache;
60
61 static DobbyTemplate* instance();
62
63 void setTemplateDevNodes(const std::list<std::string>& devNodes);
64 void setTemplateEnvVars(const std::map<std::string, std::string>& envVars);
67
68 void _setSettings(const std::shared_ptr<const IDobbySettings>& settings);
69
70 std::string _apply(const ctemplate::TemplateDictionaryInterface* dictionary,
71 bool prettyPrint) const;
72
73 bool _applyAt(int dirFd, const std::string& fileName,
74 const ctemplate::TemplateDictionaryInterface* dictionary,
75 bool prettyPrint) const;
76
77public:
78 static void setSettings(const std::shared_ptr<const IDobbySettings>& settings);
79
80 static std::string apply(const ctemplate::TemplateDictionaryInterface* dictionary,
81 bool prettyPrint);
82
83 static bool applyAt(int dirFd, const std::string& fileName,
84 const ctemplate::TemplateDictionaryInterface* dictionary,
85 bool prettyPrint);
86
87private:
88 std::map<std::string, std::string> mExtraEnvVars;
89
90private:
91 static pthread_rwlock_t mInstanceLock;
92 static DobbyTemplate* mInstance;
93};
94
95
96#endif // !defined(DOBBYTEMPLATE_H)
Singleton class that returns the OCI JSON template.
Definition DobbyTemplate.h:52
static void setSettings(const std::shared_ptr< const IDobbySettings > &settings)
Applies the settings to the global template values.
Definition DobbyTemplate.cpp:138
void setTemplateCpuRtSched()
Determines if the kernel's CONFIG_RT_GROUP_SCHED is set or not.
Definition DobbyTemplate.cpp:451
std::string _apply(const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint) const
Applies the dictionary to the template.
Definition DobbyTemplate.cpp:530
static std::string apply(const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint)
Applies the dictionary to the template.
Definition DobbyTemplate.cpp:561
static DobbyTemplate * instance()
Returns / creates singleton instance.
Definition DobbyTemplate.cpp:109
bool _applyAt(int dirFd, const std::string &fileName, const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint) const
Applies the dictionary to the template and writes the output into the file.
Definition DobbyTemplate.cpp:634
void setTemplatePlatformEnvVars()
Sets the environment variables used to identify the platform.
Definition DobbyTemplate.cpp:393
static void cleanUp()
Called at shutdown time to clean up the singleton.
Definition DobbyTemplate.cpp:90
static bool applyAt(int dirFd, const std::string &fileName, const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint)
Applies the dictionary to the template and writes the output into the file.
Definition DobbyTemplate.cpp:697
void setTemplateDevNodes(const std::list< std::string > &devNodes)
Sets up the global template values for the device nodes.
Definition DobbyTemplate.cpp:241
void _setSettings(const std::shared_ptr< const IDobbySettings > &settings)
Applies the settings to the global template values.
Definition DobbyTemplate.cpp:149
void setTemplateEnvVars(const std::map< std::string, std::string > &envVars)
Converts the envVars map to json formatted string and sets it as the EXTRA_ENV_VARS template value.
Definition DobbyTemplate.cpp:362
Interface provided to the library at startup, contains the configuration options for Dobby.
Definition IDobbySettings.h:50