Last active
November 13, 2018 20:45
-
-
Save nlharri/d3d053490d0de1918295168d6b5dee66 to your computer and use it in GitHub Desktop.
WiFiScannerLinux - main.cpp - main() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char *argv[]) { | |
// read config file | |
std::ifstream confFile; | |
std::string wifiIfName; | |
confFile.open("./MeerkatWifiScanner.conf"); | |
if (!confFile) { | |
std::cerr << "Unable to open file MeerkatWifiScanner.conf"; | |
return -1; | |
} | |
confFile >> wifiIfName; | |
confFile.close(); | |
if (wifiIfName.empty()) { | |
std::cerr << "Unable to get Wifi Interface name from config file MeerkatWifiScanner.conf"; | |
return -1; | |
} | |
// define AP Collection object as volatile to be able to manipulate it from the thread | |
WifiAPCollection* volatile wifiAPCollection = new WifiAPCollection(); | |
//----------------------------------------------- | |
// thread stuff >>> | |
// Create a std::promise object | |
std::promise<void> exitSignal; | |
//Fetch std::future object associated with promise | |
std::future<void> futureObj = exitSignal.get_future(); | |
// Starting Thread & move the future object in lambda function by reference | |
std::thread th(&wifiScannerThread, std::move(futureObj), wifiIfName, wifiAPCollection); | |
// <<< end of thread stuff | |
//----------------------------------------------- | |
// initialize Qt application | |
QApplication app(argc, argv); | |
ShapedDashboard dashBoard; | |
dashBoard.setWifiAPCollection(wifiAPCollection); | |
dashBoard.show(); | |
int app_exec_code = app.exec(); | |
//----------------------------------------------- | |
// thread stuff >>> | |
//Set the value in promise | |
exitSignal.set_value(); | |
//Wait for thread to join | |
th.join(); | |
// <<< end of thread stuff | |
//----------------------------------------------- | |
delete wifiAPCollection; | |
return app_exec_code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment