26 std::shared_ptr<ContainerAbstractInterface> container,
28 m_activatedOnce(false),
30 m_container(container),
31 m_isDynamic(isDynamic),
32 m_state(GatewayState::CREATED)
43 if (GatewayState::ACTIVATED == m_state && !m_isDynamic) {
44 std::string message =
"Can not configure a gateway that is already activated " 45 "if the gateway does not support dynamic behavior. " 46 "Gateway ID: " +
id();
47 log_error() << message;
51 if (!json_is_array(config)) {
52 log_error() <<
"Root JSON element is not an array";
56 if (json_array_size(config) == 0) {
57 log_error() <<
"Root JSON array is empty";
61 for(
size_t i = 0; i < json_array_size(config); i++) {
62 json_t *element = json_array_get(config, i);
63 if (!json_is_object(element)) {
64 log_error() <<
"json configuration is not an object";
69 log_warning() <<
"Could not read config element";
74 m_state = GatewayState::CONFIGURED;
79 if (GatewayState::ACTIVATED == m_state && !m_isDynamic) {
80 std::string message =
"Can not activate a gateway that is already activated " 81 "if the gateway does not support dynamic behavior. " 82 "Gateway ID: " +
id();
83 log_error() << message;
87 if (GatewayState::CONFIGURED != m_state) {
88 std::string message =
"Activate was called on a gateway which is not in configured state. " 89 "Gateway ID: " +
id();
90 log_error() << message;
94 if (!activateGateway()) {
95 log_error() <<
"Couldn't activate gateway: " <<
id();
99 m_state = GatewayState::ACTIVATED;
107 if (GatewayState::ACTIVATED != m_state && !m_activatedOnce) {
108 std::string message =
"Teardown called on non-activated gateway. Gateway ID: " +
id();
109 log_error() << message;
113 if (!teardownGateway()) {
114 log_error() <<
"Could not tear down gateway: " <<
id();
119 m_state = GatewayState::CREATED;
123 m_activatedOnce =
false;
130 std::shared_ptr<ContainerAbstractInterface> ptrCopy = m_container;
136 return m_state >= GatewayState::CONFIGURED;
144 return m_activatedOnce;
148 return m_state >= GatewayState::ACTIVATED;
virtual bool isActivated()
Is the gateway activated or not?
virtual bool setConfig(const json_t *config)
Configure this gateway according to the supplied JSON configuration string.
virtual bool isConfigured()
Is the gateway configured or not?
virtual std::string id() const
Returns the ID of the gateway.
virtual bool activate()
Applies any configuration set by setConfig()
virtual bool teardown()
Restore system to the state prior to launching of gateway.
Gateway(const std::string &id, std::shared_ptr< ContainerAbstractInterface > container, bool isDynamic=false)
Constructor for inheriting classes to initilize.
std::shared_ptr< ContainerAbstractInterface > getContainer()
Get a handle to the associated container.
Developers guide to adding a config item:
virtual bool readConfigElement(const json_t *element)=0
Gateway specific parsing of config elements.