remove smart pointer of ftp server

This commit is contained in:
Peter Buchegger 2021-05-19 01:03:35 +02:00
parent 1f7f56ecfa
commit bfa7b5467d
2 changed files with 8 additions and 9 deletions

View file

@ -13,30 +13,29 @@ FTPTask::~FTPTask() {
}
bool FTPTask::setup(System &system) {
_ftpServer = std::shared_ptr<FTPServer>(new FTPServer());
for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) {
logPrintD("Adding user to FTP Server: ");
logPrintlnD(user.name);
_ftpServer->addUser(user.name, user.password);
_ftpServer.addUser(user.name, user.password);
}
_ftpServer->addFilesystem("SPIFFS", &SPIFFS);
_ftpServer.addFilesystem("SPIFFS", &SPIFFS);
_stateInfo = "waiting";
return true;
}
bool FTPTask::loop(System &system) {
if (!_beginCalled) {
_ftpServer->begin();
_ftpServer.begin();
_beginCalled = true;
}
_ftpServer->handle();
_ftpServer.handle();
static bool configWasOpen = false;
if (configWasOpen && _ftpServer->countConnections() == 0) {
if (configWasOpen && _ftpServer.countConnections() == 0) {
logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config...");
logPrintlnW("");
ESP.restart();
}
if (_ftpServer->countConnections() > 0) {
if (_ftpServer.countConnections() > 0) {
configWasOpen = true;
_stateInfo = "has connection";
}

View file

@ -13,8 +13,8 @@ public:
virtual bool loop(System &system) override;
private:
std::shared_ptr<FTPServer> _ftpServer;
bool _beginCalled;
FTPServer _ftpServer;
bool _beginCalled;
};
#endif