sdkcreationmw/sdkcommonutils/util/Src/waiter.cpp
author rajpuroh
Wed, 21 Apr 2010 09:56:53 +0530
changeset 1 ac50fd48361b
parent 0 b26acd06ea60
permissions -rw-r--r--
Second Contribution
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     1
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     2
* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     3
* All rights reserved.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     8
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     9
* Initial Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    11
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    12
* Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    13
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    14
* Description: 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    15
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    16
*/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    17
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    18
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    19
// Includes
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    20
#include "waiter.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    21
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    22
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    23
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    24
*	CWaiter()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    25
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    26
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    27
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    28
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    29
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    30
EXPORT_C CWaiter::CWaiter(TInt aPriority)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    31
: CActive(aPriority)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    32
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    33
	CActiveScheduler::Add(this);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    34
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    35
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    36
*	ConstructL(CWaiter_if* cb, int idx)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    37
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    38
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    39
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    40
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    41
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    42
EXPORT_C void CWaiter::ConstructL(CWaiter_if* cb, int idx)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    43
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    44
	iCb = cb;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    45
	iOwner = RThread().Id();	
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    46
	iUserIdx = idx;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    47
	User::LeaveIfError(iMutex.CreateLocal());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    48
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    49
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    50
*	NewL(CWaiter_if* cb, int idx)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    51
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    52
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    53
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    54
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    55
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    56
EXPORT_C CWaiter* CWaiter::NewL(CWaiter_if* cb, int idx, TInt aPriority)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    57
	{	
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    58
	CWaiter* self = new (ELeave)CWaiter(aPriority);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    59
	CleanupStack::PushL(self);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    60
	self->ConstructL(cb, idx);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    61
	CleanupStack::Pop();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    62
	return self;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    63
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    64
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    65
*	DoCancel()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    66
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    67
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    68
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    69
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    70
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    71
EXPORT_C void CWaiter::DoCancel()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    72
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    73
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    74
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    75
*	~CWaiter()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    76
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    77
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    78
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    79
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    80
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    81
EXPORT_C CWaiter::~CWaiter()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    82
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    83
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    84
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    85
*	RunL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    86
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    87
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    88
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    89
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    90
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    91
EXPORT_C void CWaiter::RunL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    92
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    93
	iCb->now(iUserIdx);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    94
	// To make sure only one cllback is delivered at the time
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    95
	iMutex.Signal();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    96
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    97
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    98
*	Wait()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    99
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   100
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   101
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   102
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   103
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   104
EXPORT_C void CWaiter::Wait()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   105
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   106
	iStatus = KRequestPending;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   107
	SetActive();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   108
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   109
/****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   110
*	Complete()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   111
*****************************************************************************
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   112
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   113
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   114
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   115
****************************************************************************/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   116
EXPORT_C void CWaiter::Complete()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   117
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   118
	// To make sure only one cllback is delivered at the time
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   119
	iMutex.Wait();	// Do not deliver new event's before old has been processed
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   120
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   121
	RThread srv;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   122
	srv.Open(iOwner);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   123
	TRequestStatus* p = &iStatus;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   124
	srv.RequestComplete(p,KErrNone);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   125
}