softwarecontainer  0.18.0-739e8d7 2017-05-04
softwarecontainer::DBusGateway Class Reference
Inheritance diagram for softwarecontainer::DBusGateway:
[legend]
Collaboration diagram for softwarecontainer::DBusGateway:
[legend]

Public Types

enum  GatewayState : unsigned int { CREATED, CONFIGURED, ACTIVATED }
 

Public Member Functions

 DBusGateway (const std::string &gatewayDir, std::shared_ptr< ContainerAbstractInterface > container)
 
virtual bool setConfig (const json_t *config) override
 Sets config for both dbus session instances. More...
 
virtual bool activate () override
 Activates both dbus session instances. More...
 
virtual bool readConfigElement (const json_t *) override
 Stubbed since this class only does containment. More...
 
virtual bool activateGateway () override
 Stubbed since this class only does containment. More...
 
virtual bool teardownGateway () override
 Stubbed since this class only does containment. More...
 
virtual bool teardown () override
 Restore system to the state prior to launching of gateway. More...
 
virtual bool isConfigured () override
 Is the gateway configured or not? More...
 
virtual bool isActivated () override
 Is the gateway activated or not? More...
 
virtual std::string id () const
 Returns the ID of the gateway. More...
 

Static Public Attributes

static constexpr const char * ID
 

Protected Member Functions

std::shared_ptr< ContainerAbstractInterfacegetContainer ()
 Get a handle to the associated container. More...
 
bool setEnvironmentVariable (const std::string &variable, const std::string &value)
 Set an environment variable in the associated container. More...
 

Protected Attributes

bool m_activatedOnce
 

Detailed Description

Definition at line 27 of file dbusgateway.h.

Member Function Documentation

bool softwarecontainer::DBusGateway::setConfig ( const json_t *  config)
overridevirtual

Sets config for both dbus session instances.

Reimplemented from softwarecontainer::Gateway.

Definition at line 37 of file dbusgateway.cpp.

38 {
39  try {
40  log_debug() << "Setting config for dbus session bus";
41  bool sessionBusParseResult = sessionBus.setConfig(config);
42 
43  log_debug() << "Setting config for dbus system bus";
44  bool systemBusParseResult = systemBus.setConfig(config);
45 
46  if (!sessionBusParseResult && !systemBusParseResult) {
47  log_error() << "Neither session nor system bus could use the given config";
48  return false;
49  }
50  } catch (GatewayParserError &err) {
51  log_error() << "Bad config in one of the gateway configurations";
52  return false;
53  }
54 
55  return true;
56 }
virtual bool setConfig(const json_t *config)
Configure this gateway according to the supplied JSON configuration string.
Definition: gateway.cpp:41
bool softwarecontainer::DBusGateway::activate ( )
overridevirtual

Activates both dbus session instances.

Reimplemented from softwarecontainer::Gateway.

Definition at line 58 of file dbusgateway.cpp.

59 {
60  bool sessionBusActivationResult = false;
61  if (sessionBus.isConfigured()) {
62  log_debug() << "Activating dbus session bus";
63  sessionBusActivationResult = sessionBus.activate();
64  }
65 
66  bool systemBusActivationResult = false;
67  if (systemBus.isConfigured()) {
68  log_debug() << "Activating dbus system bus";
69  sessionBusActivationResult = systemBus.activate();
70  }
71 
72  if (!sessionBusActivationResult && !systemBusActivationResult) {
73  log_error() << "Neither dbus session bus nor dbus system bus could be activated";
74  return false;
75  }
76  return true;
77 }
virtual bool isConfigured()
Is the gateway configured or not?
Definition: gateway.cpp:134
virtual bool activate()
Applies any configuration set by setConfig()
Definition: gateway.cpp:78
virtual bool softwarecontainer::DBusGateway::readConfigElement ( const json_t *  )
inlineoverridevirtual

Stubbed since this class only does containment.

Implements softwarecontainer::Gateway.

Definition at line 51 of file dbusgateway.h.

51 { return true; }
virtual bool softwarecontainer::DBusGateway::activateGateway ( )
inlineoverridevirtual

Stubbed since this class only does containment.

Implements softwarecontainer::Gateway.

Definition at line 56 of file dbusgateway.h.

