softwarecontainer  0.18.0-739e8d7 2017-05-04
devicenode.h
1 /*
2  * Copyright (C) 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 "containerabstractinterface.h"
24 #include "jsonparser.h"
25 
26 
27 namespace softwarecontainer {
28 
29 class Device
30 {
31  LOG_DECLARE_CLASS_CONTEXT("DN", "Device Node");
32 
33 public:
34  Device(std::string name = "", int mode = -1);
35  /*
36  * @brief Copy constructor
37  */
38  Device(const Device &dev);
39 
46  bool parse(const json_t *element);
47 
54  bool activate(std::shared_ptr<ContainerAbstractInterface> container);
55 
56  /*
57  * @brief Calculate the device node mode after applying white-listing policy
58  * i.e. if the appliedMode is 706 and storedMode is 622 then the calculated mode will be 726
59  *
60  * @return integer value representing new device mode
61  */
62  void calculateDeviceMode(const int appliedMode);
63 
64  /* needed getters */
65  const std::string getName();
66  int getMode();
67  bool getIsconfigured ();
68 
69  /* needed setters*/
70  void setMode(int _mode);
71 
72 private:
73  std::string m_name;
74  /*
75  * @brief Holds device mode which consist 3 integer number between 0 and 7 which represents
76  * permissions for owner, groups and all users
77  * */
78  int m_mode;
79 
80  /*
81  * @brief Holds the flag that whether the device is configured or not
82  */
83  bool m_isConfigured;
84 };
85 
86 } // namespace softwarecontainer
bool activate(std::shared_ptr< ContainerAbstractInterface > container)
Activates this device by running mknod and chmod commands which are run in the container.
Definition: devicenode.cpp:63
bool parse(const json_t *element)
Configures this device by parsing the supplied JSON configuration string.
Definition: devicenode.cpp:39
Developers guide to adding a config item: