RChangeNotifier和CEnvironmentChangeNotifier 的使用

 收藏

 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值