chxavactivewatcher.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:4k
源码类别:

Symbian

开发平台:

C/C++

  1. /************************************************************************
  2.  * chxavactivewatcher.cpp
  3.  * ----------------------
  4.  *
  5.  * Synopsis:
  6.  *
  7.  * Implementation of base class for classes that request active object
  8.  * event notification from system services.
  9.  *
  10.  *
  11.  *
  12.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  13.  *
  14.  ************************************************************************/ 
  15. // Symbian includes...
  16. // Helix includes...
  17. #include "hxassert.h"
  18. // Includes from this project...
  19. #include "hxsym_debug.h"
  20. #include "chxavmisc.h"
  21. #include "chxavactivewatcher.h"
  22. ///////////////////////////////////
  23. // ctor
  24. CHXAvActiveWatcher::CHXAvActiveWatcher()
  25. : m_bKeepWatching(false)
  26. , m_msForwardEventDelay(0)
  27. {
  28. }
  29. ///////////////////////////////////
  30. // dtor
  31. CHXAvActiveWatcher::~CHXAvActiveWatcher()
  32. {
  33.     // derived classes must call StopWatching() (recall there is a this pointer adjustment during destruct)
  34.     HX_ASSERT(!m_spWatchObject->IsActive());
  35. }
  36. ///////////////////////////////////
  37. //
  38. void CHXAvActiveWatcher::BaseConstructL(TInt activePriority)
  39. {
  40.     // initialize active object for receiving system event notifications
  41.     m_spWatchObject =  new CHXAvActiveDisp<CHXAvActiveWatcher>(this, &CHXAvActiveWatcher::OnEvent, &CHXAvActiveWatcher::OnCancelWatch);
  42.     m_spWatchObject->SetPriority(activePriority);
  43.     CActiveScheduler::Add(m_spWatchObject.raw_ptr());
  44.     // see OnEvent()
  45.     m_cbFowardEvent.ConstructL(MakeCommand(this, &CHXAvActiveWatcher::ForwardEvent));
  46. }
  47. ///////////////////////////////////
  48. // active object cancel
  49. void CHXAvActiveWatcher::OnCancelWatch(TInt status)
  50. {
  51.     DPRINTF(SYMP_INFO, ("CHXAvActiveWatcher::OnCancelWatch(): status = %dn", status));
  52.     m_bKeepWatching = false;
  53.     // derived: cancel request from system system service provider
  54.     DoCancelRequest(m_spWatchObject);
  55. }
  56. ////////////////////////////////////////////////////////
  57. // foward event notification to event handler
  58. void CHXAvActiveWatcher::ForwardEvent()
  59. {
  60.     // set watch before executing handler so events are not missed
  61.     if(m_bKeepWatching)
  62.     {
  63. WatchForNextEvent();
  64.     }
  65.     if(m_spEventHandler)
  66.     {
  67. m_spEventHandler->Execute();
  68.     }
  69. }
  70. ////////////////////////////////////////////////////////
  71. // event notication from system
  72. void CHXAvActiveWatcher::OnEvent(TInt status)
  73. {
  74.     DPRINTF(SYMP_INFO, ("CHXAvActiveWatcher::OnEvent(): status = %d; keep watching = %sn", status, dbg::Bool(m_bKeepWatching)));
  75.     if(KErrNone == status)
  76.     {
  77. if( m_msForwardEventDelay != 0 )
  78.         {
  79.             //
  80.             // delay notification for this event to prevent execessive event
  81.             // notifications; this is helpful for events such as filesystem 
  82.             // events, where many events may be generated in rapid succession
  83.             // (e.g.,a group of files are being created/deleted/moved)
  84.             //
  85.             m_cbFowardEvent.Set(m_msForwardEventDelay);
  86.         }
  87.         else
  88.         {
  89.             ForwardEvent();
  90.         }
  91.     }
  92. }
  93. ////////////////////////////////////////////////////////
  94. // watch all events from here on
  95. void CHXAvActiveWatcher::StartWatching()
  96. {
  97.     m_bKeepWatching = true;
  98.     // start watching if not watching already
  99.     if (!m_spWatchObject->IsActive())
  100.     {
  101. WatchForNextEvent();
  102.     }
  103. }
  104. ////////////////////////////////////////////////////////
  105. //
  106. void CHXAvActiveWatcher::WatchForNextEvent()
  107. {
  108.     HX_ASSERT(!m_spWatchObject->IsActive());
  109.     // derived: request event notification from some system service
  110.     DoIssueRequest(m_spWatchObject);
  111.     m_spWatchObject->Activate();
  112. }
  113. ////////////////////////////////////////////////////////
  114. //
  115. void CHXAvActiveWatcher::StopWatching()
  116. {
  117.     m_bKeepWatching = false;
  118.     if( m_spWatchObject && m_spWatchObject->IsActive() )
  119.     {
  120. m_spWatchObject->Cancel();
  121.     }
  122. }