-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More infrastructure for the gateway app.
- Loading branch information
Showing
12 changed files
with
285 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "GatewayIoClientAcceptor.h" | ||
|
||
#include "GatewayIoClientAcceptor_Udp.h" | ||
|
||
#include <cassert> | ||
#include <type_traits> | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
GatewayIoClientAcceptor::~GatewayIoClientAcceptor() = default; | ||
|
||
GatewayIoClientAcceptor::Ptr GatewayIoClientAcceptor::create(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config) | ||
{ | ||
using CreateFunc = Ptr (*)(boost::asio::io_context&, const cc_mqttsn_gateway::Config&); | ||
static const CreateFunc Map[] = { | ||
/* ClientConnectionType_Udp */ &GatewayIoClientAcceptor_Udp::create, | ||
}; | ||
static const std::size_t MapSize = std::extent<decltype(Map)>::value; | ||
static_assert(MapSize == cc_mqttsn_gateway::Config::ClientConnectionType_ValuesLimit); | ||
|
||
auto idx = static_cast<unsigned>(config.clientConnectionType()); | ||
if (MapSize <= idx) { | ||
return Ptr(); | ||
} | ||
|
||
auto func = Map[idx]; | ||
if (func == nullptr) { | ||
return Ptr(); | ||
} | ||
|
||
return func(io, config); | ||
} | ||
|
||
bool GatewayIoClientAcceptor::start() | ||
{ | ||
if (!m_newConnectionReportCb) { | ||
return false; | ||
} | ||
|
||
return startImpl(); | ||
} | ||
|
||
void GatewayIoClientAcceptor::reportNewConnection(GatewayIoClientSocketPtr socket) | ||
{ | ||
assert(m_newConnectionReportCb); | ||
m_newConnectionReportCb(std::move(socket)); | ||
} | ||
|
||
|
||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "GatewayIoClientSocket.h" | ||
|
||
#include "cc_mqttsn_gateway/Config.h" | ||
|
||
#include <boost/asio.hpp> | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
class GatewayIoClientAcceptor | ||
{ | ||
public: | ||
using Ptr = std::unique_ptr<GatewayIoClientAcceptor>; | ||
using NewConnectionReportCb = std::function<void (GatewayIoClientSocketPtr)>; | ||
|
||
virtual ~GatewayIoClientAcceptor(); | ||
|
||
static Ptr create(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config); | ||
|
||
bool start(); | ||
|
||
template <typename TFunc> | ||
void setNewConnectionReportCb(TFunc&& func) | ||
{ | ||
m_newConnectionReportCb = std::forward<TFunc>(func); | ||
} | ||
|
||
protected: | ||
GatewayIoClientAcceptor(boost::asio::io_context& io) : | ||
m_io(io) | ||
{ | ||
}; | ||
|
||
virtual bool startImpl() = 0; | ||
|
||
boost::asio::io_context& io() | ||
{ | ||
return m_io; | ||
} | ||
|
||
void reportNewConnection(GatewayIoClientSocketPtr socket); | ||
|
||
private: | ||
boost::asio::io_context& m_io; | ||
NewConnectionReportCb m_newConnectionReportCb; | ||
}; | ||
|
||
using GatewayIoClientAcceptorPtr = GatewayIoClientAcceptor::Ptr; | ||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "GatewayIoClientAcceptor_Udp.h" | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
GatewayIoClientAcceptor_Udp::GatewayIoClientAcceptor_Udp(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config) : | ||
Base(io) | ||
{ | ||
static_cast<void>(config); | ||
} | ||
|
||
GatewayIoClientAcceptor_Udp::~GatewayIoClientAcceptor_Udp() = default; | ||
|
||
GatewayIoClientAcceptor_Udp::Ptr GatewayIoClientAcceptor_Udp::create(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config) | ||
{ | ||
return std::make_unique<GatewayIoClientAcceptor_Udp>(io, config); | ||
} | ||
|
||
bool GatewayIoClientAcceptor_Udp::startImpl() | ||
{ | ||
// TODO | ||
return false; | ||
} | ||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "GatewayIoClientAcceptor.h" | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
class GatewayIoClientAcceptor_Udp : public GatewayIoClientAcceptor | ||
{ | ||
using Base = GatewayIoClientAcceptor; | ||
public: | ||
GatewayIoClientAcceptor_Udp(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config); | ||
virtual ~GatewayIoClientAcceptor_Udp(); | ||
|
||
static Ptr create(boost::asio::io_context& io, const cc_mqttsn_gateway::Config& config); | ||
|
||
protected: | ||
virtual bool startImpl() override; | ||
|
||
private: | ||
}; | ||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "GatewayIoClientSocket.h" | ||
|
||
#include <type_traits> | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
GatewayIoClientSocket::~GatewayIoClientSocket() = default; | ||
|
||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "cc_mqttsn_gateway/Config.h" | ||
|
||
#include <boost/asio.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace cc_mqttsn_gateway_app | ||
{ | ||
|
||
class GatewayIoClientSocket | ||
{ | ||
public: | ||
virtual ~GatewayIoClientSocket(); | ||
|
||
bool start() | ||
{ | ||
return startImpl(); | ||
} | ||
|
||
protected: | ||
GatewayIoClientSocket(boost::asio::io_context& io) : | ||
m_io(io) | ||
{ | ||
}; | ||
|
||
virtual bool startImpl() = 0; | ||
|
||
boost::asio::io_context& io() | ||
{ | ||
return m_io; | ||
} | ||
|
||
private: | ||
boost::asio::io_context& m_io; | ||
}; | ||
|
||
using GatewayIoClientSocketPtr = std::unique_ptr<GatewayIoClientSocket>; | ||
|
||
} // namespace cc_mqttsn_gateway_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters