Symbian OS
read last symbian news on www.newlc.com read last symbian reviews on www.newlc.com
read last symbian tutorial on www.newlc.com read last symbian download on www.newlc.com
19 mai 2006 - 09:36

The Symbian notifier framework allow system or custom event to be handled quite easily by your application. It's an easy way for a server with no UI to display some events on the phone screen.

The behaviour of notifiers is supplied by providing an implementation of the MEikSrvNotifierBase interface . A notifier is associated with a channel and a priority. Priority is used to determine the order of activation if more than one notifier is activated at any time. Priority only affects notifiers on the same channel (e.g. a screen or LED). This means that two notifiers can be active at the same time provided that they are on different channels.

Here is how you can define your own custom notifier:

1. Implement a class which inherits from both CEikDialog and MEikSrvNotifierBase.

#include "CknNtfy.h"
#include <eikdialg.h>
       
/**
* class CCknMmcNotifier
*
* a sleeping dialog used to request a password when a protected MMC is inserted
*/
class CCknMmcNotifier : public CEikDialog, public MEikSrvNotifierBase
        {
public:
        static CCknMmcNotifier* NewL();
        ~CCknMmcNotifier();
public:
        CCknMmcNotifier();
        void ConstructL();
        TInt DisplayNotifier();
// from CEikDialog
        void PreLayoutDynInitL();
        TBool OkToExitL(TInt aButtonId);
// from MEikSrvNotifierBase
        void Release();
        TNotifierInfo RegisterL();
        TNotifierInfo Info() const;
        TPtrC8 StartL(const TDesC8& aBuffer);
        void StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage);
        void Cancel();
        TPtrC8 UpdateL(const TDesC8& aBuffer);
       
private:
        TNotifierInfo iInfo;
        RMessage iMessage;
        const TAny* iReturnVal;
        };

2. Example cpp implementation:

//
// CknMmc.cpp
//
#include "CknMmc.h"

#include <EikSecEd.h>
#include <EikEnv.h>
#include <EikBtGpc.h>
#include <BaUtils.h>



#include <notifiertest.rsg>
//#include "CknNtfy.hrh"

// local copy for now...will be defined in a header
const TUid KScreenOutputChannel={0x100065aa};

void CCknMmcNotifier::Release()
        {
        delete this;
        }

CCknMmcNotifier::TNotifierInfo CCknMmcNotifier::RegisterL()
        {
        iInfo.iUid=KCkonMmcNotifierUid;
        iInfo.iChannel=KScreenOutputChannel;
        iInfo.iPriority=ENotifierPriorityVHigh;
        return iInfo;
        }

CCknMmcNotifier::TNotifierInfo CCknMmcNotifier::Info() const
        { // return notifier info
        return iInfo;
        }

TInt CCknMmcNotifier::DisplayNotifier()
        {
        RouseSleepingDialog();
        return KErrNone;
        }

TPtrC8 CCknMmcNotifier::StartL(const TDesC8& /*aBuffer*/)
        { // will not get called as this is a get response notifier
                RouseSleepingDialog();
               

        return TPtrC8();
        }

void CCknMmcNotifier::StartL(const TDesC8& /*aBuffer*/, const TAny* aReturnVal, RMessage aMessage)
        { // display the notifier
        const TAny* rdes=aMessage.Ptr2();
        TInt desLength=aMessage.Client().GetDesLength(rdes);
        if(desLength!=(TInt)sizeof(TMediaPswdReplyNotifyInfoV1))
                User::Leave(KErrGeneral);
// non waiting dialog
        iMessage=aMessage;
        iReturnVal=aReturnVal;
        RouseSleepingDialog();
        }

void CCknMmcNotifier::Cancel()
        {
        ExitSleepingDialog();
        //static_cast<CEikSecretEditor*>(Control(ECkonMmcNotifyLabel))->Reset();
        //if (iMessage.MessagePtr()!=RMessagePtr())
                //{
                //iMessage.Complete(KErrCancel);
                //}
        }

TPtrC8 CCknMmcNotifier::UpdateL(const TDesC8& /*aBuffer*/)
        { // ??
        return TPtrC8();
        }

CCknMmcNotifier* CCknMmcNotifier::NewL()
        { // construct the notifier
        CCknMmcNotifier* self=new (ELeave) CCknMmcNotifier();
        CleanupStack::PushL(self);
        self->ConstructL();
        CleanupStack::Pop();
        return self;
        }

