os/persistentdata/persistentstorage/centralrepository/cenrepsrv/sessnotf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "sessnotf.h"
sl@0
    17
sl@0
    18
CSessionNotifier::CSessionNotifier() :
sl@0
    19
	iIdReportingOn(ETrue), iRequests(KArrayGranularity, _FOFF(SRequest, id))
sl@0
    20
	{
sl@0
    21
	}
sl@0
    22
sl@0
    23
CSessionNotifier::~CSessionNotifier()
sl@0
    24
	{
sl@0
    25
	CancelAllRequests();
sl@0
    26
	}
sl@0
    27
sl@0
    28
void CSessionNotifier::Notify(TUint32 aId)
sl@0
    29
	{
sl@0
    30
	SRequest s;
sl@0
    31
	s.id = aId;
sl@0
    32
sl@0
    33
	// Check if iIdReportingOn is True. If  it's false return KUnspecifiedKey, otherwise return
sl@0
    34
	// the individual key. One exception to this is where the individual key is KRequestPending.
sl@0
    35
	// To prevent problems in AO's using key notifications KUnspecifiedKey will be returned to
sl@0
    36
	// notify for changes to this key.
sl@0
    37
	TUint32 reportedId = (iIdReportingOn  && (aId != static_cast<TUint32>(KRequestPending))) ? aId : KUnspecifiedKey;
sl@0
    38
	
sl@0
    39
	TInt i = iRequests.FindInUnsignedKeyOrder(s);
sl@0
    40
	if(i>=0)
sl@0
    41
		{
sl@0
    42
		iRequests[i].msg.Complete(reportedId);
sl@0
    43
		iRequests.Remove(i);
sl@0
    44
		}
sl@0
    45
sl@0
    46
	for(i=iGroupRequests.Count()-1; i>=0; i--)
sl@0
    47
		{
sl@0
    48
		SGroupRequest& s = iGroupRequests[i];
sl@0
    49
		if((aId & s.idMask)==(s.partialId & s.idMask))
sl@0
    50
			{
sl@0
    51
			s.msg.Complete(reportedId);
sl@0
    52
			iGroupRequests.Remove(i);
sl@0
    53
			}
sl@0
    54
		}
sl@0
    55
	}
sl@0
    56
sl@0
    57
TInt CSessionNotifier::AddRequest(TUint32 aId, TClientRequest aMessage)
sl@0
    58
	{
sl@0
    59
	SRequest s;
sl@0
    60
	s.id = aId;
sl@0
    61
	s.msg = aMessage;
sl@0
    62
sl@0
    63
	return iRequests.InsertInUnsignedKeyOrder(s);
sl@0
    64
	}
sl@0
    65
sl@0
    66
TInt CSessionNotifier::AddRequest(TUint32 aPartialId, TUint32 aIdMask, TClientRequest aMessage)
sl@0
    67
	{
sl@0
    68
	SGroupRequest s;
sl@0
    69
	s.partialId = aPartialId;;
sl@0
    70
	s.idMask = aIdMask;
sl@0
    71
	s.msg = aMessage;
sl@0
    72
sl@0
    73
	return iGroupRequests.Append(s);
sl@0
    74
	}
sl@0
    75
sl@0
    76
TInt CSessionNotifier::CancelRequest(TUint32 aId)
sl@0
    77
	{
sl@0
    78
	SRequest s;
sl@0
    79
	s.id = aId;
sl@0
    80
	
sl@0
    81
	TInt r = iRequests.FindInUnsignedKeyOrder(s);
sl@0
    82
	if(r>=0)
sl@0
    83
		{
sl@0
    84
		iRequests[r].msg.Complete(KUnspecifiedKey);
sl@0
    85
		iRequests.Remove(r);
sl@0
    86
		}
sl@0
    87
sl@0
    88
	return r>=0 ? KErrNone : KErrNotFound;
sl@0
    89
	}
sl@0
    90
sl@0
    91
TInt CSessionNotifier::CancelRequest(TUint32 aPartialId, TUint32 aIdMask)
sl@0
    92
	{
sl@0
    93
	TInt n = 0;
sl@0
    94
	for(TInt i=iGroupRequests.Count()-1; i>=0; i--)
sl@0
    95
		{
sl@0
    96
		SGroupRequest& s = iGroupRequests[i];
sl@0
    97
		if(aPartialId==s.partialId && aIdMask==s.idMask)
sl@0
    98
			{
sl@0
    99
			n++;
sl@0
   100
			s.msg.Complete(KUnspecifiedKey);
sl@0
   101
			iGroupRequests.Remove(i);
sl@0
   102
			}
sl@0
   103
		}
sl@0
   104
sl@0
   105
	return n>0 ? KErrNone : KErrNotFound;
sl@0
   106
	}
sl@0
   107
sl@0
   108
TInt CSessionNotifier::CancelAllRequests()
sl@0
   109
	{
sl@0
   110
	TInt n = iRequests.Count();
sl@0
   111
	while(n-->0)
sl@0
   112
		iRequests[n].msg.Complete(KUnspecifiedKey);
sl@0
   113
sl@0
   114
	iRequests.Reset();
sl@0
   115
sl@0
   116
	n = iGroupRequests.Count();
sl@0
   117
	while(n-->0)
sl@0
   118
		iGroupRequests[n].msg.Complete(KUnspecifiedKey);
sl@0
   119
sl@0
   120
	iGroupRequests.Reset();
sl@0
   121
sl@0
   122
	return KErrNone;
sl@0
   123
	}
sl@0
   124
sl@0
   125
void CSessionNotifier::IdReportingOn()
sl@0
   126
	{
sl@0
   127
	iIdReportingOn = ETrue;
sl@0
   128
	}
sl@0
   129
sl@0
   130
void CSessionNotifier::IdReportingOff()
sl@0
   131
	{
sl@0
   132
	iIdReportingOn = EFalse;
sl@0
   133
	}