Rabbit Remote Control 0.0.33
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 , m_pConnecter(nullptr)
37{
38#ifdef HAVE_PCAPPLUSPLUS
39 pcpp::Logger::getInstance().setLogPrinter(Pcpp_Logger);
40 pcpp::Logger::getInstance().setAllModulesToLogLevel(
41 pcpp::Logger::LogLevel::Debug);
42 // suppressing errors to avoid cluttering stdout
43 pcpp::Logger::getInstance().enableLogs();
44 pcpp::Logger::getInstance().setLogLevel(
45 pcpp::LogModule::PcapLogModuleLiveDevice, pcpp::Logger::Info);
46#endif
47}
48
49CPluginWakeOnLan::~CPluginWakeOnLan()
50{
51 qDebug(log) << "CPluginWakeOnLan::~CPluginWakeOnLan()";
52}
53
54const QString CPluginWakeOnLan::Protocol() const
55{
56 return "Tool";
57}
58
59const QString CPluginWakeOnLan::Name() const
60{
61 return "WakeOnLan";
62}
63
64const QString CPluginWakeOnLan::DisplayName() const
65{
66 return tr("Wake on lan");
67}
68
69const QString CPluginWakeOnLan::Description() const
70{
71 return tr("Wake on lan");
72}
73
74const QIcon CPluginWakeOnLan::Icon() const
75{
76 return QIcon::fromTheme("lan");
77}
78
79const QString CPluginWakeOnLan::Version() const
80{
81 return PluginWakeOnLan_VERSION;
82}
83
84const QString CPluginWakeOnLan::Details() const
85{
86 QString szDetails;
87#ifdef HAVE_PCAPPLUSPLUS
88 szDetails = "- PcapPlusPlus";
89 szDetails += "\n";
90 szDetails += " - " + tr("version: ")
91 + pcpp::getPcapPlusPlusVersionFull().c_str();
92 szDetails += "\n";
93 szDetails += " - " + tr("Pcap lib version info: ")
94 + pcpp::IPcapDevice::getPcapLibVersionInfo().c_str();
95#endif
96 return szDetails;
97}
98
100{
101 if(!m_pConnecter) {
102 m_pConnecter = CPluginClient::CreateConnecter(szId, para);
103 if(!m_pConnecter) return m_pConnecter;
104
105 QString szFile = m_pConnecter->GetSettingsFile();
106 QDir d(szFile);
107 if(!d.exists(szFile)) return m_pConnecter;
108 int nRet = false;
109 //bRet = m_pConnecter->Load(szFile);
110 bool bRet = QMetaObject::invokeMethod(
111 m_pConnecter,
112 "Load",
113 Qt::DirectConnection,
114 Q_RETURN_ARG(int, nRet),
115 Q_ARG(QString, szFile));
116 if(!bRet) {
117 qCritical(log) << "Call m_pConnecter->Load(szFile) fail.";
118 return nullptr;
119 }
120 if(nRet) {
121 qCritical(log) << "Load parameter fail" << nRet;
122 DeleteConnecter(m_pConnecter);
123 return nullptr;
124 }
125 }
126 return m_pConnecter;
127}
128
129CConnecter* CPluginWakeOnLan::OnCreateConnecter(const QString &szId)
130{
131 qDebug(log) << Q_FUNC_INFO;
132 if(Id() == szId)
133 {
134 return new CConnecterWakeOnLan(this);
135 }
136 return nullptr;
137}
138
140{
141 qDebug(log) << Q_FUNC_INFO;
142 Q_ASSERT(m_pConnecter == p);
143 m_pConnecter = nullptr;
145}
Connecter interface.
Definition Connecter.h:62
The parameters of client.
The plugin interface.
virtual const QString Id() const
ID. Default: Protocol() + ":" + Name()
virtual Q_INVOKABLE CConnecter * CreateConnecter(const QString &szId, CParameterClient *para)
New CConnecter instance.
virtual Q_INVOKABLE int DeleteConnecter(CConnecter *p)
Delete CConnecter.
virtual const QString Details() const override
Display more information in About dialog or log.
virtual CConnecter * CreateConnecter(const QString &szId, CParameterClient *para) override
New CConnecter instance.
virtual const QString Protocol() const override
Plugin Protocol.
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.
virtual int DeleteConnecter(CConnecter *p) override
Delete CConnecter.