turn PCAPDLL into a singleton

This commit is contained in:
Jeffrey Quesnelle
2020-03-24 13:15:26 -04:00
parent 38e24d7641
commit 99879c9021
4 changed files with 32 additions and 23 deletions
+24 -14
View File
@@ -2,15 +2,31 @@
using namespace icsneo;
std::shared_ptr<PCAPDLL> PCAPDLL::lazyLoadHolder;
bool PCAPDLL::lazyLoaded = false;
const PCAPDLL& PCAPDLL::getInstance()
{
static PCAPDLL instance;
return instance;
}
PCAPDLL::PCAPDLL() {
if(!lazyLoaded) {
lazyLoaded = true;
lazyLoadHolder = std::make_shared<PCAPDLL>();
}
PCAPDLL::~PCAPDLL()
{
closeDLL();
}
void PCAPDLL::closeDLL()
{
if (dll)
FreeLibrary(dll);
dll = nullptr;
}
bool PCAPDLL::ok() const
{
return dll != nullptr;
}
PCAPDLL::PCAPDLL()
{
dll = LoadLibrary("wpcap.dll");
if(dll == NULL) {
@@ -43,9 +59,3 @@ PCAPDLL::PCAPDLL() {
}
}
}
void PCAPDLL::closeDLL() {
if(dll)
FreeLibrary(dll);
dll = nullptr;
}