Mixe for Privacy and Anonymity in the Internet
CAAccountingSettleThread.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #include "StdAfx.h"
29 #ifdef PAYMENT
33 #include "CACmdLnOptions.hpp"
34 #include "CAAccountingInstance.hpp"
35 #include "CASocketAddrINet.hpp"
37 #include "CAXMLErrorMessage.hpp"
38 #include "Hashtable.hpp"
39 #include "CALibProxytest.hpp"
40 
41 CAAccountingSettleThread::CAAccountingSettleThread(Hashtable* a_accountingHashtable,
42  UINT8* currentCascade)/*,
43  CAAccountingBIInterface *pPiInterface,
44  CAAccountingDBInterface *pDbInterface)*/
45 {
46  // launch AI thread
47  m_pThread = new CAThread((UINT8*)"Accounting Settle Thread");
48  m_settleCascade = currentCascade;
49  //m_pPiInterface = pPiInterface;
50  //m_pDbInterface = pDbInterface;
52  CAMsg::printMsg(LOG_DEBUG, "Now launching Accounting SettleThread...\n");
53  m_bRun=true;
54  m_accountingHashtable = a_accountingHashtable;
56  m_pThread->start(this);
57 }
58 
59 
61  {
62  m_bRun=false;
63  if(m_pThread != NULL)
64  {
65  settle();
66  m_pThread->join();
67  delete m_pThread;
68  m_pThread = NULL;
69  }
70  if(m_pCondition != NULL)
71  {
72  delete m_pCondition;
73  m_pCondition = NULL;
74  }
75  }
76 
77 
79 {
80  m_pCondition->lock();
81  //m_bSleep = false;
84 }
85 
91  {
92  INIT_STACK;
93  BEGIN_STACK("CAAccountingSettleThread::mainLoop");
94 
95  UINT32 settlement_status;
97 
98  CAAccountingSettleThread* m_pAccountingSettleThread=(CAAccountingSettleThread*)pParam;
99 
100  CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Start loop...\n");
101 
102  while(m_pAccountingSettleThread->m_bRun) {
103  m_pAccountingSettleThread->m_pCondition->lock();
104  m_pAccountingSettleThread->m_pCondition->wait(sleepInterval * 1000);
105  m_pAccountingSettleThread->m_pCondition->unlock();
107  if(settlement_status != E_SUCCESS)
108  {
109  CAMsg::printMsg(LOG_ERR, "AccountingSettleThread: Settlement transaction failed\n");
110  }
111  }
112 
113  FINISH_STACK("CAAccountingSettleThread::mainLoop");
114 
115  CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Exiting run loop!\n");
116  /*dbConn.terminateDBConnection();
117  delete biConn;
118  biConn = NULL;*/
120  }
121 #endif //PAYMENT
#define INIT_STACK
Definition: CAThread.hpp:48
#define BEGIN_STACK(methodName)
Definition: CAThread.hpp:49
#define FINISH_STACK(methodName)
Definition: CAThread.hpp:50
#define THREAD_RETURN
Definition: StdAfx.h:540
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static SINT32 newSettlementTransaction()
A thread that settles CCs with the BI.
CAConditionVariable * m_pCondition
CAAccountingSettleThread(Hashtable *a_accountingHashtable, UINT8 *currentCascade)
static THREAD_RETURN mainLoop(void *param)
The main loop.
UINT32 getPaymentSettleInterval()
SINT32 signal()
Signals this object.
SINT32 wait()
Waits for a signal or for a timeout.
static CACmdLnOptions * getOptions()
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
Definition: CAThread.cpp:115
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
Definition: CAThread.hpp:148
SINT32 join()
Waits for the main function to finish execution.
Definition: CAThread.cpp:187
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2