1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/src/BASSND.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,512 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <bassnd.h>
1.20 +#include <baflpan.h>
1.21 +#include <basched.h>
1.22 +#include <bautils.h>
1.23 +#include "BaSsndStore.h"
1.24 +
1.25 +const TInt KSystemSoundArrayGranularity =4;
1.26 +const TInt KNullFixedSequence=-1;
1.27 +
1.28 +// Full path and name of system sound file.
1.29 +_LIT(KSystemSoundFilePath,"_:\\system\\data\\syssnd.dat");
1.30 +// Buffer descriptor to hold full path and name of system sound file.
1.31 +typedef TBuf<28> TSystemSoundFileName; // a multiple of 4
1.32 +
1.33 +_LIT(KSystemSoundDefaultSound,"z:\\system\\SystemSounds\\ring.wav");
1.34 +_LIT(KSystemSoundDefaultRing,"z:\\system\\SystemSounds\\ring.wav");
1.35 +_LIT(KSystemSoundDefaultAlarm,"z:\\system\\SystemSounds\\alarm.wav");
1.36 +_LIT(KSystemSoundDefaultMessage,"z:\\system\\SystemSounds\\message.wav");
1.37 +
1.38 +//
1.39 +// class TBaSystemSoundType
1.40 +//
1.41 +
1.42 +EXPORT_C TBaSystemSoundType::TBaSystemSoundType()
1.43 + : iMajor(KNullUid), iMinor(KNullUid)
1.44 +/** Constructs a TBaSystemSoundType object with a null category and instance. */
1.45 + {}
1.46 +
1.47 +
1.48 +EXPORT_C TBaSystemSoundType::TBaSystemSoundType(TBaSystemSoundUid aMajor,TUid aMinor)
1.49 + : iMajor(aMajor), iMinor(aMinor)
1.50 +/** Constructs a TBaSystemSoundType object with the specified category and, optionally,
1.51 +instance.
1.52 +
1.53 +@param aMajor The category, this can be a file, tone or sequence.
1.54 +@param aMinor The instance of the category. This is optional. */
1.55 + {}
1.56 +
1.57 +
1.58 +EXPORT_C TBool TBaSystemSoundType::operator==(const TBaSystemSoundType& aType) const
1.59 +/** Tests whether the sound's category and instance are the same as that specified.
1.60 +
1.61 +@param aType The category and instance to test.
1.62 +@return ETrue if the sound's category and instance is the same as aType, EFalse
1.63 +otherwise. */
1.64 + {
1.65 + return (iMajor==aType.iMajor && iMinor==aType.iMinor);
1.66 + }
1.67 +
1.68 +//
1.69 +// class TBaSystemSoundInfo
1.70 +//
1.71 +TBool TBaSystemSoundInfo::TTone::IsNull() const
1.72 +/** Tests whether the sound's category and instance are null.
1.73 +@internalAll
1.74 +@return ETrue if the sound's category and instance are null, EFalse
1.75 +otherwise. */
1.76 + {
1.77 + return iFrequency==0 && iDuration.Int()==0;
1.78 + }
1.79 +
1.80 +
1.81 +void TBaSystemSoundInfo::TTone::InternalizeL(RReadStream& aStream)
1.82 +/**
1.83 +@internalAll
1.84 +Gets a tone's frequency and duration.
1.85 +
1.86 +@param aStream The stream from which the tone's frequency and duration is read.
1.87 +*/
1.88 + {
1.89 + iFrequency=aStream.ReadInt32L();
1.90 + iDuration=aStream.ReadInt32L();
1.91 + }
1.92 +
1.93 +
1.94 +void TBaSystemSoundInfo::TTone::ExternalizeL(RWriteStream& aStream) const
1.95 +/**
1.96 +@internalAll
1.97 +Saves a tone's frequency and duration.
1.98 +
1.99 +@param aStream The stream to which the tone's frequency and duration is
1.100 +written.
1.101 +*/
1.102 +
1.103 + {
1.104 + aStream.WriteInt32L(iFrequency);
1.105 + aStream.WriteInt32L(iDuration.Int());
1.106 + }
1.107 +
1.108 +EXPORT_C TBaSystemSoundInfo::TBaSystemSoundInfo()
1.109 + : iType(KNullUid,KNullUid), iVolume(KSystemSoundDefaultVolume), iPriority(KSystemSoundDefaultPriority),
1.110 + iName(KNullDesC), iFixedSequence(KNullFixedSequence), iTone(TTone())
1.111 +/** Constructs a default TBaSystemSoundInfo object. This object has a null type,
1.112 +default volume, default priority, null name, null fixed sequence, and tone
1.113 +of TTone. */
1.114 + {}
1.115 +
1.116 +EXPORT_C TBaSystemSoundInfo::TBaSystemSoundInfo(const TBaSystemSoundType& aType,const TBaSystemSoundName& aName,
1.117 + TInt aVolume,TInt aPriority)
1.118 + : iType(aType), iVolume(aVolume), iPriority(aPriority), iName(aName),
1.119 + iFixedSequence(KNullFixedSequence), iTone(TTone())
1.120 +/** Constructs a TBaSystemSoundInfo object with the specified type and file name.
1.121 +The sound has default volume and priority.
1.122 +
1.123 +@param aType Sound type
1.124 +@param aName Sound name
1.125 +@param aVolume Sound volume
1.126 +@param aPriority Sound priority */
1.127 + {}
1.128 +
1.129 +EXPORT_C TBaSystemSoundInfo::TBaSystemSoundInfo(const TBaSystemSoundType& aType,TInt aFixedSequence,
1.130 + TInt aVolume,TInt aPriority)
1.131 + : iType(aType), iVolume(aVolume), iPriority(aPriority), iName(KNullDesC),
1.132 + iFixedSequence(aFixedSequence), iTone(TTone())
1.133 +/** Constructs a TBaSystemSoundInfo object with the specified type and sequence.
1.134 +The sound has default volume and priority.
1.135 +
1.136 +@param aType Sound type
1.137 +@param aFixedSequence Sound sequence
1.138 +@param aVolume Sound volume
1.139 +@param aPriority Sound priority */
1.140 + {}
1.141 +
1.142 +EXPORT_C TBaSystemSoundInfo::TBaSystemSoundInfo(const TBaSystemSoundType& aType,TTone aTone,
1.143 + TInt aVolume,TInt aPriority)
1.144 + : iType(aType), iVolume(aVolume), iPriority(aPriority), iName(KNullDesC),
1.145 + iFixedSequence(KNullFixedSequence), iTone(aTone)
1.146 +/** Constructs a TBaSystemSoundInfo object with the specified type and tone. The
1.147 +sound has default volume and priority.
1.148 +
1.149 +@param aType Sound type
1.150 +@param aTone Sound tone
1.151 +@param aVolume Sound volume
1.152 +@param aPriority Sound priority */
1.153 + {}
1.154 +
1.155 +
1.156 +EXPORT_C TBaSystemSoundInfo::TSoundCategory TBaSystemSoundInfo::SoundCategory() const
1.157 +/** Gets the sound's category.
1.158 +
1.159 +@return The system sound's category, or NULL if the sound is not a file, sequence,
1.160 +or tone. */
1.161 + {
1.162 + TBaSystemSoundInfo::TSoundCategory cat=TBaSystemSoundInfo::ENull;
1.163 + if (!iTone.IsNull())
1.164 + cat=TBaSystemSoundInfo::ETone;
1.165 + else if (iName.Length())
1.166 + cat=TBaSystemSoundInfo::EFile;
1.167 + else if (iFixedSequence!=KNullFixedSequence)
1.168 + cat=TBaSystemSoundInfo::ESequence;
1.169 + return cat;
1.170 + }
1.171 +
1.172 +
1.173 +EXPORT_C void TBaSystemSoundInfo::SetFixedSequenceNumber(TInt aNumber)
1.174 +/** Replaces the current sound with the specified sequence number.
1.175 +
1.176 +@param aNumber The sequence number with which to replace the current sound. */
1.177 + {
1.178 + iFixedSequence=aNumber;
1.179 + iName=KNullDesC();
1.180 + iTone=TTone();
1.181 + }
1.182 +
1.183 +
1.184 +EXPORT_C void TBaSystemSoundInfo::SetFileName(const TBaSystemSoundName& aFileName)
1.185 +/** Replaces the current sound with the specified file.
1.186 +
1.187 +@param aFileName The file with which to replace the current sound. */
1.188 + {
1.189 + iFixedSequence=KNullFixedSequence;
1.190 + iName=aFileName;
1.191 + iTone=TTone();
1.192 + }
1.193 +
1.194 +
1.195 +EXPORT_C void TBaSystemSoundInfo::SetTone(const TTone& aTone)
1.196 +/** Replaces the current sound with the specified tone.
1.197 +
1.198 +@param aTone The tone with which to replace the current sound. */
1.199 + {
1.200 + iFixedSequence=KNullFixedSequence;
1.201 + iName=KNullDesC();
1.202 + iTone=aTone;
1.203 + }
1.204 +/** Internalises an object of this class from a read stream.
1.205 +Presence of this function means that the standard templated operator>>()
1.206 +can be used to internalise objects of this class.
1.207 +
1.208 +@param aStream The stream from which the object is to be internalised.
1.209 +@internalAll
1.210 +*/
1.211 +void TBaSystemSoundInfo::InternalizeL(RReadStream& aStream)
1.212 + {
1.213 + aStream >> iType.iMajor;
1.214 + aStream >> iType.iMinor;
1.215 + iVolume = aStream.ReadInt32L();
1.216 + iPriority = aStream.ReadInt32L();
1.217 +
1.218 + TSoundCategory cat = (TSoundCategory)aStream.ReadInt32L();
1.219 + switch (cat)
1.220 + {
1.221 + case EFile:
1.222 + {
1.223 + TUint16 pathLength = aStream.ReadUint16L();
1.224 + if (pathLength > iName.MaxLength())
1.225 + {
1.226 + User::Leave(KErrCorrupt);
1.227 + }
1.228 + TUint16* buf = const_cast<TUint16*>(iName.Ptr());
1.229 + aStream.ReadL(buf, pathLength);
1.230 + iName.SetLength(pathLength);
1.231 +
1.232 + iFixedSequence=KNullFixedSequence;
1.233 + iTone=TTone();
1.234 + }
1.235 + break;
1.236 +
1.237 + case ESequence:
1.238 + iFixedSequence = aStream.ReadInt32L();
1.239 + iName=KNullDesC;
1.240 + iTone=TTone();
1.241 + break;
1.242 +
1.243 + case ETone:
1.244 + aStream >> iTone;
1.245 + iName=KNullDesC;
1.246 + iFixedSequence=KNullFixedSequence;
1.247 + break;
1.248 +
1.249 + default:
1.250 + User::Leave(KErrCorrupt);
1.251 + }
1.252 + }
1.253 +
1.254 +/** Externalises an object of this class to a write stream.
1.255 +The presence of this function means that the standard templated operator<<()
1.256 +can be used to externalise objects of this class.
1.257 +
1.258 +@param aStream Stream to which the object should be externalised.
1.259 +*/
1.260 +void TBaSystemSoundInfo::ExternalizeL(RWriteStream& aStream) const
1.261 + {
1.262 + aStream << iType.iMajor;
1.263 + aStream << iType.iMinor;
1.264 + aStream.WriteInt32L(iVolume);
1.265 + aStream.WriteInt32L(iPriority);
1.266 +
1.267 + TSoundCategory cat = SoundCategory();
1.268 + aStream.WriteInt32L((TInt32)cat);
1.269 +
1.270 + switch (cat)
1.271 + {
1.272 + case TBaSystemSoundInfo::EFile:
1.273 + {
1.274 + // Do it this way so that in InternalizeL we can check
1.275 + // for data corruption.
1.276 + TUint16 pathLength = iName.Length();
1.277 + aStream.WriteUint16L(pathLength);
1.278 + aStream.WriteL(iName.Ptr(), pathLength);
1.279 + }
1.280 + break;
1.281 + case TBaSystemSoundInfo::ESequence:
1.282 + aStream.WriteInt32L( iFixedSequence );
1.283 + break;
1.284 + case TBaSystemSoundInfo::ETone:
1.285 + aStream << iTone;
1.286 + break;
1.287 + default:
1.288 + // object not initialized
1.289 + User::Leave(KErrCorrupt);
1.290 + }
1.291 + }
1.292 +
1.293 +//
1.294 +// class BaSystemSound
1.295 +//
1.296 +
1.297 +EXPORT_C TInt BaSystemSound::GetSound(RFs& /* aFsSession */,const TBaSystemSoundType& aType,TBaSystemSoundInfo& aInfo)
1.298 +/** Gets sound information from storage.
1.299 +
1.300 +@param aFsSession unused parameter kept for compatibility reason.
1.301 +@param aType unique identifier of the sound. aType encapsulates a major
1.302 +and optionally a minor UID. The major UID specifes the sound category
1.303 +while the minor UID specifies an instance of the category.
1.304 +@param aInfo On return, the sound.
1.305 +@return KErrNone if successful, or one of the system wide errors if
1.306 +unsuccessful. */
1.307 + { // static
1.308 + CBaSsndStore* soundStore(NULL);
1.309 + TRAPD(err, soundStore = CBaSsndStore::NewL() );
1.310 +
1.311 + if (err == KErrNone)
1.312 + {
1.313 + err = soundStore->GetSound(aType, aInfo);
1.314 +
1.315 + if (err == KErrNotFound && aType.iMinor != KNullUid)
1.316 + {
1.317 + TBaSystemSoundType tmpType(aType.iMajor);
1.318 + err = soundStore->GetSound(tmpType, aInfo);
1.319 + }
1.320 +
1.321 + delete soundStore; // finish with the pointer
1.322 + } // CBaSsndStore::NewL is successful
1.323 +
1.324 + // err can be from CBaSsndStore::NewL or CBaSsndStore::GetSound
1.325 + if (err != KErrNone)
1.326 + {
1.327 + aInfo.SetFileName( DefaultSound(aType.iMajor) );
1.328 + aInfo.iVolume=KSystemSoundDefaultVolume;
1.329 + aInfo.iPriority=KSystemSoundDefaultPriority;
1.330 + }
1.331 +
1.332 + return err;
1.333 + }
1.334 +
1.335 +
1.336 +EXPORT_C void BaSystemSound::SetSoundL(RFs& /* aFsSession */,const TBaSystemSoundInfo& aInfo)
1.337 +/** Adds the specified sound to the system sound table if it does not
1.338 +already exist in the table. If the sound already exists then overwrite
1.339 +the entry in the sound table.
1.340 +
1.341 +@param aFsSession unused parameter kept for backward compatibility.
1.342 +@param aInfo The sound to add to the system sound table.
1.343 +@capability WriteDeviceData Note only clients with WriteDeviceData capability can sucessfully
1.344 +call this API.
1.345 +@leave KErrPermissionDenied caller does not have WriteDeviceData capability.
1.346 +@leave KErrArgument if the sound has not been initialized.
1.347 +Other system-wide error codes may also be returned.
1.348 +*/
1.349 + { // static
1.350 + TBaSystemSoundInfo::TSoundCategory cat = aInfo.SoundCategory();
1.351 + if (cat == TBaSystemSoundInfo::ENull)
1.352 + {
1.353 + User::Leave(KErrArgument);
1.354 + }
1.355 +
1.356 + //check that the name includes a path
1.357 +#ifdef _DEBUG
1.358 + if (cat == TBaSystemSoundInfo::EFile)
1.359 + {
1.360 + TFileName fullpath = BaflUtils::DriveAndPathFromFullName(
1.361 + aInfo.FileName() );
1.362 + if (fullpath.Length()==0)
1.363 + {
1.364 + Panic(EBafPanicSystemSoundNoPath);
1.365 + }
1.366 + }
1.367 +#endif
1.368 + CBaSsndStore* ssndStore = CBaSsndStore::NewL();
1.369 + CleanupStack::PushL(ssndStore);
1.370 + ssndStore->SetSoundL(aInfo);
1.371 + CleanupStack::PopAndDestroy(ssndStore);
1.372 + }
1.373 +
1.374 +/**
1.375 +Returns the system sound filename.
1.376 +
1.377 +This function is now deprecated. System sounds are now stored in Central Repository.
1.378 +The function still returns the file name, but the file is no longer read from nor written to.
1.379 +There is no guarantee that the file exists.
1.380 +
1.381 +Client code which uses the filename for backup and restore
1.382 +purposes should be removed. Central Repository handles backup and
1.383 +restore of system sound settings.
1.384 +
1.385 +Client code that uses the filename for change notification
1.386 +must use KSystemSoundRepositoryUID to connect to Central Repository and
1.387 +must register for group notification on system sound repository
1.388 +changes. For example, if you used code such as:
1.389 +@code
1.390 +iFs.Connect() ;
1.391 +TFileName soundFileName = BaSystemSound ::SystemSoundFile();
1.392 +iFs.NotifyChange(ENotifyAll, iRequestStatus, soundFileName);
1.393 +@endcode
1.394 +you would now use:
1.395 +@code
1.396 +const Tuint32 KDoNotCareValue = 0 ;
1.397 +const Tuint32 KAllMask = 0 ;
1.398 +iRepository = CRepository ::NewL(KBaSsndRepositoryUid);
1.399 +iRepository.NotifyRequest(KDoNotCareValue, KAllMask, iRequestStatus);
1.400 +@endcode
1.401 +
1.402 +@see CRepository::NotifyRequest()
1.403 +@deprecated
1.404 +*/
1.405 +EXPORT_C TFileName BaSystemSound::SystemSoundFile()
1.406 + { // static
1.407 + TSystemSoundFileName filename(KSystemSoundFilePath);
1.408 + filename[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
1.409 + return filename;
1.410 + }
1.411 +
1.412 +TBaSystemSoundName BaSystemSound::DefaultSound(TBaSystemSoundUid aSSUid)
1.413 + { // static
1.414 + TBaSystemSoundName name;
1.415 + if (aSSUid==KSystemSoundRingUID )
1.416 + name=KSystemSoundDefaultRing;
1.417 + else if (aSSUid==KSystemSoundAlarmUID )
1.418 + name=KSystemSoundDefaultAlarm;
1.419 + else if (aSSUid==KSystemSoundMessageUID )
1.420 + name=KSystemSoundDefaultMessage;
1.421 + else
1.422 + name=KSystemSoundDefaultSound;
1.423 + return name;
1.424 + }
1.425 +
1.426 +//
1.427 +// class CBaSystemSoundArray
1.428 +//
1.429 +
1.430 +/**
1.431 + @internalAll*/
1.432 +CBaSystemSoundArray::CBaSystemSoundArray()
1.433 + : iSystemSounds(KSystemSoundArrayGranularity)
1.434 +
1.435 + {}
1.436 +
1.437 +/**
1.438 + @internalAll*/
1.439 +CBaSystemSoundArray::~CBaSystemSoundArray()
1.440 + {
1.441 + iSystemSounds.Reset();
1.442 + }
1.443 +
1.444 +EXPORT_C CBaSystemSoundArray* CBaSystemSoundArray::NewL()
1.445 + {
1.446 + CBaSystemSoundArray* self=new(ELeave) CBaSystemSoundArray;
1.447 + return self;
1.448 + }
1.449 +EXPORT_C CBaSystemSoundArray* CBaSystemSoundArray::NewLC()
1.450 + {
1.451 + CBaSystemSoundArray* self=CBaSystemSoundArray::NewL();
1.452 + CleanupStack::PushL(self);
1.453 + return self;
1.454 + }
1.455 +
1.456 +/** Retrieves all instances of a sound category.
1.457 +@param aFsSession unused parameter kept for backward compatibility
1.458 +@param aSSuid specifies the sound category to retrieve.
1.459 +*/
1.460 +EXPORT_C void CBaSystemSoundArray::RestoreL(RFs& /* aFsSession */,TBaSystemSoundUid aSSUid)
1.461 + {
1.462 + iUid=aSSUid;
1.463 + iSystemSounds.Reset();
1.464 +
1.465 + CBaSsndStore* ssndStore = CBaSsndStore::NewL();
1.466 + CleanupStack::PushL(ssndStore);
1.467 + User::LeaveIfError( ssndStore->GetSoundCategory(aSSUid, iSystemSounds) );
1.468 + CleanupStack::PopAndDestroy(ssndStore);
1.469 + }
1.470 +
1.471 +EXPORT_C TBaSystemSoundInfo CBaSystemSoundArray::At(TInt aIndex)
1.472 + {
1.473 + return iSystemSounds[aIndex];
1.474 + }
1.475 +
1.476 +EXPORT_C TInt CBaSystemSoundArray::Count()
1.477 + {
1.478 + return iSystemSounds.Count();
1.479 + }
1.480 +
1.481 +//
1.482 +// class TBaSoundPriorityBase
1.483 +//
1.484 +
1.485 +const TInt KPrefEpocMask =0x0000FF00;
1.486 +const TInt KPrefDeviceMask =0xFFFF0000;
1.487 +
1.488 +EXPORT_C TMdaPriorityPreference TBaSoundPriorityBase::PriorityPreference() const
1.489 + {
1.490 + TInt pref=0;
1.491 + pref=(iPriority&KPrefEpocMask)>>8;
1.492 + pref|=(iPriority&KPrefDeviceMask);
1.493 + return static_cast<TMdaPriorityPreference>(pref);
1.494 + }
1.495 +
1.496 +/**
1.497 + @internalAll*/
1.498 +void TBaSoundPriorityBase::Set(TInt aPriority,TMdaPriorityPreference aPriorityPreference)
1.499 +
1.500 +{
1.501 + __ASSERT_ALWAYS(aPriority>=EMdaPriorityMin && aPriority<=EMdaPriorityMax,Panic(EBafPanicInvalidSoundPriority));
1.502 + iPriority=0;
1.503 + *(TInt8*)&iPriority=(TInt8)aPriority;
1.504 + iPriority|=((aPriorityPreference<<8)&KPrefEpocMask);
1.505 + iPriority|=(aPriorityPreference&KPrefDeviceMask);
1.506 + }
1.507 +
1.508 +//
1.509 +// class TBaSoundPriorityEncoder
1.510 +//
1.511 +
1.512 +EXPORT_C TBaSoundPriorityEncoder::TBaSoundPriorityEncoder(TInt aPriority,TMdaPriorityPreference aPriorityPreference)
1.513 + {
1.514 + Set(aPriority,aPriorityPreference);
1.515 + }