#include <iostream>
#include <chrono>
#include <thread>
#include <telux/sec/ConnectionSecurityFactory.hpp>
class CellSecurityReportListener : public telux::sec::ICellularScanReportListener {
void onScanReportAvailable(telux::sec::CellularSecurityReport report,
telux::sec::EnvironmentInfo envInfo) {
std::cout << "Threat score: " << static_cast<uint32_t>(report.threatScore) << std::endl;
std::cout << "Cell ID : " << static_cast<uint32_t>(report.cellId) << std::endl;
std::cout << "PID : " << static_cast<uint32_t>(report.pid) << std::endl;
std::cout << "MCC : " << report.mcc << std::endl;
std::cout << "MNC : " << report.mnc << std::endl;
std::cout << "Action type : " << static_cast<uint32_t>(report.actionType) << std::endl;
std::cout << "RAT : " << static_cast<uint32_t>(report.rat) << std::endl;
for (size_t x = 0; x < report.threatTypesDetected.size(); x++) {
std::cout << "Threat type : " <<
static_cast<uint32_t>(report.threatTypesDetected[x]) << std::endl;
}
}
void onServiceStatusChange(telux::common::ServiceStatus newStatus) {
std::cout << "New status: " << static_cast<uint32_t>(newStatus) << std::endl;
}
};
int main(int argc, char **argv) {
telux::common::ErrorCode ec;
std::shared_ptr<CellSecurityReportListener> reportListener;
std::shared_ptr<telux::sec::ICellularSecurityManager> cellConSecMgr;
try {
reportListener = std::make_shared<CellSecurityReportListener>();
} catch (const std::exception& e) {
std::cout << "can't allocate CellSecurityReportListener" << std::endl;
return -ENOMEM;
}
auto &cellConSecFact = telux::sec::ConnectionSecurityFactory::getInstance();
cellConSecMgr = cellConSecFact.getCellularSecurityManager(ec);
if (!cellConSecMgr) {
std::cout <<
"can't get ICellularSecurityManager, err " << static_cast<int>(ec) << std::endl;
return -ENOMEM;
}
ec = cellConSecMgr->registerListener(reportListener);
if (ec != telux::common::ErrorCode::SUCCESS) {
std::cout << "can't register listener, err " << static_cast<int>(ec) << std::endl;
return -EIO;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
ec = cellConSecMgr->deRegisterListener(reportListener);
if (ec != telux::common::ErrorCode::SUCCESS) {
std::cout << "can't deregister listener, err " << static_cast<int>(ec) << std::endl;
return -EIO;
}
return 0;
}