homescreensrv_plat/sapi_menucontent/mcsservice/src/mcsrequestnotification.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mcsdef.h"
       
    20 #include "mcsmenu.h"
       
    21 #include "mcsmenufilter.h"
       
    22 
       
    23 #include "mcsrequestnotification.h"
       
    24 #include "mcsservice.h"
       
    25 #include "mcsconstants.h"
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // two-phased constructor
       
    30 // ---------------------------------------------------------------------------
       
    31 CMCSReqNotification* CMCSReqNotification::NewL( RMenu& aMCS )
       
    32     {
       
    33     CMCSReqNotification* self = new (ELeave) CMCSReqNotification();
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL(aMCS);
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39     
       
    40 // ---------------------------------------------------------------------------
       
    41 // destructor
       
    42 // ---------------------------------------------------------------------------
       
    43 CMCSReqNotification::~CMCSReqNotification()
       
    44     {
       
    45     Cancel();
       
    46 
       
    47   //  delete iRunningApps;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // default constructor
       
    52 // ---------------------------------------------------------------------------
       
    53 CMCSReqNotification::CMCSReqNotification() : CActive( EPriorityStandard )
       
    54     {
       
    55   
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // second phase constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 void CMCSReqNotification::ConstructL( RMenu& aMCS)
       
    62     {
       
    63     TInt err = KErrNone;
       
    64     err = iNotifier.Open(aMCS);
       
    65     iMCS = aMCS;
       
    66     iIsNotification = EFalse;
       
    67     if(err != KErrNone)
       
    68         {
       
    69         User::Leave( err );
       
    70         }
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Inherited from CActive class 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CMCSReqNotification::DoCancel()
       
    78     {
       
    79     iNotifier.Close();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Inherited from CActive class 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CMCSReqNotification::RunL()
       
    87     {
       
    88     TInt event = iStatus.Int();
       
    89     if( event != KErrCancel )
       
    90         {
       
    91         if(iIsNotification)
       
    92             {
       
    93             if(event)
       
    94                 {
       
    95                 iCallback->NotifyResultL( event, (TAny*) &iFolderId );
       
    96                 iStatus = KRequestPending; 
       
    97                 iNotifier.Notify(iFolderId, iEvents, iStatus );
       
    98                 SetActive();
       
    99                 }
       
   100             else
       
   101                 { 
       
   102                 if(event != KErrCancel)// error in notification
       
   103                     {
       
   104                     iCallback->NotifyResultL( event, (TAny*) &iFolderId );
       
   105                     }
       
   106                 }
       
   107              }
       
   108         else
       
   109             {
       
   110             iIsNotification = ETrue;
       
   111             iStatus = KRequestPending; 
       
   112             iNotifier.Notify(iFolderId, iEvents, iStatus );
       
   113             SetActive();
       
   114             }    
       
   115         }
       
   116     }
       
   117     
       
   118 // ---------------------------------------------------------------------------
       
   119 // Activates the asynchronous request
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CMCSReqNotification::ActivateRequest( TInt aReason )
       
   123     {
       
   124     iStatus = KRequestPending; 
       
   125     SetActive();
       
   126     TRequestStatus* temp = &iStatus;
       
   127     User::RequestComplete( temp, aReason );
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Start event's notifications 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CMCSReqNotification::StartNotificationL(TInt aFolderId, 
       
   136         TInt aEvent, MMCSCallback* aCallback )
       
   137     {
       
   138     if(IsActive() )
       
   139       {
       
   140       User::Leave( KErrInUse );
       
   141       }
       
   142     iCallback = aCallback;
       
   143     iFolderId = aFolderId;
       
   144     iEvents = aEvent;
       
   145     CActiveScheduler::Add ( this );
       
   146     ActivateRequest( KErrNone );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Stop event's notifications 
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CMCSReqNotification::StopNotificationL()
       
   154     {
       
   155     if ( !IsActive() )
       
   156         {
       
   157         User::Leave(KErrNotFound);  
       
   158         }
       
   159     else
       
   160         {
       
   161         TRAP_IGNORE( iCallback->NotifyResultL( KErrCancel, NULL ));
       
   162         }
       
   163     }
       
   164 
       
   165