|
| 1 | +// Copyright Copyright (c) Kang Lin studio, All Rights Reserved |
| 2 | +// Author: Kang Lin <kl222@126.com> |
| 3 | + |
| 4 | +#include <QLoggingCategory> |
| 5 | +#include "BackendFtpServer.h" |
| 6 | +#include "OperateFtpServer.h" |
| 7 | +static Q_LOGGING_CATEGORY(log, "FtpServer.Backend") |
| 8 | +CBackendFtpServer::CBackendFtpServer(COperate *pOperate) : CBackend(pOperate) |
| 9 | + , m_pServer(nullptr) |
| 10 | +{ |
| 11 | + qDebug(log) << Q_FUNC_INFO; |
| 12 | + m_Para = ((COperateFtpServer*)pOperate)->GetParameter(); |
| 13 | +} |
| 14 | + |
| 15 | +CBackendFtpServer::~CBackendFtpServer() |
| 16 | +{ |
| 17 | + qDebug(log) << Q_FUNC_INFO; |
| 18 | +} |
| 19 | + |
| 20 | +CBackend::OnInitReturnValue CBackendFtpServer::OnInit() |
| 21 | +{ |
| 22 | + qDebug(log) << Q_FUNC_INFO; |
| 23 | + if(m_pServer) { |
| 24 | + qCritical(log) << "Server is exist"; |
| 25 | + return OnInitReturnValue::Fail; |
| 26 | + } |
| 27 | + m_pServer = new FtpServer(this, m_Para->GetRoot(), m_Para->GetPort(), |
| 28 | + m_Para->GetUser(), m_Para->GetPassword(), |
| 29 | + m_Para->GetReadOnly(), m_Para->GetAnonymousLogin()); |
| 30 | + if(m_pServer->isListening()) { |
| 31 | + qInfo(log) << "The ftp server listen in" << m_Para->GetPort(); |
| 32 | + emit sigRunning(); |
| 33 | + } else { |
| 34 | + QString szErr = tr("The ftp server is not listening in %1").arg(m_Para->GetPort()); |
| 35 | + emit sigError(-1, szErr); |
| 36 | + } |
| 37 | + return OnInitReturnValue::NotUseOnProcess; |
| 38 | +} |
| 39 | + |
| 40 | +int CBackendFtpServer::OnClean() |
| 41 | +{ |
| 42 | + qDebug(log) << Q_FUNC_INFO; |
| 43 | + |
| 44 | + if(m_pServer) |
| 45 | + delete m_pServer; |
| 46 | + |
| 47 | + return 0; |
| 48 | +} |
0 commit comments