CCknMmcNotifier::~CCknMmcNotifier()
        { // remove sleeping dialog from the stack
        iEikonEnv->RemoveFromStack(this);
        }

CCknMmcNotifier::CCknMmcNotifier()
        {
        }

void CCknMmcNotifier::ConstructL()
        {
//#pragma message ("A problem with wins emulatator. CBA can not be used if SetGloballyCapturing(ETrue) is called")
        //SetGloballyCapturing(ETrue);
        _LIT(KResFileName,"\\System\\Data\\notifiertest.rsc");
        _LIT(KDrive,"z:");
        // hack as Dll::Filename appears to not return the drive for notifiers
        TBuf<2> drive;
        drive=KDrive;
        TFileName fileName;
        Dll::FileName(fileName);
        TParse parse;
        parse.Set(KResFileName, &fileName, &drive);
        fileName=parse.FullName();
       
        BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(),fileName);
//
        TInt offset=iEikonEnv->AddResourceFileL(fileName);
        TRAPD(err,ConstructSleepingAlertDialogL(R_CHECKBOX_DEMO_DIALOG));
        iEikonEnv->DeleteResourceFile(offset);
        User::LeaveIfError(err);
        }

void CCknMmcNotifier::PreLayoutDynInitL()
        { // must not fail in anyway
        }

TBool CCknMmcNotifier::OkToExitL(TInt aButtonId)
        {
        return ETrue;
}  

3. Create dll entry implementation file.

/*
============================================================================
Name        : Try_00Dll.cpp
Author      : HanyMT & basedj
Version     :
Copyright   : Your copyright notice
Description : Try_00Dll.cpp - main DLL source
============================================================================
*/

//  Include Files  

#include <e32std.h>         // GLDEF_C
#include "Try_00.pan"       // panic codes


//  Global Functions

GLDEF_C void Panic(TTry_00Panic aPanic)
// Panics the thread with given panic code
   {
   User::Panic(_L("TRY_00"), aPanic);
   }


//  Exported Functions

EXPORT_C TInt E32Dll(TDllReason /*aReason*/)
// Called when the DLL is loaded and unloaded. Note: have to define
// epoccalldllentrypoints in MMP file to get this called in THUMB.
   {
   return KErrNone;
   }

4. Create a MMP file

Use a custom - and registered - UID3 to identify your notifier. Note the UID2 value which must match the KUidNotifierPlugIn value (0x10005522):

/*
============================================================================
Name        : Try_00.mmp
Author      : HanyMT & Basedj
Version     :
Copyright   : Your copyright notice
Description : This is the project specification file for Try_00.
============================================================================
*/
TARGET                Try_00.dll
TARGETTYPE            dll
TARGETPATH            \system\Notifiers
UID                   0x10005522 0x101f5ac4
USERINCLUDE           ..\inc
SYSTEMINCLUDE         \epoc32\include
DOCUMENT              bld.inf
DOCUMENT              Try_00.pkg
SOURCEPATH            ..\data
RESOURCE              NotifierTest.rss

SOURCEPATH            ..\src
SOURCE                cknmmc.cpp
SOURCE                cknntfy.cpp

LIBRARY               eiksrv.lib
LIBRARY               eikcore.lib
LIBRARY               efsrv.lib
LIBRARY               eikdlg.lib
LIBRARY               cone.lib
LIBRARY               eikcoctl.lib
LIBRARY               bafl.lib
LIBRARY               euser.lib
EXPORTUNFROZEN                

5. Call notifier from client app.

Rnotifier r;
r.Connect();
r.StartNotifier(NotifierUID,buf1,buf2);          

Tutorial posted mai 19th, 2006 by hanymt

Soumis par Anonymous le ven, 2006-08-04 14:00.

But where is NotifierArray implementation? And what about exported methods order?

Soumis par Anonymous le mar, 2006-08-08 15:58.

You'll find a nice example of NotifierArray in the SDK. Search for NotifierArray.

With respect to order of exports, I think you're wondering how to ensure that NotifierArray is the first ordinal. This is doen't via the mmp file. TARGETTYPE can be set to notifier.

 jk



copyright 2003-2009 NewLC SARL