mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
explanation:
This commit is contained in:
parent
9ec8699eed
commit
7dbe7409ec
|
@ -16,6 +16,12 @@
|
|||
#include "ILog.h"
|
||||
#include "ITcpServer.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* @brief Get the singleton instance of TcpServerHandle
|
||||
* @param impl Optional implementation pointer to replace the current instance
|
||||
* @return The singleton instance of TcpServerHandle
|
||||
*/
|
||||
std::shared_ptr<TcpServerHandle> &TcpServerHandle::GetInstance(std::shared_ptr<TcpServerHandle> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<TcpServerHandle>();
|
||||
|
@ -30,11 +36,24 @@ std::shared_ptr<TcpServerHandle> &TcpServerHandle::GetInstance(std::shared_ptr<T
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a server
|
||||
* @param fd File descriptor of the server
|
||||
* @param server Shared pointer to the ITcpServer instance
|
||||
*/
|
||||
void TcpServerHandle::AddServer(const int &fd, const std::shared_ptr<ITcpServer> &server)
|
||||
{
|
||||
LogInfo("AddServer fd = %d\n", fd);
|
||||
mFd[fd] = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a server by file descriptor
|
||||
* @param fd File descriptor of the server
|
||||
* @param server Reference to a shared pointer to store the ITcpServer instance
|
||||
* @return True if the server is found, false otherwise
|
||||
*/
|
||||
bool TcpServerHandle::GetServer(const int &fd, std::shared_ptr<ITcpServer> &server)
|
||||
{
|
||||
auto it = mFd.find(fd);
|
||||
|
|
|
@ -20,10 +20,32 @@
|
|||
class TcpServerHandle
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
TcpServerHandle() = default;
|
||||
/**
|
||||
* @brief Default destructor
|
||||
*/
|
||||
~TcpServerHandle() = default;
|
||||
/**
|
||||
* @brief Get the singleton instance of TcpServerHandle
|
||||
* @param impl Optional implementation pointer to replace the current instance
|
||||
* @return The singleton instance of TcpServerHandle
|
||||
*/
|
||||
static std::shared_ptr<TcpServerHandle> &GetInstance(std::shared_ptr<TcpServerHandle> *impl = nullptr);
|
||||
/**
|
||||
* @brief Add a server
|
||||
* @param fd File descriptor of the server
|
||||
* @param server Shared pointer to the ITcpServer instance
|
||||
*/
|
||||
void AddServer(const int &fd, const std::shared_ptr<ITcpServer> &server);
|
||||
/**
|
||||
* @brief Get a server by file descriptor
|
||||
* @param fd File descriptor of the server
|
||||
* @param server Reference to a shared pointer to store the ITcpServer instance
|
||||
* @return True if the server is found, false otherwise
|
||||
*/
|
||||
bool GetServer(const int &fd, std::shared_ptr<ITcpServer> &server);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user