From 07a1894c6e0391d06df641353a48f6cfdfa9f78a Mon Sep 17 00:00:00 2001 From: ehouse Date: Thu, 6 Oct 2005 02:49:50 +0000 Subject: [PATCH] implement heartbeat timer required for relay --- xwords4/symbian/inc/xwappview.h | 24 +++++++++++++++--- xwords4/symbian/src/xwappview.cpp | 41 +++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/xwords4/symbian/inc/xwappview.h b/xwords4/symbian/inc/xwappview.h index ff4fc1f96..60dfe9964 100644 --- a/xwords4/symbian/inc/xwappview.h +++ b/xwords4/symbian/inc/xwappview.h @@ -118,7 +118,7 @@ class CXWordsAppView : public CCoeControl EUtilRequest , EProcessPacket , ENumReasons - } XWTimerReason ; + } XWTimerReason_symb ; /* open game from prefs or start a new one. */ void MakeOrLoadGameL(); @@ -145,7 +145,7 @@ class CXWordsAppView : public CCoeControl TBool DoNewGame(); void DoImmediateDraw(); void DrawGameName() const; - void StartIdleTimer( XWTimerReason aWhy ); + void StartIdleTimer( XWTimerReason_symb aWhy ); static void sym_util_requestTime( XW_UtilCtxt* uc ); static VTableMgr* sym_util_getVTManager( XW_UtilCtxt* uc ); @@ -162,6 +162,9 @@ class CXWordsAppView : public CCoeControl static void sym_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* aOld, const CommsAddrRec* aNew ); + static void sym_util_setTimer( XW_UtilCtxt* uc, + XWTimerReason why, XP_U16 when, + TimerProc proc, void* closure ); #endif #ifdef XWFEATURE_STANDALONE_ONLY @@ -178,6 +181,14 @@ class CXWordsAppView : public CCoeControl #endif static TInt TimerCallback( TAny* aThis ); + static TInt HeartbeatTimerCallback( TAny* closure ); + + void SetHeartbeatCB( TimerProc aHBP, void* aHBC) { + iHeartbeatProc =aHBP; iHeartbeatClosure = aHBC; + } + void GetHeartbeatCB( TimerProc* aHBP, void** aHBC) { + *aHBP = iHeartbeatProc; *aHBC = iHeartbeatClosure; + } CEikApplication* iApp; /* remove if there's some way to get from env */ @@ -202,6 +213,14 @@ class CXWordsAppView : public CCoeControl CDesC16ArrayFlat* iDictList; /* to pass into the dialog */ + CDeltaTimer* iDeltaTimer; + + TimerProc iHeartbeatProc; + void* iHeartbeatClosure; + TCallBack iHeartbeatCB; + TDeltaTimerEntry iHeartbeatDTE; + XP_Bool iHBQueued; + #ifndef XWFEATURE_STANDALONE_ONLY CSendSocket* iSendSock; CDesC8ArrayFlat* iNewPacketQueue; @@ -210,5 +229,4 @@ class CXWordsAppView : public CCoeControl MPSLOT }; - #endif // _XWORDSAPPVIEW_H_ diff --git a/xwords4/symbian/src/xwappview.cpp b/xwords4/symbian/src/xwappview.cpp index f0d1b177d..5172edabd 100644 --- a/xwords4/symbian/src/xwappview.cpp +++ b/xwords4/symbian/src/xwappview.cpp @@ -69,6 +69,9 @@ CXWordsAppView* CXWordsAppView::NewLC(const TRect& aRect, CEikApplication* aApp CXWordsAppView::CXWordsAppView( CEikApplication* aApp ) : iApp( aApp ) + , iHeartbeatCB( HeartbeatTimerCallback, this ) + , iHeartbeatDTE(iHeartbeatCB) + , iHBQueued(XP_FALSE) { #ifdef DEBUG TInt processHandleCount, threadHandleCount; @@ -134,6 +137,8 @@ void CXWordsAppView::ConstructL(const TRect& aRect) iRequestTimer = CIdle::NewL( CActive::EPriorityIdle ); iTimerRunCount = 0; + iDeltaTimer = CDeltaTimer::NewL( CActive::EPriorityStandard ); + #ifndef XWFEATURE_STANDALONE_ONLY iSendSock = CSendSocket::NewL( PacketReceived, (void*)this ); @@ -362,7 +367,8 @@ sym_util_trayHiddenChange(XW_UtilCtxt* /*uc*/, XW_TrayVisState /*newState*/ ) } static void -sym_util_yOffsetChange(XW_UtilCtxt* /*uc*/, XP_U16 /*oldOffset*/, XP_U16 /*newOffset*/ ) +sym_util_yOffsetChange(XW_UtilCtxt* /*uc*/, XP_U16 /*oldOffset*/, + XP_U16 /*newOffset*/ ) { } @@ -388,10 +394,35 @@ sym_util_engineProgressCallback( XW_UtilCtxt* /*uc*/ ) return XP_TRUE; } -static void -sym_util_setTimer( XW_UtilCtxt* /*uc*/, XWTimerReason /*why*/, XP_U16 /*when*/, - TimerProc /* proc */, void* /* closure */ ) +/*static*/ TInt +CXWordsAppView::HeartbeatTimerCallback( TAny* closure ) { + CXWordsAppView* self = (CXWordsAppView*)closure; + self->iHBQueued = XP_FALSE; + + TimerProc proc; + void* hbclosure; + self->GetHeartbeatCB( &proc, &hbclosure ); + (*proc)( hbclosure, TIMER_HEARTBEAT ); + return 0; +} + +/* static */ void +CXWordsAppView::sym_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, + XP_U16 when, + TimerProc proc, void* closure ) +{ + CXWordsAppView* self = (CXWordsAppView*)uc->closure; + + self->SetHeartbeatCB( proc, closure ); + + if ( self->iHBQueued ) { + self->iDeltaTimer->Remove( self->iHeartbeatDTE ); + self->iHBQueued = XP_FALSE; + } + + self->iDeltaTimer->Queue( when * 1000000, self->iHeartbeatDTE ); + self->iHBQueued = XP_TRUE; } /* static */ void @@ -1330,7 +1361,7 @@ CXWordsAppView::sym_send_on_close( XWStreamCtxt* aStream, void* aClosure ) #endif void -CXWordsAppView::StartIdleTimer( XWTimerReason aWhy ) +CXWordsAppView::StartIdleTimer( XWTimerReason_symb aWhy ) { ++iTimerReasons[aWhy];