Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Private Member Functions | Private Attributes
CAAccountingSettleThread Class Reference

A thread that settles CCs with the BI. More...

#include <CAAccountingSettleThread.hpp>

Collaboration diagram for CAAccountingSettleThread:
[legend]

List of all members.

Public Member Functions

 CAAccountingSettleThread (Hashtable *a_accountingHashtable, UINT8 *currentCascade)
 ~CAAccountingSettleThread ()
void settle ()

Static Private Member Functions

static THREAD_RETURN mainLoop (void *param)
 The main loop.

Private Attributes

CAConditionVariablem_pCondition
CAConditionVariablem_pForcedSettlementCondition
UINT8m_settleCascade
CAThreadm_pThread
volatile bool m_bRun
Hashtablem_accountingHashtable
bool m_bSleep

Detailed Description

A thread that settles CCs with the BI.

Author:
Bastian Voigt
Todo:
make SLEEP_SECONDS a configure option

Definition at line 62 of file CAAccountingSettleThread.hpp.


Constructor & Destructor Documentation

CAAccountingSettleThread::CAAccountingSettleThread ( Hashtable a_accountingHashtable,
UINT8 currentCascade 
)

Definition at line 41 of file CAAccountingSettleThread.cpp.

References m_accountingHashtable, m_bRun, m_pCondition, m_pThread, m_settleCascade, mainLoop(), CAMsg::printMsg(), CAThread::setMainLoop(), and CAThread::start().

{
  // launch AI thread
  m_pThread = new CAThread((UINT8*)"Accounting Settle Thread");
  m_settleCascade = currentCascade;
  //m_pPiInterface = pPiInterface;
  //m_pDbInterface = pDbInterface;
  m_pThread->setMainLoop( mainLoop );
  CAMsg::printMsg(LOG_DEBUG, "Now launching Accounting SettleThread...\n");
  m_bRun=true;
  m_accountingHashtable = a_accountingHashtable;
  m_pCondition = new CAConditionVariable;
  m_pThread->start(this);
}

Here is the call graph for this function:

Definition at line 60 of file CAAccountingSettleThread.cpp.

References CAThread::join(), m_bRun, m_pCondition, m_pThread, and settle().

  {
    m_bRun=false;
    if(m_pThread != NULL)
    {
      settle();
      m_pThread->join();
      delete m_pThread;
      m_pThread = NULL;
    }
    if(m_pCondition != NULL)
    {
      delete m_pCondition;
      m_pCondition = NULL;
    }
  }

Here is the call graph for this function:


Member Function Documentation

THREAD_RETURN CAAccountingSettleThread::mainLoop ( void *  pParam) [static, private]

The main loop.

Sleeps for a few minutes, then contacts the BI to settle CCs, then sleeps again

Definition at line 90 of file CAAccountingSettleThread.cpp.

References BEGIN_STACK, E_SUCCESS, FINISH_STACK, CALibProxytest::getOptions(), CACmdLnOptions::getPaymentSettleInterval(), INIT_STACK, CAMutex::lock(), m_bRun, m_pCondition, CAAccountingInstance::newSettlementTransaction(), CAMsg::printMsg(), THREAD_RETURN_SUCCESS, CAMutex::unlock(), and CAConditionVariable::wait().

Referenced by CAAccountingSettleThread().

  {
    INIT_STACK;
    BEGIN_STACK("CAAccountingSettleThread::mainLoop");

    UINT32 settlement_status;
    UINT32 sleepInterval = CALibProxytest::getOptions()->getPaymentSettleInterval();
    
    CAAccountingSettleThread* m_pAccountingSettleThread=(CAAccountingSettleThread*)pParam;

    CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Start loop...\n");

    while(m_pAccountingSettleThread->m_bRun) {
      m_pAccountingSettleThread->m_pCondition->lock();
      m_pAccountingSettleThread->m_pCondition->wait(sleepInterval * 1000);
      m_pAccountingSettleThread->m_pCondition->unlock();
      settlement_status = CAAccountingInstance::newSettlementTransaction();
      if(settlement_status != E_SUCCESS)
      {
        CAMsg::printMsg(LOG_ERR, "AccountingSettleThread: Settlement transaction failed\n");
      }
    }

    FINISH_STACK("CAAccountingSettleThread::mainLoop");

    CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Exiting run loop!\n");
    /*dbConn.terminateDBConnection();
    delete biConn;
    biConn = NULL;*/
    THREAD_RETURN_SUCCESS;
  }

Here is the call graph for this function:

Definition at line 78 of file CAAccountingSettleThread.cpp.

References CAMutex::lock(), m_pCondition, CAConditionVariable::signal(), and CAMutex::unlock().

Referenced by CAAccountingInstance::handleCostConfirmation_internal(), and ~CAAccountingSettleThread().

{
  m_pCondition->lock();
  //m_bSleep = false;
  m_pCondition->signal();
  m_pCondition->unlock();
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 78 of file CAAccountingSettleThread.hpp.

Referenced by CAAccountingSettleThread().

volatile bool CAAccountingSettleThread::m_bRun [private]

Definition at line 79 of file CAAccountingSettleThread.hpp.

Definition at line 73 of file CAAccountingSettleThread.hpp.

Definition at line 74 of file CAAccountingSettleThread.hpp.

Referenced by CAAccountingSettleThread().


The documentation for this class was generated from the following files: