refs #681, using FSD setup in server

This commit is contained in:
Klaus Basan
2016-06-27 01:58:01 +02:00
parent 75a7ca382c
commit c133ad04c7
6 changed files with 44 additions and 11 deletions

View File

@@ -8,6 +8,7 @@
*/
#include "blackmisc/network/server.h"
#include "blackmisc/stringutils.h"
#include "blackmisc/logcategory.h"
#include "blackmisc/logcategorylist.h"
#include "blackmisc/propertyindex.h"
@@ -21,6 +22,9 @@ namespace BlackMisc
{
namespace Network
{
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections)
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections) {}
QString CServer::convertToQString(bool i18n) const
{
QString s(this->m_name);
@@ -28,7 +32,8 @@ namespace BlackMisc
s.append(" ").append(this->m_address);
s.append(" ").append(QString::number(this->m_port));
s.append(" ").append(this->m_user.toQString(i18n));
s.append(" ").append(this->m_isAcceptingConnections ? "true" : "false");
s.append(" ").append(boolToYesNo(this->m_isAcceptingConnections));
s.append(" ").append(this->m_fsdSetup.toQString(i18n));
return s;
}
@@ -69,6 +74,7 @@ namespace BlackMisc
if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); }
if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Wrong port")); }
msgs.push_back(this->getUser().validate());
msgs.push_back(this->getFsdSetup().validate());
msgs.addCategories(cats);
return msgs;
}
@@ -89,6 +95,8 @@ namespace BlackMisc
return CVariant::fromValue(this->m_port);
case IndexUser:
return this->m_user.propertyByIndex(index.copyFrontRemoved());
case IndexFsdSetup:
return this->m_fsdSetup.propertyByIndex(index.copyFrontRemoved());
case IndexIsAcceptingConnections:
return CVariant::fromValue(this->m_isAcceptingConnections);
default:
@@ -117,6 +125,9 @@ namespace BlackMisc
case IndexUser:
this->m_user.setPropertyByIndex(index.copyFrontRemoved(), variant);
break;
case IndexFsdSetup:
this->m_fsdSetup.setPropertyByIndex(index.copyFrontRemoved(), variant);
break;
case IndexIsAcceptingConnections:
this->setIsAcceptingConnections(variant.value<bool>());
break;
@@ -125,6 +136,5 @@ namespace BlackMisc
break;
}
}
} // namespace
} // namespace

View File

@@ -15,6 +15,7 @@
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/network/user.h"
#include "blackmisc/network/fsdsetup.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/valueobject.h"
@@ -39,6 +40,7 @@ namespace BlackMisc
IndexAddress,
IndexPort,
IndexUser,
IndexFsdSetup,
IndexIsAcceptingConnections
};
@@ -46,8 +48,7 @@ namespace BlackMisc
CServer() {}
//! Constructor.
CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections = true)
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections) {}
CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections = true);
//! Get address.
const QString &getAddress() const { return m_address; }
@@ -100,6 +101,12 @@ namespace BlackMisc
//! Address and port?
bool hasAddressAndPort() const;
//! Get setup
const CFsdSetup &getFsdSetup() const { return this->m_fsdSetup; }
//! Set setup
void setFsdSetup(const CFsdSetup &setup) { this->m_fsdSetup = setup; }
//! Validate, provide details about issues
BlackMisc::CStatusMessageList validate() const;
@@ -113,12 +120,13 @@ namespace BlackMisc
QString convertToQString(bool i18n = false) const;
private:
QString m_name;
QString m_description;
QString m_address;
int m_port = -1;
CUser m_user;
bool m_isAcceptingConnections = true; //!< temp. disable server
QString m_name;
QString m_description;
QString m_address;
int m_port = -1;
CUser m_user;
CFsdSetup m_fsdSetup;
bool m_isAcceptingConnections = true; //!< temp. disable server
BLACK_METACLASS(
CServer,
@@ -127,6 +135,7 @@ namespace BlackMisc
BLACK_METAMEMBER(address),
BLACK_METAMEMBER(port),
BLACK_METAMEMBER(user),
BLACK_METAMEMBER(fsdSetup),
BLACK_METAMEMBER(isAcceptingConnections)
);
};

View File

@@ -71,5 +71,13 @@ namespace BlackMisc
this->addIfAddressNotExists(s);
}
}
void CServerList::setFsdSetup(const CFsdSetup &setup)
{
for (CServer &s : *this)
{
s.setFsdSetup(setup);
}
}
} // namespace
} // namespace

View File

@@ -55,6 +55,9 @@ namespace BlackMisc
//! Add if address not already exists
void addIfAddressNotExists(const CServerList &servers);
//! Set FSD setup for all entries
void setFsdSetup(const CFsdSetup &setup);
};
} //namespace
} // namespace