56 { return true; }
virtual bool softwarecontainer::DBusGateway::teardownGateway ( )
inlineoverridevirtual

Stubbed since this class only does containment.

Implements softwarecontainer::Gateway.

Definition at line 61 of file dbusgateway.h.

References isActivated(), isConfigured(), and teardown().

61 { return true; }

Here is the call graph for this function:

bool softwarecontainer::DBusGateway::teardown ( )
overridevirtual

Restore system to the state prior to launching of gateway.

Any cleanup code (removal of files, virtual interfaces, etc) should be placed here.

Returns
true upon successful clean-up, false otherwise
Exceptions
GatewayErrorIf called on a non activated gateway.

Reimplemented from softwarecontainer::Gateway.

Definition at line 79 of file dbusgateway.cpp.

Referenced by teardownGateway().

80 {
81  bool sessionBusTeardownResult;
82  if (sessionBus.isActivated()) {
83  log_debug() << "Tearing down dbus session bus";
84  sessionBusTeardownResult = sessionBus.teardown();
85  } else {
86  sessionBusTeardownResult = false;
87  }
88 
89  bool systemBusTeardownResult;
90  if (systemBus.isActivated()) {
91  log_debug() << "Tearing down dbus system bus";
92  systemBusTeardownResult = systemBus.teardown();
93  } else {
94  systemBusTeardownResult = false;
95  }
96 
97  if (!sessionBusTeardownResult && !systemBusTeardownResult) {
98  log_error() << "Neither dbus session bus nor dbus system bus could be tore down";
99  return false;
100  }
101 
102  return true;
103 }
virtual bool isActivated()
Is the gateway activated or not?
Definition: gateway.cpp:139
virtual bool teardown()
Restore system to the state prior to launching of gateway.
Definition: gateway.cpp:103

Here is the caller graph for this function:

bool softwarecontainer::DBusGateway::isConfigured ( )
overridevirtual

Is the gateway configured or not?

Reimplemented from softwarecontainer::Gateway.

Definition at line 105 of file dbusgateway.cpp.

Referenced by teardownGateway().

106 {
107  return sessionBus.isConfigured() || systemBus.isConfigured();
108 }
virtual bool isConfigured()
Is the gateway configured or not?
Definition: gateway.cpp:134

Here is the caller graph for this function:

bool softwarecontainer::DBusGateway::isActivated ( )
overridevirtual

Is the gateway activated or not?

Dynamic gateways will return true if they have been activated at least once. Non-dynamic gateways will return true if they are in state ACTIVATED

Reimplemented from softwarecontainer::Gateway.

Definition at line 110 of file dbusgateway.cpp.

Referenced by teardownGateway().

111 {
112  return sessionBus.isActivated() || systemBus.isActivated();
113 }
virtual bool isActivated()
Is the gateway activated or not?
Definition: gateway.cpp:139

Here is the caller graph for this function:

std::string softwarecontainer::Gateway::id ( ) const
virtualinherited

Returns the ID of the gateway.

Returns
Returns the ID of the gateway as a string

Definition at line 36 of file gateway.cpp.

Referenced by softwarecontainer::Gateway::activate(), softwarecontainer::DBusGatewayInstance::DBusGatewayInstance(), softwarecontainer::Gateway::setConfig(), and softwarecontainer::Gateway::teardown().

37 {
38  return m_id;
39 }

Here is the caller graph for this function:

std::shared_ptr< ContainerAbstractInterface > softwarecontainer::Gateway::getContainer ( )
protectedinherited

Get a handle to the associated container.

Exceptions
GatewayErrorIf called before setContainer() has been called.

Definition at line 128 of file gateway.cpp.

Referenced by softwarecontainer::NetworkGateway::activateGateway(), softwarecontainer::DBusGatewayInstance::activateGateway(), softwarecontainer::WaylandGateway::readConfigElement(), and softwarecontainer::NetworkGateway::teardownGateway().

129 {
130  std::shared_ptr<ContainerAbstractInterface> ptrCopy = m_container;
131  return ptrCopy;
132 }

Here is the caller graph for this function:

bool softwarecontainer::Gateway::setEnvironmentVariable ( const std::string &  variable,
const std::string &  value 
)
protectedinherited

Set an environment variable in the associated container.


The documentation for this class was generated from the following files: