|
|
|
|
|
|
|
|
// snfGBUdbmgr.cpp |
|
|
// snfGBUdbmgr.cpp |
|
|
// Copyright (C) 2006 - 2009 ARM Research Labs, LLC. |
|
|
|
|
|
|
|
|
// Copyright (C) 2006 - 2020 ARM Research Labs, LLC. |
|
|
// See www.armresearch.com for the copyright terms. |
|
|
// See www.armresearch.com for the copyright terms. |
|
|
// |
|
|
// |
|
|
// See snfGBUdbmgr.hpp for details. |
|
|
// See snfGBUdbmgr.hpp for details. |
|
|
|
|
|
|
|
|
#include "snfGBUdbmgr.hpp" |
|
|
#include "snfGBUdbmgr.hpp" |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
namespace cd = codedweller; |
|
|
|
|
|
|
|
|
const ThreadType snfGBUdbmgr::Type("snfGBUdbmgr"); // The thread's type. |
|
|
|
|
|
|
|
|
const cd::ThreadType snfGBUdbmgr::Type("snfGBUdbmgr"); // The thread's type. |
|
|
|
|
|
|
|
|
snfGBUdbmgr::snfGBUdbmgr() : // Clean init and start thread. |
|
|
snfGBUdbmgr::snfGBUdbmgr() : // Clean init and start thread. |
|
|
Thread(snfGBUdbmgr::Type, "GBUdb Manager"), // XCI Manager type and Name. |
|
|
Thread(snfGBUdbmgr::Type, "GBUdb Manager"), // XCI Manager type and Name. |
|
|
MyGBUdb(NULL), // NULL our links to avoid
|
|
|
|
|
|
MyLOGmgr(NULL), // any errors when the thread starts.
|
|
|
|
|
|
Configured(false), // Not configured yet.
|
|
|
|
|
|
TimeToStop(false), // It is not time to stop ;-)
|
|
|
|
|
|
|
|
|
MyGBUdb(NULL), // NULL our links to avoid |
|
|
|
|
|
MyLOGmgr(NULL), // any errors when the thread starts. |
|
|
|
|
|
Configured(false), // Not configured yet. |
|
|
|
|
|
TimeToStop(false), // It is not time to stop ;-) |
|
|
CondenseGuardTime(600000), // 10 minute guard time by default. |
|
|
CondenseGuardTime(600000), // 10 minute guard time by default. |
|
|
TimeTriggerOnOff(true), // By default, condense once per day. |
|
|
TimeTriggerOnOff(true), // By default, condense once per day. |
|
|
TimeTrigger(86400000), |
|
|
TimeTrigger(86400000), |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::linkGBUdb(GBUdb& G) { // Connect to our GBUdb |
|
|
void snfGBUdbmgr::linkGBUdb(GBUdb& G) { // Connect to our GBUdb |
|
|
ScopeMutex JustMe(MyMutex); // Lock for the config change. |
|
|
|
|
|
|
|
|
cd::ScopeMutex JustMe(MyMutex); // Lock for the config change. |
|
|
MyGBUdb = &G; // Set the new link. |
|
|
MyGBUdb = &G; // Set the new link. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::linkLOGmgr(snfLOGmgr& L) { // Connect to our LOGmgr |
|
|
void snfGBUdbmgr::linkLOGmgr(snfLOGmgr& L) { // Connect to our LOGmgr |
|
|
ScopeMutex JustMe(MyMutex); // Lock for the config change. |
|
|
|
|
|
|
|
|
cd::ScopeMutex JustMe(MyMutex); // Lock for the config change. |
|
|
MyLOGmgr = &L; // Set the new link. |
|
|
MyLOGmgr = &L; // Set the new link. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const int SECsASms = 1000; // How to convert seconds to milliseconds.
|
|
|
|
|
|
msclock toDuration(int Configuration_Integer) { // Convert int Seconds to timer duration.
|
|
|
|
|
|
return (Configuration_Integer * SECsASms); // Do the math and send it back.
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int SECsASms = 1000; // How to convert seconds to milliseconds. |
|
|
|
|
|
cd::msclock toDuration(int Configuration_Integer) { // Convert int Seconds to timer duration. |
|
|
|
|
|
return (Configuration_Integer * SECsASms); // Do the math and send it back. |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::configure(snfCFGData& CFGData) { // Establish or change our CFG. |
|
|
void snfGBUdbmgr::configure(snfCFGData& CFGData) { // Establish or change our CFG. |
|
|
ScopeMutex JustMe(MyMutex); // Only when we're not busy. |
|
|
|
|
|
|
|
|
cd::ScopeMutex JustMe(MyMutex); // Only when we're not busy. |
|
|
|
|
|
|
|
|
// Set up our configuration from the CFGData provided. |
|
|
// Set up our configuration from the CFGData provided. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GBUdb file name |
|
|
// GBUdb file name |
|
|
|
|
|
|
|
|
string GBUdbFileName; // Formulate the correct GBUdb file name |
|
|
|
|
|
|
|
|
std::string GBUdbFileName; // Formulate the correct GBUdb file name |
|
|
GBUdbFileName = CFGData.paths_workspace_path + // using the CFGData. |
|
|
GBUdbFileName = CFGData.paths_workspace_path + // using the CFGData. |
|
|
CFGData.node_licenseid + ".gbx"; |
|
|
CFGData.node_licenseid + ".gbx"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// eventually be saved for later re-use. |
|
|
// eventually be saved for later re-use. |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::load() { // Load the GBUdb as configured. |
|
|
void snfGBUdbmgr::load() { // Load the GBUdb as configured. |
|
|
ScopeMutex JustMe(MyMutex); // Just me while I do this. |
|
|
|
|
|
|
|
|
cd::ScopeMutex JustMe(MyMutex); // Just me while I do this. |
|
|
if( // Perform some sanity checks. |
|
|
if( // Perform some sanity checks. |
|
|
NULL != MyGBUdb && // If we have a GBUdb and |
|
|
NULL != MyGBUdb && // If we have a GBUdb and |
|
|
0 < string(MyGBUdb->FileName()).length() && // it has a file name and |
|
|
|
|
|
|
|
|
0 < std::string(MyGBUdb->FileName()).length() && // it has a file name and |
|
|
0 == access(MyGBUdb->FileName(),R_OK) // the file can be accessed |
|
|
0 == access(MyGBUdb->FileName(),R_OK) // the file can be accessed |
|
|
) { // then we can proceed: |
|
|
) { // then we can proceed: |
|
|
MyGBUdb->load(); // Load the GBUdb from disk. |
|
|
MyGBUdb->load(); // Load the GBUdb from disk. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!Configured) return; // Do nothing if we're not configured. |
|
|
if(!Configured) return; // Do nothing if we're not configured. |
|
|
|
|
|
|
|
|
ScopeMutex JustMe(MyMutex); // No CFG changes while I'm busy. |
|
|
|
|
|
|
|
|
cd::ScopeMutex JustMe(MyMutex); // No CFG changes while I'm busy. |
|
|
|
|
|
|
|
|
if(CondenseGuardTime.isExpired()) { // If we are allowed to condense |
|
|
if(CondenseGuardTime.isExpired()) { // If we are allowed to condense |
|
|
bool CondenseTriggered = false; // check to see if we should. |
|
|
bool CondenseTriggered = false; // check to see if we should. |
|
|
|
|
|
|
|
|
// The thread's task is to call DoMaintenanceWork() once every second. |
|
|
// The thread's task is to call DoMaintenanceWork() once every second. |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::myTask() { // This is what our thread does. |
|
|
void snfGBUdbmgr::myTask() { // This is what our thread does. |
|
|
Sleeper WaitATic(1000); // We need a 1 second sleeper. |
|
|
|
|
|
|
|
|
cd::Sleeper WaitATic(1000); // We need a 1 second sleeper. |
|
|
while(!TimeToStop) { // While it's not time to stop |
|
|
while(!TimeToStop) { // While it's not time to stop |
|
|
WaitATic(); // wait a tic and then do work. |
|
|
WaitATic(); // wait a tic and then do work. |
|
|
DoMaintenanceWork(); |
|
|
DoMaintenanceWork(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::GetAlertsForSync(list<GBUdbAlert>& AlertList) { // Fill AlertList w/ outgoing alerts. |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::GetAlertsForSync(std::list<GBUdbAlert>& AlertList) { // Fill AlertList w/ outgoing alerts. |
|
|
(*MyGBUdb).GetAlerts(AlertList); // For now, just pass this through. |
|
|
(*MyGBUdb).GetAlerts(AlertList); // For now, just pass this through. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::ProcessReflections(list<GBUdbAlert>& Reflections) { // Integrate returning reflections. |
|
|
|
|
|
|
|
|
void snfGBUdbmgr::ProcessReflections(std::list<GBUdbAlert>& Reflections) { // Integrate returning reflections. |
|
|
(*MyGBUdb).ImportAlerts(Reflections); // For now, just pass this through. |
|
|
(*MyGBUdb).ImportAlerts(Reflections); // For now, just pass this through. |
|
|
} |
|
|
} |