chxavactivewatcher.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:4k
- /************************************************************************
- * chxavactivewatcher.cpp
- * ----------------------
- *
- * Synopsis:
- *
- * Implementation of base class for classes that request active object
- * event notification from system services.
- *
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Symbian includes...
- // Helix includes...
- #include "hxassert.h"
- // Includes from this project...
- #include "hxsym_debug.h"
- #include "chxavmisc.h"
- #include "chxavactivewatcher.h"
- ///////////////////////////////////
- // ctor
- CHXAvActiveWatcher::CHXAvActiveWatcher()
- : m_bKeepWatching(false)
- , m_msForwardEventDelay(0)
- {
- }
- ///////////////////////////////////
- // dtor
- CHXAvActiveWatcher::~CHXAvActiveWatcher()
- {
- // derived classes must call StopWatching() (recall there is a this pointer adjustment during destruct)
- HX_ASSERT(!m_spWatchObject->IsActive());
- }
- ///////////////////////////////////
- //
- void CHXAvActiveWatcher::BaseConstructL(TInt activePriority)
- {
- // initialize active object for receiving system event notifications
- m_spWatchObject = new CHXAvActiveDisp<CHXAvActiveWatcher>(this, &CHXAvActiveWatcher::OnEvent, &CHXAvActiveWatcher::OnCancelWatch);
- m_spWatchObject->SetPriority(activePriority);
- CActiveScheduler::Add(m_spWatchObject.raw_ptr());
- // see OnEvent()
- m_cbFowardEvent.ConstructL(MakeCommand(this, &CHXAvActiveWatcher::ForwardEvent));
- }
- ///////////////////////////////////
- // active object cancel
- void CHXAvActiveWatcher::OnCancelWatch(TInt status)
- {
- DPRINTF(SYMP_INFO, ("CHXAvActiveWatcher::OnCancelWatch(): status = %dn", status));
- m_bKeepWatching = false;
- // derived: cancel request from system system service provider
- DoCancelRequest(m_spWatchObject);
- }
- ////////////////////////////////////////////////////////
- // foward event notification to event handler
- void CHXAvActiveWatcher::ForwardEvent()
- {
- // set watch before executing handler so events are not missed
- if(m_bKeepWatching)
- {
- WatchForNextEvent();
- }
- if(m_spEventHandler)
- {
- m_spEventHandler->Execute();
- }
- }
- ////////////////////////////////////////////////////////
- // event notication from system
- void CHXAvActiveWatcher::OnEvent(TInt status)
- {
- DPRINTF(SYMP_INFO, ("CHXAvActiveWatcher::OnEvent(): status = %d; keep watching = %sn", status, dbg::Bool(m_bKeepWatching)));
- if(KErrNone == status)
- {
- if( m_msForwardEventDelay != 0 )
- {
- //
- // delay notification for this event to prevent execessive event
- // notifications; this is helpful for events such as filesystem
- // events, where many events may be generated in rapid succession
- // (e.g.,a group of files are being created/deleted/moved)
- //
- m_cbFowardEvent.Set(m_msForwardEventDelay);
- }
- else
- {
- ForwardEvent();
- }
- }
- }
- ////////////////////////////////////////////////////////
- // watch all events from here on
- void CHXAvActiveWatcher::StartWatching()
- {
- m_bKeepWatching = true;
- // start watching if not watching already
- if (!m_spWatchObject->IsActive())
- {
- WatchForNextEvent();
- }
- }
- ////////////////////////////////////////////////////////
- //
- void CHXAvActiveWatcher::WatchForNextEvent()
- {
- HX_ASSERT(!m_spWatchObject->IsActive());
- // derived: request event notification from some system service
- DoIssueRequest(m_spWatchObject);
- m_spWatchObject->Activate();
- }
- ////////////////////////////////////////////////////////
- //
- void CHXAvActiveWatcher::StopWatching()
- {
- m_bKeepWatching = false;
- if( m_spWatchObject && m_spWatchObject->IsActive() )
- {
- m_spWatchObject->Cancel();
- }
- }