收藏
RChangeNotifier
CEnvironmentChangeNotifier
可以用来监视是否到达了午夜,位置改变,有线程死掉了,系统时间被修改,电量变化等事件,有因内存不足引起的分配失败等事件
RChangeNotifier 和 CEnvironmentChangeNotifier 的关系类似于RTimer和CTimer的关系。
RChangeNotifier 是阻塞的,使用的时候最好放在一个CActive里面。用法灵活。
CEnvironmentChangeNotifier 本身就是个CActive可以直接使用。使用方便
使用方法如下:
RChangeNotifier:
{
...
RChangeNotifier the_notifier;
TRequestStatus the_status;
...
the_notifier.Create();
the_notifier.Logon(the_status);
User::WaitForRequest(the_status);
...
...// prepare for a long wait
...
TInt changes = the_status.Int();
if (changes & EChangesSystemTime)
{
// handle a change to system time
}
if (changes & EChanges EChangesLocale)
{
// handle a change to locale
}
...
the_notifier.Close();
...
}
CEnvironmentChangeNotifier
void CExampleEnvChangeNotifier::ConstructL()
{
iCallBack = new (ELeave)TCallBack(CallBackFunction, this);
iChangeNotifier =
CEnvironmentChangeNotifier::NewL(0, *iCallBack);
iChangeNotifier->Start();
}
CExampleEnvChangeNotifier::~CMyEnvChangeNotifier()
{
iChangeNotifier->Cancel();
delete iChangeNotifier;
delete iCallBack;
}
TInt CExampleEnvChangeNotifier::CallBackFunction(TAny* aFunction)
{
return ((CEventsEnvChangeNotifier*)aFunction)->ChangeL();
}
TInt CExampleEnvChangeNotifier::ChangeL()
{
TInt change = iChangeNotifier->Change();
//当iChangeNotifier 启动的时候绘产生一次回掉此时change为127
if (change==127)
{
return -1;
}
if (change & EChangesLocale)
{
// Locale change, do something
}
if (change & EChangesMidnightCrossover)
{
// Midnight crossover, do something
}
if (change & EChangesThreadDeath)
{
// Thread death, do something
}
if (change & EChangesPowerStatus)
{
// Power status change, do something
}
if (change & EChangesSystemTime)
{
// System status change, do something
}
return 1;
}
EChangesLocale
The system locale has changed.
Typically this event occurs as a result of a call to TLocale::Set().
位置改变
EChangesMidnightCrossover
The system time has passed midnight.
到达午夜
EChangesThreadDeath
A thread has died.
This event is reported when any thread in the system dies.
有线程死掉了
EChangesPowerStatus
The status of the power supply has changed.
电量变化
EChangesSystemTime
The system time has changed.
系统时间被修改
EChangesFreeMemory
The free memory level has crossed a specified threshold value.
EChangesOutOfMemory
A memory allocation has failed due to insufficient free memory.
有因内存不足引起的分配失败
我专门写了个CEnvironmentChangeNotifier 例子,在e51上可以正常工作了。http://download.csdn.net/source/710390