mirror of https://github.com/nymea/nymea.git
Make use of system data location for searching the mac address database
parent
19e21b9dd4
commit
b3fb5b44d7
|
|
@ -1,12 +1,21 @@
|
|||
# Building the MAC address database
|
||||
|
||||
The MAC address database can be created using the `build-database.py` script. The script will download the latest registered MAC address block information from [https://macaddress.io](https://macaddress.io) and creates a SQLITE database file.
|
||||
The MAC address database can be created using the `build-database.py` script.
|
||||
The script will download the latest registered MAC address block information
|
||||
from [https://macaddress.io](https://macaddress.io) and creates a size and access optimized
|
||||
SQLITE database file.
|
||||
|
||||
The generated database is read performance optimized and tried to keep as small as possible for searching MAC address OUIs (Organizationally Unique Identifiers) blocks and returning the registered company name.
|
||||
The generated database is read performance optimized and tried to keep as small as possible for
|
||||
searching MAC address OUIs (Organizationally Unique Identifiers) blocks and returning the registered company name.
|
||||
|
||||
$ python3 build-database.py
|
||||
|
||||
The final database will be named `mac-addresses.db`.
|
||||
|
||||
In nymea the `MacAddressDatabase` will search by default for this database file in `/usr/share/nymea/mac-addresses.db` and provides an asynch threaded mechanism to get the company name for a given MAC address.
|
||||
In nymea the `MacAddressDatabase` class will provide access to this generated database and provides an asynch threaded mechanism to
|
||||
get the company name for a given MAC address.
|
||||
|
||||
The database will be searched in the system default data location `${XDG_DATA_DIRS}/nymead/`.
|
||||
|
||||
On debian package based system the database file will be installed in `/usr/share/nymea/nymead/mac-addresses.db`.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
data/mac-database/mac-addresses.db usr/share/nymea/
|
||||
data/mac-database/mac-addresses.db usr/share/nymea/nymead/
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,34 @@
|
|||
#include <QFileInfo>
|
||||
#include <QTimer>
|
||||
#include <QSqlDatabase>
|
||||
#include <QStandardPaths>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
NYMEA_LOGGING_CATEGORY(dcMacAddressDatabase, "MacAddressDatabase")
|
||||
|
||||
MacAddressDatabase::MacAddressDatabase(QObject *parent) : QObject(parent)
|
||||
{
|
||||
// Find database in system data locations
|
||||
QString databaseFileName;
|
||||
foreach (const QString &dataLocation, QStandardPaths::standardLocations(QStandardPaths::DataLocation)) {
|
||||
QFileInfo databaseFileInfo(dataLocation + QDir::separator() + "mac-addresses.db");
|
||||
if (!databaseFileInfo.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
databaseFileName = databaseFileInfo.absoluteFilePath();
|
||||
break;
|
||||
}
|
||||
|
||||
if (databaseFileName.isEmpty()) {
|
||||
qCWarning(dcMacAddressDatabase()) << "Could not find the mac address database in any system data location paths" << QStandardPaths::standardLocations(QStandardPaths::DataLocation);
|
||||
qCWarning(dcMacAddressDatabase()) << "The mac address database lookup feature will not be available.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_databaseName = databaseFileName;
|
||||
|
||||
m_available = initDatabase();
|
||||
if (m_available) {
|
||||
m_futureWatcher = new QFutureWatcher<QString>(this);
|
||||
|
|
@ -90,6 +112,7 @@ MacAddressDatabaseReply *MacAddressDatabase::lookupMacAddress(const QString &mac
|
|||
|
||||
bool MacAddressDatabase::initDatabase()
|
||||
{
|
||||
qCDebug(dcMacAddressDatabase()) << "Starting to initialize the mac address database:" << m_databaseName;
|
||||
m_connectionName = QFileInfo(m_databaseName).baseName();
|
||||
m_db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), m_connectionName);
|
||||
m_db.setDatabaseName(m_databaseName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue