×
Namespaces

Variants
Actions

Log监控示例

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

代码示例
文章
翻译:
hoolee
最后由 hamishwillee 在 22 Dec 2011 编辑

这里的CLogMonitor演示了当使用LogEventL()回调方法获得系统Log事件报告时,如何将其写入监控。注意,每个调用都可能包

含多个log事件,首先可能为“missed”,过段时间后可能变为“answered”,如果你正在删除,要确保你将所有都清除干净。

如果你想读完所有的存储到log中的信息条目,可以使用CCallLogReader来代替

同样有一个对SMS信息进行监控和删除log条目的示例,在File:SMS DeliveryReport Deleting.zip这个示例中。

链接库:

LIBRARY logcli.lib

所需能力:

CAPABILITY ReadUserData

Log_Monitor.h

#include <logcli.h>
#include <logview.h>
 
class MLogMonitor
{
public:
virtual void LogEventL(const CLogEvent& event) = 0;
};
 
class CLogMonitor : public CActive
{
enum TMonitorStates
{
EUninitalised,
EInitalised,
EWaitingChange,
EReadingLog,
EReadingFirstLog,
EDeletingEvent,
EReadingLogItems
};
 
public:
static CLogMonitor* NewL(MLogMonitor* aCallBack);
static CLogMonitor* NewLC(MLogMonitor* aCallBack);
~CLogMonitor();
 
protected:
CLogMonitor(MLogMonitor* aCallBack);
void ConstructL(void);
void StartMonitorL();
void GetLatest();
void GetFirstEventL();
void GetNextEventL();
void DoCancel();
void RunL();
 
private:
CLogClient* iLogClient;
CLogViewRecent* iRecentLogView;
TMonitorStates iState;
MLogMonitor* iCallBack;
RFs iFsSession;
};


Log_Monitor.cpp

#include "Log_Monitor.h"
 
CLogMonitor* CLogMonitor::NewL(MLogMonitor* aCallBack)
{
CLogMonitor* self = CLogMonitor::NewLC(aCallBack);
CleanupStack::Pop(self);
return self;
}
 
CLogMonitor* CLogMonitor::NewLC(MLogMonitor* aCallBack)
{
CLogMonitor* self = new (ELeave) CLogMonitor(aCallBack);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CLogMonitor::CLogMonitor(MLogMonitor* aCallBack)
:CActive(0),iState(EUninitalised),iCallBack(aCallBack)
{
}
 
CLogMonitor::~CLogMonitor()
{
Cancel();
 
delete iRecentLogView, iRecentLogView = NULL;
delete iLogClient, iLogClient = NULL;
 
iFsSession.Close();
}
 
void CLogMonitor::ConstructL()
{
CActiveScheduler::Add(this);
 
User::LeaveIfError(iFsSession.Connect());
 
iLogClient = CLogClient::NewL(iFsSession);
iRecentLogView = CLogViewRecent::NewL(*iLogClient);
 
iState = EInitalised;
StartMonitorL();
}
 
void CLogMonitor::DoCancel()
{
if(iRecentLogView)
iRecentLogView->Cancel();
 
if(iLogClient)
{
if(iState == EWaitingChange)
iLogClient->NotifyChangeCancel();
else
iLogClient->Cancel();
}
}
 
void CLogMonitor::RunL()
{
if(iStatus != KErrCancel)
switch(iState)
{
case EWaitingChange:
// if this doesn't appear to catch the event right
// you could try sleeping a bit before fetching the event...
// User::After(2000000);
GetLatest();
break;
 
case EReadingLog:
if(iRecentLogView)
{
if(iRecentLogView->CountL() > 0)
GetFirstEventL();
else
StartMonitorL();
}
break;
 
case EReadingFirstLog:
case EReadingLogItems:
if(iStatus == KErrNone && iRecentLogView)
{
iCallBack->LogEventL(iRecentLogView->Event());
GetNextEventL();
}
else
StartMonitorL();
break;
 
case EDeletingEvent:
GetNextEventL();
break;
 
default:
StartMonitorL();
break;
}
}
 
 
void CLogMonitor::StartMonitorL()
{
if(iLogClient)
{
if(iRecentLogView)
iRecentLogView->Cancel();
 
iLogClient->Cancel();
 
iState = EWaitingChange;
iLogClient->NotifyChange(TTimeIntervalMicroSeconds32(3000000),iStatus);
SetActive();
}
}
 
void CLogMonitor::GetLatest()
{
if(iRecentLogView)
{
iState = EReadingLog;
iRecentLogView->Cancel();
if(iRecentLogView->SetRecentListL(KLogNullRecentList,iStatus))
SetActive();
else
StartMonitorL();
}
}
 
void CLogMonitor::GetFirstEventL()
{
if(iRecentLogView)
{
iState = EReadingFirstLog;
if(iRecentLogView->LastL(iStatus))
SetActive();
else
StartMonitorL();
}
}
 
 
void CLogMonitor::GetNextEventL()
{
if(iRecentLogView)
{
iState = EReadingLogItems;
if(iRecentLogView->PreviousL(iStatus))
SetActive();
else
StartMonitorL();
}
}
This page was last modified on 22 December 2011, at 04:42.
167 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×