Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DobbyContainer.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: DobbyContainer.h
21  *
22  */
23 #ifndef DOBBYCONTAINER_H
24 #define DOBBYCONTAINER_H
25 
26 #include <sys/types.h>
27 
28 #include <cstdint>
29 #include <memory>
30 #include <chrono>
31 #include <bitset>
32 #include <mutex>
33 #include <list>
34 
35 
36 class DobbyBundle;
37 class DobbyConfig;
38 class DobbyRootfs;
39 class IDobbyStream;
41 
42 // -----------------------------------------------------------------------------
59 {
60 public:
61  DobbyContainer() = delete;
62  DobbyContainer(DobbyContainer&) = delete;
63  DobbyContainer(DobbyContainer&&) = delete;
64 
65 private:
66  friend class DobbyManager;
67  DobbyContainer(const std::shared_ptr<const DobbyBundle>& _bundle,
68  const std::shared_ptr<const DobbyConfig>& _config,
69  const std::shared_ptr<const DobbyRootfs>& _rootfs);
70 
71  DobbyContainer(const std::shared_ptr<const DobbyBundle>& _bundle,
72  const std::shared_ptr<const DobbyConfig>& _config,
73  const std::shared_ptr<const DobbyRootfs>& _rootfs,
74  const std::shared_ptr<const DobbyRdkPluginManager>& _rdkPluginManager);
75 
76 public:
77  ~DobbyContainer();
78 
79 public:
80  const int32_t descriptor;
81  const std::shared_ptr<const DobbyBundle> bundle;
82  const std::shared_ptr<const DobbyConfig> config;
83  const std::shared_ptr<const DobbyRootfs> rootfs;
84  const std::shared_ptr<const DobbyRdkPluginManager> rdkPluginManager;
85 
86 public:
87  pid_t containerPid;
88  bool hasCurseOfDeath;
89  enum class State { Starting, Running, Stopping, Paused, Hibernating, Hibernated, Awakening, Unknown } state;
90  std::string customConfigFilePath;
91 
92 public:
93  void setRestartOnCrash(const std::list<int>& files);
94  void clearRestartOnCrash();
95 
96  bool shouldRestart(int statusCode);
97  const std::list<int>& files() const;
98 
99 private:
100  bool mRestartOnCrash;
101  std::list<int> mFiles;
102 
103  unsigned mRestartCount;
104  std::chrono::time_point<std::chrono::steady_clock> mLastRestartAttempt;
105 
106 private:
107  static std::mutex mIdsLock;
108  static std::bitset<1024> mUsedIds;
109 
110  static int32_t allocDescriptor();
111  static void freeDescriptor(int32_t cd);
112 
113 };
114 
115 
116 #endif // DOBBYCONTAINER_H
Simple class that just creates a subdir in the bundles directory.
Definition: DobbyBundle.h:46
Interface that configuration file parser classes have to implement.
Definition: DobbyConfig.h:66
Wrapper object used to store container resources.
Definition: DobbyContainer.h:59
static void freeDescriptor(int32_t cd)
Frees a descriptor created with allocDescriptor.
Definition: DobbyContainer.cpp:88
static int32_t allocDescriptor()
Alloc a unique descriptor from the pool.
Definition: DobbyContainer.cpp:49
The main object which starts / stops / manages the containers.
Definition: DobbyManager.h:77
Class that manages all the RDK plugin hook libraries.
Definition: DobbyRdkPluginManager.h:48
Creates a directory populated with rootfs based on the supplied container config.
Definition: DobbyRootfs.h:57
Interface for all character streams used in the daemon.
Definition: DobbyStream.h:41