Explorar el Código

tidy namespace GBUdbmgr

master
Pete McNeil hace 3 años
padre
commit
cddeeb21df
Se han modificado 2 ficheros con 26 adiciones y 29 borrados
  1. 22
    22
      snfGBUdbmgr.cpp
  2. 4
    7
      snfGBUdbmgr.hpp

+ 22
- 22
snfGBUdbmgr.cpp Ver fichero

@@ -1,5 +1,5 @@
// 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 snfGBUdbmgr.hpp for details.
@@ -7,16 +7,16 @@
#include "snfGBUdbmgr.hpp"
#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.
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.
TimeTriggerOnOff(true), // By default, condense once per day.
TimeTrigger(86400000),
@@ -39,22 +39,22 @@ snfGBUdbmgr::~snfGBUdbmgr() {
}

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.
}

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.
}
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.
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.

@@ -99,7 +99,7 @@ void snfGBUdbmgr::configure(snfCFGData& CFGData) {

// 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.
CFGData.node_licenseid + ".gbx";

@@ -127,10 +127,10 @@ void snfGBUdbmgr::configure(snfCFGData& CFGData) {
// eventually be saved for later re-use.

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.
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
) { // then we can proceed:
MyGBUdb->load(); // Load the GBUdb from disk.
@@ -144,7 +144,7 @@ void snfGBUdbmgr::DoMaintenanceWork() {

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
bool CondenseTriggered = false; // check to see if we should.
@@ -220,17 +220,17 @@ void snfGBUdbmgr::stop() {
// The thread's task is to call DoMaintenanceWork() once every second.

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
WaitATic(); // wait a tic and then do work.
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.
}

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.
}

+ 4
- 7
snfGBUdbmgr.hpp Ver fichero

@@ -6,8 +6,7 @@
// It is responsible for setting parameters, monitoring activity, and handling
// scheduled maintenance tasks.

#ifndef snfGBUdbmgr_included
#define snfGBUdbmgr_included
#pragma once

#include "../CodeDweller/threading.hpp"
#include "../CodeDweller/timing.hpp"
@@ -15,7 +14,7 @@
#include "snfLOGmgr.hpp"
#include "GBUdb.hpp"

using namespace std;
namespace cd = codedweller;

class snfLOGmgr;

@@ -58,11 +57,9 @@ class snfGBUdbmgr : public cd::Thread {
void stop(); // Stop the thread.
void myTask(); // Establish our thread's task.

void GetAlertsForSync(list<GBUdbAlert>& AlertList); // Fill AlertList w/ outgoing alerts.
void ProcessReflections(list<GBUdbAlert>& Reflections); // Integrate returning reflections.
void GetAlertsForSync(std::list<GBUdbAlert>& AlertList); // Fill AlertList w/ outgoing alerts.
void ProcessReflections(std::list<GBUdbAlert>& Reflections); // Integrate returning reflections.

const static cd::ThreadType Type; // The thread's type.

};

#endif

Cargando…
Cancelar
Guardar