CVS update: /common/system/, /common/system/pub/
ehyche at helixcommunity.org ehyche at helixcommunity.orgUser: ehyche Date: 02/12/11 05:24:32 Added /common/system/ pxtimer.cpp /common/system/pub/ pxtimer.h Modified /common/system/ Umakefil Log Add pxtimer.cpp File Changes: Directory: /common/system/ ========================== File [changed]: Umakefil Url: https://common.helixcommunity.org/source/browse/common/system/Umakefil.diff?r1=1.1.1.1&r2=1.2 Delta lines: +2 -1 ------------------- --- Umakefil 18 Oct 2002 01:45:08 -0000 1.1.1.1 +++ Umakefil 11 Dec 2002 13:24:32 -0000 1.2 @@ -45,7 +45,8 @@ "hxdate.cpp", "hxrquest.cpp", "genthrd.cpp", - "pq.cpp") + "pq.cpp", + "pxtimer.cpp") if project.BuildOption('nodll'): project.AddSources("stataccs.cpp", "staticff.cpp") File [added]: pxtimer.cpp Url: https://common.helixcommunity.org/source/browse/common/system/pxtimer.cpp?rev=1.1&content-type=text/vnd.viewcvs-markup Added lines: 201 ---------------- // include #include "hxtypes.h" #include "hxcom.h" #include "hxengin.h" // pnmisc #include "baseobj.h" // pxcomlib #include "pxtimer.h" // pndebug #include "hxheap.h" #ifdef _DEBUG #undef HX_THIS_FILE static char HX_THIS_FILE[] = __FILE__; #endif PXTimer::PXTimer() { m_lRefCount = 0; m_ulState = kStateConstructed; m_ulInstance = 0; m_ulInterval = 0; m_pScheduler = NULL; m_pResponse = NULL; m_ulCallbackHandle = 0; m_bCallbackPending = FALSE; m_bInsideTimerFire = FALSE; } PXTimer::~PXTimer() { Deallocate(); } void PXTimer::Deallocate() { if (IsCallbackPending()) { RemovePendingCallback(); } HX_RELEASE(m_pScheduler); HX_RELEASE(m_pResponse); } STDMETHODIMP PXTimer::QueryInterface(REFIID riid, void** ppvObj) { HX_RESULT retVal = HXR_OK; if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = (IUnknown*) this; } else if (IsEqualIID(riid, IID_IHXCallback)) { AddRef(); *ppvObj = (IHXCallback*) this; } else { *ppvObj = NULL; retVal = HXR_NOINTERFACE; } return retVal; } STDMETHODIMP_(UINT32) PXTimer::AddRef() { return InterlockedIncrement(&m_lRefCount); } STDMETHODIMP_(UINT32) PXTimer::Release() { if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0; } STDMETHODIMP PXTimer::Func() { HX_RESULT retVal = HXR_OK; if (m_pScheduler && m_pResponse) { // Schedule another callback m_ulInterval // milliseconds from now m_ulCallbackHandle = m_pScheduler->RelativeEnter(this, m_ulInterval); // Set the callback pending flag m_bCallbackPending = TRUE; // Make sure we don't allow re-entrancy // into TimerFire(). if (!m_bInsideTimerFire) { // Set the re-entrancy flag m_bInsideTimerFire = TRUE; // Call TimerFire on the response interface m_pResponse->TimerFire(m_ulInstance); // Clear the re-entrancy flag m_bInsideTimerFire = FALSE; } } return retVal; } HX_RESULT PXTimer::Init(UINT32 ulInstance, IUnknown* pContext, PXTimerResponse* pResponse) { HX_RESULT retVal = HXR_OK; if (pContext && pResponse) { // Clear out everything if necessary Deallocate(); // Init members retVal = pContext->QueryInterface(IID_IHXScheduler, (void**) &m_pScheduler); if (SUCCEEDED(retVal)) { // Save the members m_ulInstance = ulInstance; m_pResponse = pResponse; m_ulCallbackHandle = 0; m_bCallbackPending = FALSE; m_pResponse->AddRef(); // Set the state m_ulState = kStateInitialized; } } else { retVal = HXR_INVALID_PARAMETER; } return retVal; } HX_RESULT PXTimer::StartTimer(UINT32 ulInterval) { HX_RESULT retVal = HXR_OK; if (m_ulState == kStateConstructed) { retVal = HXR_NOT_INITIALIZED; } else if (m_ulState == kStateInitialized) { if (ulInterval >= kMinInterval) { // Save the interval m_ulInterval = ulInterval; // Schedule the first callback m_ulCallbackHandle = m_pScheduler->RelativeEnter(this, m_ulInterval); // Set the callback flag m_bCallbackPending = TRUE; // Set the state m_ulState = kStateActive; } else { retVal = HXR_INVALID_PARAMETER; } } else if (m_ulState == kStateActive) { // Timer is already started, so no need to // do anything... } return retVal; } void PXTimer::StopTimer() { if (m_ulState == kStateConstructed || m_ulState == kStateInitialized) { // Timer has not been started; therefore, // we don't need to do anything to stop it. } else if (m_ulState == kStateActive) { // Remove any pending callback if (IsCallbackPending()) { RemovePendingCallback(); } // Reset the state m_ulState = kStateInitialized; } } Directory: /common/system/pub/ ============================== File [added]: pxtimer.h Url: https://common.helixcommunity.org/source/browse/common/system/pub/pxtimer.h?rev=1.1&content-type=text/vnd.viewcvs-markup Added lines: 87 --------------- #ifndef PXTIMER_H #define PXTIMER_H // Forward declarations typedef _INTERFACE IHXCallback IHXCallback; typedef _INTERFACE IHXScheduler IHXScheduler; class CHXBaseCountingObject; class PXTimerResponse : public IUnknown { public: // IUnknown methods STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **ppvObj) PURE; STDMETHOD_(ULONG32,AddRef) (THIS) PURE; STDMETHOD_(ULONG32,Release) (THIS) PURE; // PXTimerResponse methods STDMETHOD(TimerFire) (THIS_ UINT32 ulInstance) PURE; }; class PXTimer : public CHXBaseCountingObject, public IHXCallback { public: PXTimer(); virtual ~PXTimer(); // IUnknown methods STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **ppvObj); STDMETHOD_(ULONG32,AddRef) (THIS); STDMETHOD_(ULONG32,Release) (THIS); // IHXCallback methods STDMETHOD(Func) (THIS); // PXTimer methods HX_RESULT Init(UINT32 ulInstance, IUnknown* pContext, PXTimerResponse* pResponse); HX_RESULT StartTimer(UINT32 ulInterval); void StopTimer(); BOOL IsStarted(); protected: enum { kStateConstructed, kStateInitialized, kStateActive, kMinInterval = 33 }; INT32 m_lRefCount; UINT32 m_ulState; UINT32 m_ulInstance; UINT32 m_ulInterval; IHXScheduler* m_pScheduler; PXTimerResponse* m_pResponse; UINT32 m_ulCallbackHandle; BOOL m_bCallbackPending; BOOL m_bInsideTimerFire; void Deallocate(); BOOL IsCallbackPending(); void RemovePendingCallback(); }; inline BOOL PXTimer::IsCallbackPending() { return m_bCallbackPending; } inline void PXTimer::RemovePendingCallback() { if (m_bCallbackPending && m_pScheduler) { m_pScheduler->Remove(m_ulCallbackHandle); m_bCallbackPending = FALSE; m_ulCallbackHandle = 0; } } inline BOOL PXTimer::IsStarted() { return (m_ulState == kStateActive ? TRUE : FALSE); } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe at common.helixcommunity.org For additional commands, e-mail: cvs-help at common.helixcommunity.org