chxavcallback.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:3k
- /************************************************************************
- * chxavcallback.cpp
- * -----------------
- *
- * Synopsis:
- * Encapsulates single or periodic timer callback
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Symbian includes...
- #include "hxtypes.h"
- #include "hxassert.h"
- // Includes from this project...
- #include "chxavmisc.h"
- #include "chxavutil.h"
- #include "chxavcallback.h"
- #include "chxavcommand.h"
- #include "hxsym_leaveutil.h"
- ////////////////////////////////////////////
- //
- CHXAvCallback::CHXAvCallback()
- : m_pAction(0)
- , m_cbType(ONCE)
- , m_msTimeout(0)
- {
- }
- ////////////////////////////////////////////
- //
- CHXAvCallback::~CHXAvCallback()
- {
- Stop();
- m_timer.Close();
- HX_DELETE(m_pAction);
- }
- ////////////////////////////////////////////
- //
- void CHXAvCallback::ConstructL(const CHXAvCommand& cmd)
- {
- m_pAction = cmd.CloneL();
- HXSYM_LEAVE_IF_ERR(m_timer.CreateLocal());
- // active object to run on timer event
- m_pActiveObject =
- new (ELeave) CHXAvActiveDisp<CHXAvCallback>(this,
- &CHXAvCallback::OnTimerEvent,
- &CHXAvCallback::OnTimerEventCancel);
- CActiveScheduler::Add(m_pActiveObject.raw_ptr());
- }
- ////////////////////////////////////////////
- // abort callback if it is pending
- //
- void CHXAvCallback::Stop()
- {
- if( m_pActiveObject && m_pActiveObject->IsActive() )
- {
- m_pActiveObject->Cancel();
- }
- }
- ////////////////////////////////////////////
- // issue timer event request
- //
- // can be called at any time to extend or
- // reset the timeout
- //
- void CHXAvCallback::Set(TUint msTimeout, CallbackType cbType)
- {
- m_cbType = cbType;
- m_msTimeout = msTimeout;
- // cancel existing request if it exists;
- Stop();
- m_timer.After(m_pActiveObject->Status(), m_msTimeout * 1000);
- m_pActiveObject->Activate();
- }
- ////////////////////////////////////////////
- // AO notification
- void CHXAvCallback::OnTimerEvent(TInt status)
- {
- //DPRINTF(D_GUI_VERBOSE, ("OnTimerEvent(%d)'n", status));
- if(status == KErrNone)
- {
- m_pAction->Execute();
- HX_ASSERT(m_pAction != 0); // self-delete?
- if(REPEAT == m_cbType)
- {
- Set(m_msTimeout, REPEAT);
- }
- }
-
- }
- ////////////////////////////////////////////
- // AO notification
- void CHXAvCallback::OnTimerEventCancel(TInt status)
- {
- m_timer.Cancel();
- }