00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #include "StdAfx.h" 00029 #ifdef PAYMENT 00030 #include "CAAccountingSettleThread.hpp" 00031 #include "CAAccountingBIInterface.hpp" 00032 #include "CAAccountingDBInterface.hpp" 00033 #include "CACmdLnOptions.hpp" 00034 #include "CAAccountingInstance.hpp" 00035 #include "CASocketAddrINet.hpp" 00036 #include "CAXMLCostConfirmation.hpp" 00037 #include "CAXMLErrorMessage.hpp" 00038 #include "Hashtable.hpp" 00039 #include "CALibProxytest.hpp" 00040 00041 CAAccountingSettleThread::CAAccountingSettleThread(Hashtable* a_accountingHashtable, 00042 UINT8* currentCascade)/*, 00043 CAAccountingBIInterface *pPiInterface, 00044 CAAccountingDBInterface *pDbInterface)*/ 00045 { 00046 // launch AI thread 00047 m_pThread = new CAThread((UINT8*)"Accounting Settle Thread"); 00048 m_settleCascade = currentCascade; 00049 //m_pPiInterface = pPiInterface; 00050 //m_pDbInterface = pDbInterface; 00051 m_pThread->setMainLoop( mainLoop ); 00052 CAMsg::printMsg(LOG_DEBUG, "Now launching Accounting SettleThread...\n"); 00053 m_bRun=true; 00054 m_accountingHashtable = a_accountingHashtable; 00055 m_pCondition = new CAConditionVariable; 00056 m_pThread->start(this); 00057 } 00058 00059 00060 CAAccountingSettleThread::~CAAccountingSettleThread() 00061 { 00062 m_bRun=false; 00063 if(m_pThread != NULL) 00064 { 00065 settle(); 00066 m_pThread->join(); 00067 delete m_pThread; 00068 m_pThread = NULL; 00069 } 00070 if(m_pCondition != NULL) 00071 { 00072 delete m_pCondition; 00073 m_pCondition = NULL; 00074 } 00075 } 00076 00077 00078 void CAAccountingSettleThread::settle() 00079 { 00080 m_pCondition->lock(); 00081 //m_bSleep = false; 00082 m_pCondition->signal(); 00083 m_pCondition->unlock(); 00084 } 00085 00090 THREAD_RETURN CAAccountingSettleThread::mainLoop(void * pParam) 00091 { 00092 INIT_STACK; 00093 BEGIN_STACK("CAAccountingSettleThread::mainLoop"); 00094 00095 UINT32 settlement_status; 00096 UINT32 sleepInterval = CALibProxytest::getOptions()->getPaymentSettleInterval(); 00097 00098 CAAccountingSettleThread* m_pAccountingSettleThread=(CAAccountingSettleThread*)pParam; 00099 00100 CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Start loop...\n"); 00101 00102 while(m_pAccountingSettleThread->m_bRun) { 00103 m_pAccountingSettleThread->m_pCondition->lock(); 00104 m_pAccountingSettleThread->m_pCondition->wait(sleepInterval * 1000); 00105 m_pAccountingSettleThread->m_pCondition->unlock(); 00106 settlement_status = CAAccountingInstance::newSettlementTransaction(); 00107 if(settlement_status != E_SUCCESS) 00108 { 00109 CAMsg::printMsg(LOG_ERR, "AccountingSettleThread: Settlement transaction failed\n"); 00110 } 00111 } 00112 00113 FINISH_STACK("CAAccountingSettleThread::mainLoop"); 00114 00115 CAMsg::printMsg(LOG_DEBUG, "AccountingSettleThread: Exiting run loop!\n"); 00116 /*dbConn.terminateDBConnection(); 00117 delete biConn; 00118 biConn = NULL;*/ 00119 THREAD_RETURN_SUCCESS; 00120 } 00121 #endif //PAYMENT
1.5.6