testexecfw/stf/stffw/eventsystem/server/src/waitingevent.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include <e32svr.h>
       
    19 #include <stfeventsystemerrorcodes.h>
       
    20 #include "waitingevent.h"
       
    21 
       
    22 
       
    23 /**
       
    24  * Constructor for performing 1st stage construction
       
    25  */
       
    26 CWaitingEvent::CWaitingEvent(const TInt aOwnerId): iOwnerId(aOwnerId)
       
    27     {
       
    28     RDebug::Print(_L("STF [ESS]: CWaitingEvent::CWaitingEvent() iOwnerId=[%d]"), iOwnerId);
       
    29     }
       
    30 
       
    31 /**
       
    32  * Destructor.
       
    33  */
       
    34 CWaitingEvent::~CWaitingEvent()
       
    35     {
       
    36     RDebug::Print(_L("STF [ESS]: CWaitingEvent::~CWaitingEvent() iOwnerId=[%d]"), iOwnerId);
       
    37     if(iMessage && iState == EEventWaiting)
       
    38         {
       
    39         RDebug::Print(_L("STF [ESS]: Cancelling event [%S] in destructor"), iEventName);
       
    40         iMessage->Complete(KErrCancel);
       
    41         delete iMessage;
       
    42         }
       
    43     delete iEventName;
       
    44     }
       
    45 
       
    46 /**
       
    47  * Two-phased constructor.
       
    48  */
       
    49 CWaitingEvent* CWaitingEvent::NewLC(const TDesC& aEventName, const TInt aOwnerId)
       
    50     {
       
    51     //RDebug::Print(_L("STF [ESS]: CWaitingEvent::NewLC()"));
       
    52     CWaitingEvent* self = new (ELeave) CWaitingEvent(aOwnerId);
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL(aEventName);
       
    55     return self;
       
    56     }
       
    57 
       
    58 /**
       
    59  * Two-phased constructor.
       
    60  */
       
    61 CWaitingEvent* CWaitingEvent::NewL(const TDesC& aEventName, const TInt aOwnerId)
       
    62     {
       
    63     //RDebug::Print(_L("STF [ESS]: CWaitingEvent::NewL()"));
       
    64     CWaitingEvent* self = CWaitingEvent::NewLC(aEventName, aOwnerId);
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 
       
    69 /**
       
    70  * Constructor for performing 2nd stage construction
       
    71  */
       
    72 void CWaitingEvent::ConstructL(const TDesC& aEventName)
       
    73     {
       
    74     //RDebug::Print(_L("STF [ESS]: CWaitingEvent::ConstructL()"));
       
    75     iEventName = aEventName.AllocL();
       
    76     RDebug::Print(_L("STF [ESS]: Event [%S] is set state to [EEventRequested]"), iEventName);
       
    77     iState = EEventRequested;
       
    78     RDebug::Print(_L("STF [ESS]: Event [%S] is set iEventSetWhenRequested notification to [EFalse]"), iEventName);    
       
    79     iEventSetWhenRequested = EFalse;
       
    80     }
       
    81 
       
    82 /**
       
    83  * Checks if event name is the same as provided in argument
       
    84  */
       
    85 TInt CWaitingEvent::IsMatchingEvent(const TDesC& aEventName)
       
    86     {
       
    87     return (aEventName.Compare(*iEventName) == 0) ? (1) : (0);
       
    88     }
       
    89 
       
    90 /**
       
    91  * Checks if event name is the same as provided in argument
       
    92  */
       
    93 TInt CWaitingEvent::IsMatchingEvent(const TDesC& aEventName, const TInt aOwnerId)
       
    94     {
       
    95     return (aEventName.Compare(*iEventName) == 0 && iOwnerId == aOwnerId) ? (1) : (0);
       
    96     }
       
    97 
       
    98 /**
       
    99  * Checks if event's session is the same as provided in argument
       
   100  */
       
   101 TInt CWaitingEvent::IsMatchingSession(const CSession2* aSession)
       
   102     {
       
   103     return (aSession == iSession);
       
   104     }
       
   105 
       
   106 /**
       
   107  * Complete event
       
   108  */
       
   109 void CWaitingEvent::CompleteEventL()
       
   110     {
       
   111     RDebug::Print(_L("STF [ESS]: CWaitingEvent::CompleteEventL(): Completing event [%S]"), iEventName);
       
   112     if(iState == EEventWaiting)
       
   113         {
       
   114         iMessage->Complete(KErrNone);
       
   115         delete iMessage;
       
   116         iMessage = NULL;
       
   117         RDebug::Print(_L("STF [ESS]: Event [%S] switches state to [EEventRequested]"), iEventName);
       
   118         iState = EEventRequested;
       
   119         if(iEventSetWhenRequested)
       
   120             {
       
   121             RDebug::Print(_L("STF [ESS]: Event [%S] switches iEventSetWhenRequested notification to [EFalse]"), iEventName);    
       
   122             iEventSetWhenRequested = EFalse;
       
   123             }
       
   124         }
       
   125     }
       
   126     
       
   127 /**
       
   128  * Cancel event (because i.e. test case is being cancelled)
       
   129  */
       
   130 void CWaitingEvent::CancelEvent()
       
   131     {
       
   132     RDebug::Print(_L("STF [ESS]: CWaitingEvent::CancelEvent()"));
       
   133     if(iMessage && iState == EEventWaiting)
       
   134         {
       
   135         iMessage->Complete(KErrCancel);
       
   136         delete iMessage;
       
   137         iMessage = NULL;
       
   138         RDebug::Print(_L("STF [ESS]: Event [%S] switches state to [EEventRequested]"), iEventName);
       
   139         iState = EEventRequested;
       
   140         }
       
   141     }
       
   142 
       
   143 /**
       
   144  * Wait for event (allowed only if event is in requested state)
       
   145  */
       
   146 void CWaitingEvent::WaitL(const RMessage2& aMessage, const CSession2* aSession)
       
   147     {
       
   148     __ASSERT_ALWAYS(aSession != NULL, PanicClient(aMessage, EEventSystemSessionNotDefined));
       
   149 
       
   150     // Check if we can wait for event
       
   151     if(iState != EEventRequested)
       
   152         {
       
   153         RDebug::Print(_L("STF [ESS]: CWaitingEvent::WaitL() Event not requested"));
       
   154         User::Leave(EEventSystemNotInRequestedState);
       
   155         }
       
   156 
       
   157     // Set values
       
   158     iMessage = new RMessage2(aMessage);
       
   159     iSession = const_cast<CSession2*>(aSession);
       
   160     
       
   161     // Switch to real waiting
       
   162     RDebug::Print(_L("STF [ESS]: Event [%S] switches state to [EEventWaiting]"), iEventName);
       
   163     iState = EEventWaiting;
       
   164     
       
   165     // If indication event was set when this event was in requested state, complete immediately
       
   166     if(iEventSetWhenRequested)
       
   167          {
       
   168          CompleteEventL();
       
   169          }
       
   170     }
       
   171 
       
   172 /**
       
   173  * Give event name
       
   174  */
       
   175 const TDesC& CWaitingEvent::EventName()
       
   176     {
       
   177     return *iEventName;
       
   178     }
       
   179 
       
   180 /**
       
   181  * Check if event is in requested state
       
   182  */
       
   183 TInt CWaitingEvent::IsRequested()
       
   184     {
       
   185     return iState == EEventRequested;
       
   186     }
       
   187         
       
   188 /**
       
   189  * Check if event is waitng
       
   190  */
       
   191 TInt CWaitingEvent::IsWaiting()
       
   192     {
       
   193     return iState == EEventWaiting;
       
   194     }
       
   195 
       
   196 /**
       
   197 Panics the client
       
   198 */
       
   199 void CWaitingEvent::PanicClient(const RMessage2& aMessage, const TInt aPanic) const
       
   200     {
       
   201     RDebug::Print(_L("STF [ESS]: CWaitingEvent::PanicClient"));
       
   202     _LIT(KMessage, "CEventSystemSession");
       
   203     aMessage.Panic(KMessage, aPanic);
       
   204     }
       
   205 
       
   206 // Notify requested event, that indicatin event 
       
   207 void CWaitingEvent::NotifyRequestedEventL()
       
   208     {
       
   209     if(!iEventSetWhenRequested)
       
   210         {
       
   211         RDebug::Print(_L("STF [ESS]: Event [%S] switches iEventSetWhenRequested notification to [ETrue]"), iEventName);    
       
   212         iEventSetWhenRequested = ETrue;
       
   213         }
       
   214     }
       
   215 
       
   216 // Give owner id 
       
   217 TInt CWaitingEvent::OwnerId()
       
   218     {
       
   219     return iOwnerId;
       
   220     }     
       
   221 // EOF