Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
PluginWakeOnLan.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "PluginWakeOnLan.h"
4#include "ConnecterWakeOnLan.h"
5#include <QLoggingCategory>
6
7#ifdef HAVE_PCAPPLUSPLUS
8 #include "PcapPlusPlusVersion.h"
9 #include "PcapDevice.h"
10 #include <Logger.h>
11 static Q_LOGGING_CATEGORY(logPcpp, "WOL.PCPP")
12 void Pcpp_Logger(pcpp::Logger::LogLevel logLevel,
13 const std::string& logMessage,
14 const std::string& file,
15 const std::string& method,
16 const int line)
17 {
18 switch(logLevel)
19 {
20 case pcpp::Logger::LogLevel::Debug:
21 qDebug(logPcpp) << logMessage.c_str();
22 break;
23 case pcpp::Logger::LogLevel::Info:
24 qInfo(logPcpp) << logMessage.c_str();
25 break;
26 case pcpp::Logger::LogLevel::Error:
27 qCritical(logPcpp) << logMessage.c_str();
28 break;
29 }
30 }
31#endif
32
33static Q_LOGGING_CATEGORY(log, "WakeOnLan.Plugin")
34CPluginWakeOnLan::CPluginWakeOnLan(QObject *parent)
35 : CPluginClient{parent}
36{
37#ifdef HAVE_PCAPPLUSPLUS
38 pcpp::Logger::getInstance().setLogPrinter(Pcpp_Logger);
39 pcpp::Logger::getInstance().setAllModulesToLogLevel(
40 pcpp::Logger::LogLevel::Debug);
41 // suppressing errors to avoid cluttering stdout
42 pcpp::Logger::getInstance().enableLogs();
43 pcpp::Logger::getInstance().setLogLevel(
44 pcpp::LogModule::PcapLogModuleLiveDevice, pcpp::Logger::Info);
45#endif
46}
47
48CPluginWakeOnLan::~CPluginWakeOnLan()
49{
50 qDebug(log) << "CPluginWakeOnLan::~CPluginWakeOnLan()";
51}
52
53const QString CPluginWakeOnLan::Protocol() const
54{
55 return "Tool";
56}
57
58const QString CPluginWakeOnLan::Name() const
59{
60 return "WakeOnLan";
61}
62
63const QString CPluginWakeOnLan::DisplayName() const
64{
65 return tr("Wake on lan");
66}
67
68const QString CPluginWakeOnLan::Description() const
69{
70 return tr("Wake on lan");
71}
72
73const QIcon CPluginWakeOnLan::Icon() const
74{
75 return QIcon::fromTheme("lan");
76}
77
78const QString CPluginWakeOnLan::Version() const
79{
80 return PluginWakeOnLan_VERSION;
81}
82
83const QString CPluginWakeOnLan::Details() const
84{
85 QString szDetails;
86#ifdef HAVE_PCAPPLUSPLUS
87 szDetails = "- PcapPlusPlus";
88 szDetails += "\n";
89 szDetails += " - " + tr("version: ")
90 + pcpp::getPcapPlusPlusVersionFull().c_str();
91 szDetails += "\n";
92 szDetails += " - " + tr("Pcap lib version info: ")
93 + pcpp::IPcapDevice::getPcapLibVersionInfo().c_str();
94#endif
95 return szDetails;
96}
97
99{
100 if(Id() == szId)
101 {
102 return new CConnecterWakeOnLan(this);
103 }
104 return nullptr;
105}
Connecter interface.
Definition Connecter.h:62
The plugin interface.
virtual const QString Id() const
ID. Default: Protocol() + ":" + Name()
virtual const QString Details() const override
Display more information in About dialog or log.
virtual const QString Protocol() const override
Plugin Protocol.
virtual CConnecter * CreateConnecter(const QString &szId) override
New CConnecter instance.
virtual const QString DisplayName() const override
The plugin display name.
virtual const QString Name() const override
This name must be the same as the project name (${PROJECT_NAME}). The translation file (${PROJECT_NAM...
virtual const QString Version() const override
Version.
virtual const QString Description() const override
Plugin description.