os/mm/devsoundextensions/restrictedaudiooutput/RestrictedAudioOutputBase/src/RestrictedAudioOutputImpl.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/restrictedaudiooutput/RestrictedAudioOutputBase/src/RestrictedAudioOutputImpl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,244 @@
1.4 +/*
1.5 +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: This is the implementation of the CRestrictedAudioOutputImpl class.
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +
1.24 +// INCLUDE FILES
1.25 +#include <e32svr.h>
1.26 +#include "RestrictedAudioOutputImpl.h"
1.27 +
1.28 +#ifdef _DEBUG
1.29 +#define DEBPRN0(str) RDebug::Print(str, this)
1.30 +#define DEBPRN1(str) RDebug::Printf( "%s %s", __PRETTY_FUNCTION__, str );
1.31 +#else
1.32 +#define DEBPRN0
1.33 +#define DEBPRN1(str)
1.34 +#endif
1.35 +
1.36 +const TInt KGranularity=20;
1.37 +
1.38 +
1.39 +// -----------------------------------------------------------------------------
1.40 +// CRestrictedAudioOutputImpl::CRestrictedAudioOutputImpl
1.41 +// C++ default constructor can NOT contain any code, that
1.42 +// might leave.
1.43 +// -----------------------------------------------------------------------------
1.44 +//
1.45 +CRestrictedAudioOutputImpl::CRestrictedAudioOutputImpl()
1.46 +: iAllowedOutputPrefArray(KGranularity)
1.47 + {
1.48 + DEBPRN0(_L("CRestrictedAudioOutputImpl::[0x%x]::CRestrictedAudioOutputImpl\n"));
1.49 + iAllowedOutputPrefArray.Reset();
1.50 + }
1.51 +
1.52 +
1.53 +// -----------------------------------------------------------------------------
1.54 +// CRestrictedAudioOutputImpl::ConstructL
1.55 +// Symbian 2nd phase constructor can leave.
1.56 +// assumes that iParent has already been set up properly
1.57 +// -----------------------------------------------------------------------------
1.58 +//
1.59 +void CRestrictedAudioOutputImpl::ConstructL()
1.60 + {
1.61 +
1.62 + }
1.63 +
1.64 +
1.65 +// Two-phased constructor.
1.66 +CRestrictedAudioOutputImpl* CRestrictedAudioOutputImpl::NewL()
1.67 + {
1.68 +#ifdef _DEBUG
1.69 + RDebug::Print(_L("CRestrictedAudioOutputImpl::NewL\n"));
1.70 +#endif
1.71 +
1.72 + CRestrictedAudioOutputImpl* self = new(ELeave) CRestrictedAudioOutputImpl();
1.73 + CleanupStack::PushL(self);
1.74 + self->ConstructL();
1.75 + CleanupStack::Pop(self);
1.76 + return self;
1.77 +
1.78 + }
1.79 +
1.80 +// -----------------------------------------------------------------------------
1.81 +// CRestrictedAudioOutputImpl::~CRestrictedAudioOutputImpl
1.82 +// Destructor
1.83 +// -----------------------------------------------------------------------------
1.84 +//
1.85 +CRestrictedAudioOutputImpl::~CRestrictedAudioOutputImpl()
1.86 + {
1.87 + DEBPRN0(_L("CRestrictedAudioOutputImpl[0x%x]::~CRestrictedAudioOutputImpl\n"));
1.88 +
1.89 + iAllowedOutputPrefArray.Close();
1.90 +
1.91 + DEBPRN0(_L("CRestrictedAudioOutputImpl[0x%x]::~CRestrictedAudioOutputImpl:EXIT"));
1.92 + }
1.93 +
1.94 +// ---------------------------------------------------------
1.95 +// CRestrictedAudioOutputImpl::AppendAllowedOutput
1.96 +// ?implementation_description
1.97 +// (other items were commented in a header).
1.98 +// ---------------------------------------------------------
1.99 +//
1.100 +TInt CRestrictedAudioOutputImpl::AppendAllowedOutput( CRestrictedAudioOutput::TAllowedOutputPreference aOutput)
1.101 + {
1.102 + DEBPRN0(_L("CRestrictedAudioOutputImpl[0x%x]::AppendAllowedOutput\n"));
1.103 +
1.104 +#ifdef _DEBUG
1.105 + RDebug::Print(_L("Append Output: %d\n"), aOutput);
1.106 +#endif
1.107 +
1.108 + // Check to see if it's in array already
1.109 + TBool found = ExistsInArray(aOutput);
1.110 + if (found)
1.111 + {
1.112 +#ifdef _DEBUG
1.113 + RDebug::Print(_L("Append Output ERROR. Output already in List\n"));
1.114 +#endif
1.115 + return KErrAlreadyExists;
1.116 + }
1.117 +
1.118 + TInt err = KErrNone;
1.119 + TRAP(err,iAllowedOutputPrefArray.AppendL(aOutput));
1.120 + if (err != KErrNone)
1.121 + return err;
1.122 +
1.123 + return KErrNone;
1.124 + }
1.125 +
1.126 +// ---------------------------------------------------------
1.127 +// CRestrictedAudioOutputImpl::RemoveAllowedOutput
1.128 +// ?implementation_description
1.129 +// (other items were commented in a header).
1.130 +// ---------------------------------------------------------
1.131 +//
1.132 +TInt CRestrictedAudioOutputImpl::RemoveAllowedOutput(CRestrictedAudioOutput::TAllowedOutputPreference aOutput)
1.133 + {
1.134 +#ifdef _DEBUG
1.135 + RDebug::Print(_L("Remove Output: %d\n"), aOutput);
1.136 +#endif
1.137 +
1.138 + // Make sure it's in list
1.139 + TBool found = ExistsInArray(aOutput);
1.140 + if (!found)
1.141 + {
1.142 + #ifdef _DEBUG
1.143 + RDebug::Print(_L("Remove Output ERROR. Output not in List\n"));
1.144 + #endif
1.145 + return KErrNotFound;
1.146 + }
1.147 +
1.148 + for (TInt i = 0; i < iAllowedOutputPrefArray.Count(); i++)
1.149 + {
1.150 + if (iAllowedOutputPrefArray[i] == aOutput)
1.151 + {
1.152 + iAllowedOutputPrefArray.Remove(i);
1.153 + #ifdef _DEBUG
1.154 + RDebug::Print(_L("RemoveAllowedOutput: Item Removed\n"));
1.155 + #endif
1.156 + break;
1.157 + }
1.158 + }
1.159 +
1.160 + return KErrNone;
1.161 + }
1.162 +
1.163 +// ---------------------------------------------------------
1.164 +// CRestrictedAudioOutputImpl::GetAllowedOutput
1.165 +// ?implementation_description
1.166 +// (other items were commented in a header).
1.167 +// ---------------------------------------------------------
1.168 +//
1.169 +TInt CRestrictedAudioOutputImpl::GetAllowedOutput(TInt aIndex, CRestrictedAudioOutput::TAllowedOutputPreference& aOutput)
1.170 + {
1.171 +#ifdef _DEBUG
1.172 + RDebug::Print(_L("CRestrictedAudioOutputImpl::GetAllowedOutput for index: %d\n"), aIndex);
1.173 +#endif
1.174 +
1.175 + // Verify aIndex valid:
1.176 + if (aIndex >= iAllowedOutputPrefArray.Count())
1.177 + {
1.178 + #ifdef _DEBUG
1.179 + RDebug::Print(_L("GetAllowedOutput ERROR. Invalid Index: %d\n"),aIndex);
1.180 + #endif
1.181 + return KErrNotFound;
1.182 + }
1.183 + aOutput = iAllowedOutputPrefArray[aIndex];
1.184 + #ifdef _DEBUG
1.185 + RDebug::Print(_L("GetAllowedOutput: Returning %d\n"),aOutput);
1.186 + #endif
1.187 + return KErrNone;
1.188 + }
1.189 +
1.190 +// ---------------------------------------------------------
1.191 +// CRestrictedAudioOutputImpl::GetAllowedOutputCount
1.192 +// ?implementation_description
1.193 +// (other items were commented in a header).
1.194 +// ---------------------------------------------------------
1.195 +//
1.196 +TInt CRestrictedAudioOutputImpl::GetAllowedOutputCount(TInt& aSize)
1.197 + {
1.198 +#ifdef _DEBUG
1.199 + RDebug::Print(_L("CRestrictedAudioOutputImpl::GetAllowedOutputCount\n"));
1.200 +#endif
1.201 + aSize = iAllowedOutputPrefArray.Count();
1.202 + return KErrNone;
1.203 + }
1.204 +
1.205 +// ---------------------------------------------------------
1.206 +// CRestrictedAudioOutputImpl::Reset
1.207 +// ?implementation_description
1.208 +// (other items were commented in a header).
1.209 +// ---------------------------------------------------------
1.210 +//
1.211 +TInt CRestrictedAudioOutputImpl::Reset()
1.212 + {
1.213 + iAllowedOutputPrefArray.Reset();
1.214 + return KErrNone;
1.215 + }
1.216 +
1.217 +// ---------------------------------------------------------
1.218 +// CRestrictedAudioOutputImpl::Commit
1.219 +// ?implementation_description
1.220 +// (other items were commented in a header).
1.221 +// ---------------------------------------------------------
1.222 +//
1.223 +TInt CRestrictedAudioOutputImpl::Commit()
1.224 + {
1.225 + return KErrNone;
1.226 + }
1.227 +
1.228 +// ---------------------------------------------------------
1.229 +// CRestrictedAudioOutputImpl::ExistsInArray
1.230 +// ?implementation_description
1.231 +// (other items were commented in a header).
1.232 +// ---------------------------------------------------------
1.233 +//
1.234 +TBool CRestrictedAudioOutputImpl::ExistsInArray(CRestrictedAudioOutput::TAllowedOutputPreference& aOutput)
1.235 + {
1.236 +
1.237 + for (TInt i = 0; i < iAllowedOutputPrefArray.Count(); i++)
1.238 + {
1.239 + if (iAllowedOutputPrefArray[i] == aOutput)
1.240 + return ETrue;
1.241 + }
1.242 +
1.243 + return EFalse;
1.244 + }
1.245 +
1.246 +// End of file
1.247 +