bluetoothappprofiles/avrcp/playerinformation/src/eventsmask.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19  @released
       
    20 */
       
    21 
       
    22 #include "eventsmask.h"
       
    23 
       
    24 #ifdef _DEBUG
       
    25 _LIT(KEventsMask, "TEventsMask");
       
    26 #endif
       
    27 
       
    28 TEventsMask::TEventsMask ()
       
    29 	{
       
    30 	Reset();
       
    31 	}
       
    32 
       
    33 void TEventsMask::Reset()
       
    34 	{
       
    35 	iMask = 0x0000;
       
    36 	iNextSupportedEvent = 0x00;
       
    37 	}
       
    38 
       
    39 TBool TEventsMask::Find(TRegisterNotificationEvent aEvent) const
       
    40 	{
       
    41 	return ( (0x0001 << (aEvent -1)) & iMask ) ? ETrue : EFalse;
       
    42 	}
       
    43 
       
    44 void TEventsMask::Append(TRegisterNotificationEvent aEvent)
       
    45 	{
       
    46 	// the assertion assures that aEvent is a valid argument (in the range) 
       
    47 	__ASSERT_DEBUG((aEvent >= ERegisterNotificationPlaybackStatusChanged) && 
       
    48 		(aEvent < ERegisterNotificationReservedLast), 
       
    49 		User::Panic(KEventsMask, KErrArgument));
       
    50 
       
    51 	iMask |= (0x0001 << (aEvent -1));
       
    52 	}
       
    53 
       
    54 void TEventsMask::Remove(TRegisterNotificationEvent aEvent)
       
    55 	{
       
    56 	// the assertion assures that aEvent is a valid argument (in the range)
       
    57 	__ASSERT_DEBUG((aEvent >= ERegisterNotificationPlaybackStatusChanged) && 
       
    58 		(aEvent < ERegisterNotificationReservedLast), 
       
    59 		User::Panic(KEventsMask, KErrArgument));
       
    60 		
       
    61 	iMask &= ~(0x0001 << (aEvent -1));
       
    62 	}
       
    63 
       
    64 void TEventsMask::Begin()
       
    65 	{
       
    66 	iNextSupportedEvent = 0x00;
       
    67 	}
       
    68 
       
    69 TBool TEventsMask::Next()
       
    70 	{
       
    71 	TUint index = iNextSupportedEvent+1;
       
    72 	
       
    73 	if (index == ERegisterNotificationReservedLast)
       
    74 		{
       
    75 		return EFalse;
       
    76 		}
       
    77 	
       
    78 	while( (!Find((TRegisterNotificationEvent)index)) && (index < ERegisterNotificationReservedLast) )
       
    79 		{
       
    80 		index++;
       
    81 		}
       
    82 	
       
    83 	if (index < ERegisterNotificationReservedLast)
       
    84 		{
       
    85 		iNextSupportedEvent = index;
       
    86 		return ETrue;
       
    87 		}
       
    88 	else
       
    89 		{
       
    90 		return EFalse;
       
    91 		}
       
    92 	}
       
    93 
       
    94 TRegisterNotificationEvent TEventsMask::Get() const
       
    95 	{
       
    96 	// if Get() is called before calling Begin() and at least one call to Next()
       
    97 	// it Panics because iNextSupportedEvent is invalid (equals to 0x00).
       
    98 	__ASSERT_DEBUG(iNextSupportedEvent >= ERegisterNotificationPlaybackStatusChanged, User::Panic(KEventsMask, KErrUnderflow));
       
    99 	// this should never happen, it would mean that iNextSupport overtakes the
       
   100 	// last valid value
       
   101 	__ASSERT_DEBUG(iNextSupportedEvent < ERegisterNotificationReservedLast, User::Panic(KEventsMask, KErrOverflow));
       
   102 
       
   103 	return static_cast<TRegisterNotificationEvent>(iNextSupportedEvent);
       
   104 	}