dosservices/dosserver/src/dosclieventnotifier.cpp
changeset 0 4e1aa6a622a0
child 15 b2f9f823b5fb
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002 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 *    Implementation for the CDosEventNotifier class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "DosSvrServices.h"
       
    21 
       
    22 //
       
    23 // ---------------------------------------------------------
       
    24 // CDosEventNotifier Constructor
       
    25 // ---------------------------------------------------------
       
    26 //  
       
    27 
       
    28 CDosEventNotifier::CDosEventNotifier(CDosEventListenerBase* aListener,TPriority aPriority)
       
    29 : CActive(aPriority)
       
    30 {
       
    31 	CActiveScheduler::Add(this);
       
    32 	iListener = aListener;
       
    33 }
       
    34 
       
    35 //
       
    36 // ---------------------------------------------------------
       
    37 // CDosEventNotifier Destructor
       
    38 // ---------------------------------------------------------
       
    39 //  
       
    40 
       
    41 CDosEventNotifier::~CDosEventNotifier()
       
    42 {
       
    43 	Cancel();
       
    44 	iReceiver.Close();
       
    45 }
       
    46 
       
    47 //
       
    48 // ---------------------------------------------------------
       
    49 // CDosEventNotifier::NewL
       
    50 // ---------------------------------------------------------
       
    51 //  
       
    52 
       
    53 CDosEventNotifier* CDosEventNotifier::NewL(RDosServer& aServer,CDosEventListenerBase* aListener)
       
    54 {
       
    55 	CDosEventNotifier* result = new(ELeave) CDosEventNotifier(aListener);
       
    56 
       
    57 	CleanupStack::PushL(result);
       
    58 	result->ConstructL(aServer);
       
    59 	CleanupStack::Pop();
       
    60 
       
    61 	return result;
       
    62 }
       
    63 
       
    64 //
       
    65 // ---------------------------------------------------------
       
    66 // CDosEventNotifier::ConstructL
       
    67 // ---------------------------------------------------------
       
    68 //  
       
    69 
       
    70 void CDosEventNotifier::ConstructL(RDosServer& aServer)
       
    71 {
       
    72 	User::LeaveIfError(iReceiver.Open(aServer));
       
    73 }
       
    74 
       
    75 //
       
    76 // ---------------------------------------------------------
       
    77 // CDosEventNotifier::RunL
       
    78 // ---------------------------------------------------------
       
    79 //  
       
    80 
       
    81 void CDosEventNotifier::RunL()
       
    82 {
       
    83 	if(iStatus.Int()==KErrNone)
       
    84 	{
       
    85 		TRegisterEvent currentEvent = {iReceiver.Event(),iReceiver.ParameterSize(),iReceiver.Queue()};
       
    86 
       
    87 		iListener->HandleEventL(currentEvent,/*par*/ iReceiver.Parameter());
       
    88 	
       
    89 		iReceiver.WaitEvent(iStatus);
       
    90 		SetActive();
       
    91 	}
       
    92 	else
       
    93 		User::Leave(iStatus.Int());
       
    94 }
       
    95 
       
    96 //
       
    97 // ---------------------------------------------------------
       
    98 // CDosEventNotifier::RunError
       
    99 // ---------------------------------------------------------
       
   100 //  
       
   101 
       
   102 TInt CDosEventNotifier::RunError(TInt aError)
       
   103 {
       
   104 	TBool stopListening = EFalse;
       
   105 
       
   106 	iListener->OnError(aError,stopListening);
       
   107 	
       
   108 	if(aError!=KErrServerTerminated && !stopListening)
       
   109 	{
       
   110 	   iReceiver.WaitEvent(iStatus);
       
   111 	   SetActive();
       
   112 	}
       
   113 
       
   114 	return KErrNone;
       
   115 }
       
   116 
       
   117 //
       
   118 // ---------------------------------------------------------
       
   119 // CDosEventNotifier::DoCancel
       
   120 // ---------------------------------------------------------
       
   121 //  
       
   122 
       
   123 void CDosEventNotifier::DoCancel()
       
   124 {
       
   125 	iReceiver.CancelWaitEvent();
       
   126 	iReceiver.UnRegister(); // No need to check if it's registered or not.
       
   127 }
       
   128 
       
   129 //
       
   130 // ---------------------------------------------------------
       
   131 // CDosEventNotifier::StartListeningL
       
   132 // ---------------------------------------------------------
       
   133 //  
       
   134 
       
   135 void CDosEventNotifier::StartListeningL(TUint aEvent,TInt aParamSize,TQueueType aQueue)
       
   136 {
       
   137 	User::LeaveIfError(iReceiver.Register(aEvent,aParamSize,aQueue));
       
   138 	iReceiver.WaitEvent(iStatus);
       
   139 	
       
   140 	SetActive();
       
   141 }
       
   142 
       
   143