uifw/EikStd/srvuisrc/eikkeysoundserver.cpp
branchRCL_3
changeset 72 a5e7a4f63858
parent 64 85902f042028
equal deleted inserted replaced
64:85902f042028 72:a5e7a4f63858
    86 // CEikKeySoundServer implementation.
    86 // CEikKeySoundServer implementation.
    87 // ==================================
    87 // ==================================
    88 
    88 
    89 TInt CEikKeySoundServer::LaunchServer(TThreadId& aThreadId)
    89 TInt CEikKeySoundServer::LaunchServer(TThreadId& aThreadId)
    90     {
    90     {
    91     LOGTEXT(_L("CEikKeySoundServer::LaunchServer"));
       
    92     // First, check that ther server isn't already running.
    91     // First, check that ther server isn't already running.
    93     TFindServer findServer(__KEYSOUND_SERVER_NAME);
    92     TFindServer findServer(__KEYSOUND_SERVER_NAME);
    94     TFullName name;
    93     TFullName name;
    95     if (findServer.Next(name) == KErrNone)
    94     if (findServer.Next(name) == KErrNone)
    96         {
    95         {
   191     // construct all system SID objects
   190     // construct all system SID objects
   192     }
   191     }
   193 
   192 
   194 void CEikKeySoundServer::ConstructL()
   193 void CEikKeySoundServer::ConstructL()
   195     {
   194     {
   196     LOGTEXT(_L("CEikKeySoundServer::ConstructL"));
       
   197     iInit = EFalse;
   195     iInit = EFalse;
   198     iSidList = new(ELeave)CArrayFixFlat<TAknSoundID>(KAknSoundInfoMapGranularity);
   196     iSidList = new(ELeave)CArrayFixFlat<TAknSoundID>(KAknSoundInfoMapGranularity);
   199     iSoundList = new(ELeave)CArrayPtrFlat<CEikSoundInfo>(KAknSoundInfoMapGranularity);
   197     iSoundList = new(ELeave)CArrayPtrFlat<CEikSoundInfo>(KAknSoundInfoMapGranularity);
   200 
   198 
   201     // Default to loudest volume
   199     // Default to loudest volume
   242 #endif
   240 #endif
   243     }
   241     }
   244 
   242 
   245 CEikKeySoundServer::~CEikKeySoundServer()
   243 CEikKeySoundServer::~CEikKeySoundServer()
   246     {
   244     {
   247     LOGTEXT(_L("CEikKeySoundServer::~CEikKeySoundServer"));
       
   248     if (iProfilesNotifyHandler)
   245     if (iProfilesNotifyHandler)
   249         {
   246         {
   250         iProfilesNotifyHandler->StopListening();
   247         iProfilesNotifyHandler->StopListening();
   251         delete iProfilesNotifyHandler;
   248         delete iProfilesNotifyHandler;
   252         }
   249         }
   265     }
   262     }
   266 
   263 
   267 CSession2* CEikKeySoundServer::NewSessionL(const TVersion& aVersion,
   264 CSession2* CEikKeySoundServer::NewSessionL(const TVersion& aVersion,
   268     const RMessage2& /*aMessage*/) const
   265     const RMessage2& /*aMessage*/) const
   269     {
   266     {
   270     LOGTEXT(_L("CEikKeySoundServer::NewSessionL"));
       
   271     TVersion ver(KKeySoundServMajorVN, KKeySoundServMinorVN, KKeySoundServBuildVN);
   267     TVersion ver(KKeySoundServMajorVN, KKeySoundServMinorVN, KKeySoundServBuildVN);
   272     if (!User::QueryVersionSupported(ver, aVersion))
   268     if (!User::QueryVersionSupported(ver, aVersion))
   273         {
   269         {
   274         User::Leave(KErrNotSupported);
   270         User::Leave(KErrNotSupported);
   275         }
   271         }
   292 		}
   288 		}
   293 	}
   289 	}
   294 
   290 
   295 void CEikKeySoundServer::PlaySid(TInt aSid, TBool aPlaySelf)
   291 void CEikKeySoundServer::PlaySid(TInt aSid, TBool aPlaySelf)
   296     {
   292     {
   297     LOGTEXT1(_L("CEikKeySoundServer::PlaySid aSid: %d"), aSid);
       
   298     if (aSid == EAvkonSIDWarningTone && iWarningToneEnabled == 0)
   293     if (aSid == EAvkonSIDWarningTone && iWarningToneEnabled == 0)
   299         {
   294         {
   300         // Don't play warning tone, when the warning tone is disabled in setting.
   295         // Don't play warning tone, when the warning tone is disabled in setting.
   301         return;
   296         return;
   302         }
   297         }
   387         }
   382         }
   388     }
   383     }
   389 
   384 
   390 void CEikKeySoundServer::SetDisabledScanCode( TInt aScanCode )
   385 void CEikKeySoundServer::SetDisabledScanCode( TInt aScanCode )
   391 	{
   386 	{
   392     LOGTEXT1(_L("CEikKeySoundServer::SetDisabledScanCode aScanCode: %d"),
       
   393             aScanCode);
       
   394 	iDisabledScanCode = aScanCode;
   387 	iDisabledScanCode = aScanCode;
   395 	}
   388 	}
   396 
   389 
   397 TInt CEikKeySoundServer::DisabledScanCode()
   390 TInt CEikKeySoundServer::DisabledScanCode()
   398 	{
   391 	{
   432     {
   425     {
   433     }
   426     }
   434 
   427 
   435 CEikKeySoundSession::~CEikKeySoundSession()
   428 CEikKeySoundSession::~CEikKeySoundSession()
   436     {
   429     {
   437     LOGTEXT1(_L("CEikKeySoundSession::~CEikKeySoundSession iClientUid %d"),
       
   438             iClientUid);
       
   439     RemoveSids(iClientUid);
   430     RemoveSids(iClientUid);
   440     if (iHasLockedContext)
   431     if (iHasLockedContext)
   441         {
   432         {
   442         if( iServer )
   433         if( iServer )
   443             {
   434             {
   444             iServer->SetContextLocked(EFalse);
   435             iServer->SetContextLocked(EFalse);
   445             }
   436             }
   446         }
   437         }
   447     if (iOwnsDefaultSounds)
   438     if (iOwnsDefaultSounds)
   448         {
   439         {
   449         LOGTEXT(_L("CEikKeySoundSession::~CEikKeySoundSession OwnsDefaultSounds"));
       
   450         RemoveSids(0);
   440         RemoveSids(0);
   451         iServer->iInit = EFalse;
   441         iServer->iInit = EFalse;
   452         }
   442         }
   453     if (iSoundStack)
   443     if (iSoundStack)
   454         {
   444         {
   478     }
   468     }
   479 
   469 
   480 
   470 
   481 void CEikKeySoundSession::ServiceL(const RMessage2& aMessage)
   471 void CEikKeySoundSession::ServiceL(const RMessage2& aMessage)
   482     {
   472     {
   483     LOGTEXT1(_L("CEikKeySoundSession::ServiceL aMessage: %d"),
       
   484             aMessage.Function());
       
   485     if (aMessage.Function() == EKeySoundServerPlayKey)
   473     if (aMessage.Function() == EKeySoundServerPlayKey)
   486         {
   474         {
   487         TInt scancode = aMessage.Int0() & 0xff;
   475         TInt scancode = aMessage.Int0() & 0xff;
   488         TBool repeat = aMessage.Int1();
   476         TBool repeat = aMessage.Int1();
   489         aMessage.Complete(KErrNone);
   477         aMessage.Complete(KErrNone);
   593 
   581 
   594 void CEikKeySoundSession::AddSoundIdBufferL(const RMessage2& aMessage)
   582 void CEikKeySoundSession::AddSoundIdBufferL(const RMessage2& aMessage)
   595     {
   583     {
   596     TInt uid = aMessage.Int0();
   584     TInt uid = aMessage.Int0();
   597     TInt size = aMessage.Int1();
   585     TInt size = aMessage.Int1();
   598     LOGTEXT1(_L("CEikKeySoundSession::AddSoundIdBufferL uid: %d"), uid);
   586 
   599     // CBufFlat requires that size must be positive and not larger than KMaxTInt / 2.
   587     // CBufFlat requires that size must be positive and not larger than KMaxTInt / 2.
   600     // Without this check the KeySoundServer could panic.
   588     // Without this check the KeySoundServer could panic.
   601     if (size <= 0 || size >= ((KMaxTInt / 2) - KKeySoundServerBufExpandSize))
   589     if (size <= 0 || size >= ((KMaxTInt / 2) - KKeySoundServerBufExpandSize))
   602         {
   590         {
   603         User::Leave(KErrArgument);
   591         User::Leave(KErrArgument);
   710     iServer->SetVolumeForPreferenceType(KKeyClickPreference, iServer->iKeypadVolume);
   698     iServer->SetVolumeForPreferenceType(KKeyClickPreference, iServer->iKeypadVolume);
   711     }
   699     }
   712 
   700 
   713 void CEikKeySoundSession::RemoveSids(TInt aUid)
   701 void CEikKeySoundSession::RemoveSids(TInt aUid)
   714     {
   702     {
   715     LOGTEXT1(_L("CEikKeySoundSession::RemoveSids aUid %d"), aUid);
       
   716     TUint uid = aUid << 16;
   703     TUint uid = aUid << 16;
   717     if (!iServer->iSidList)
   704     if (!iServer->iSidList)
   718         {
   705         {
   719         return;
   706         return;
   720         }
   707         }
   741             // If no duplicate found, sid is deleted. Else duplicate will be
   728             // If no duplicate found, sid is deleted. Else duplicate will be
   742             // deleted when the for-loop reaches it (unless there is even more duplicates).
   729             // deleted when the for-loop reaches it (unless there is even more duplicates).
   743             if (!duplicateFound)
   730             if (!duplicateFound)
   744                 {
   731                 {
   745                 // Remove sound at this position
   732                 // Remove sound at this position
   746                 if(id.iSoundInfo->IsWaittingPlay())
   733                 delete id.iSoundInfo;
   747                     {
       
   748                     LOGTEXT1(_L("CEikKeySoundSession::RemoveSids DestroyAfterplay : %d"),
       
   749                             (TInt)id.iSoundInfo );
       
   750                     id.iSoundInfo->SetDestroyAfterPlay(ETrue);
       
   751                     }
       
   752                 else
       
   753                     {
       
   754                     LOGTEXT1(_L("CEikKeySoundSession::RemoveSids Destroy : %d"),
       
   755                             (TInt)id.iSoundInfo );
       
   756                     delete id.iSoundInfo;
       
   757                     }
       
   758                 if (iServer->iSoundList)
   734                 if (iServer->iSoundList)
   759                     {
   735                     {
   760                     iServer->iSoundList->Delete(ii);
   736                     iServer->iSoundList->Delete(ii);
   761                     }
   737                     }
   762                 iServer->iSidList->Delete(ii);
   738                 iServer->iSidList->Delete(ii);
   822         }
   798         }
   823     }
   799     }
   824 
   800 
   825 void CEikKeySoundSession::AddToneSidL(const TAknSoundID& aSoundID, CAknToneSoundInfo* aSoundInfo)
   801 void CEikKeySoundSession::AddToneSidL(const TAknSoundID& aSoundID, CAknToneSoundInfo* aSoundInfo)
   826     {
   802     {
   827     LOGTEXT(_L("CEikKeySoundSession::AddToneSidL"));
       
   828     aSoundInfo->InitL();
   803     aSoundInfo->InitL();
   829 
   804 
   830     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   805     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   831     if (iServer->iSidList && iServer->iSoundList)
   806     if (iServer->iSidList && iServer->iSoundList)
   832         {
   807         {
   841     }
   816     }
   842 
   817 
   843 void CEikKeySoundSession::AddSequenceSidL(const TAknSoundID& aSoundID,
   818 void CEikKeySoundSession::AddSequenceSidL(const TAknSoundID& aSoundID,
   844     CAknSequenceSoundInfo* aSoundInfo)
   819     CAknSequenceSoundInfo* aSoundInfo)
   845     {
   820     {
   846     LOGTEXT(_L("CEikKeySoundSession::AddSequenceSidL"));
       
   847     aSoundInfo->InitL();
   821     aSoundInfo->InitL();
   848 
   822 
   849     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   823     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   850 
   824 
   851     if (iServer->iSidList && iServer->iSoundList)
   825     if (iServer->iSidList && iServer->iSoundList)
   861     }
   835     }
   862 
   836 
   863 void CEikKeySoundSession::AddFileSidL(const TAknSoundID& aSoundID, CAknFileSoundInfo* aSoundInfo,
   837 void CEikKeySoundSession::AddFileSidL(const TAknSoundID& aSoundID, CAknFileSoundInfo* aSoundInfo,
   864     const TDesC& aFileName)
   838     const TDesC& aFileName)
   865     {
   839     {
   866     LOGTEXT(_L("CEikKeySoundSession::AddFileSidL"));
       
   867     aSoundInfo->InitL(aFileName, NULL);
   840     aSoundInfo->InitL(aFileName, NULL);
   868 
   841 
   869     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   842     TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint);
   870     if (iServer->iSidList && iServer->iSoundList)
   843     if (iServer->iSidList && iServer->iSoundList)
   871         {
   844         {
   885 
   858 
   886 CEikSoundInfo::CEikSoundInfo(TInt aPriority, TInt aPreference)
   859 CEikSoundInfo::CEikSoundInfo(TInt aPriority, TInt aPreference)
   887     {
   860     {
   888     iPriority = aPriority;
   861     iPriority = aPriority;
   889     iPreference = aPreference;
   862     iPreference = aPreference;
   890     iWaittingPlay = EFalse;
       
   891     iDestroyAfterPlay = EFalse;
       
   892     iVolume = ESoundVolume9; // default to loudest
   863     iVolume = ESoundVolume9; // default to loudest
   893     }
   864     }
   894 
   865 
   895 CEikSoundInfo::~CEikSoundInfo()
   866 CEikSoundInfo::~CEikSoundInfo()
   896     {
   867     {
   904     }
   875     }
   905 
   876 
   906 CEikSoundInfo::TVolumeSetting CEikSoundInfo::Volume()
   877 CEikSoundInfo::TVolumeSetting CEikSoundInfo::Volume()
   907     {
   878     {
   908     return iVolume;
   879     return iVolume;
   909     }
       
   910 
       
   911 TBool CEikSoundInfo::IsWaittingPlay()
       
   912     {
       
   913     LOGTEXT1(_L("CEikSoundInfo::IsWaittingPlay : %d"), iWaittingPlay);
       
   914     return iWaittingPlay;
       
   915     }
       
   916 
       
   917 void CEikSoundInfo::SetDestroyAfterPlay(TBool aDestroyAfterPlay)
       
   918     {
       
   919     iDestroyAfterPlay = aDestroyAfterPlay;
       
   920     }
   880     }
   921 
   881 
   922 // ==================================
   882 // ==================================
   923 // CAknSynthSoundInfo implementation.
   883 // CAknSynthSoundInfo implementation.
   924 // ==================================
   884 // ==================================
  1168 CAknFileSoundInfo::~CAknFileSoundInfo()
  1128 CAknFileSoundInfo::~CAknFileSoundInfo()
  1169     {
  1129     {
  1170     delete iAudioPlayer;
  1130     delete iAudioPlayer;
  1171     }
  1131     }
  1172 
  1132 
  1173 void CAknFileSoundInfo::InitL(const TDesC& aFileName, CMdaServer* /*aMdaServer*/)
  1133 void CAknFileSoundInfo::InitL(const TDesC& aFileName, CMdaServer* aMdaServer)
  1174     {
  1134     {
  1175     LOGTEXT(_L("CAknFileSoundInfo::InitL() - Filename:"));
  1135     LOGTEXT(_L("CAknFileSoundInfo::InitL() - Filename:"));
  1176     LOGTEXT(aFileName);
  1136     LOGTEXT(aFileName);
  1177     iFileName = aFileName;
  1137     iFileName = aFileName;
  1178     LOGTEXT(_L(" CAknFileSoundInfo::InitL() - Exit"));
  1138     LOGTEXT(_L(" CAknFileSoundInfo::InitL() - Exit"));
  1186     // Stops playing and deletes audio player instance if it exist.
  1146     // Stops playing and deletes audio player instance if it exist.
  1187     Stop();
  1147     Stop();
  1188 
  1148 
  1189     // Create audio player. DoPlay() will be called in all circumstances.
  1149     // Create audio player. DoPlay() will be called in all circumstances.
  1190     iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(iFileName, *this, iPriority,(TMdaPriorityPreference)iPreference );
  1150     iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(iFileName, *this, iPriority,(TMdaPriorityPreference)iPreference );
  1191     iWaittingPlay =ETrue;
       
  1192     LOGTEXT(_L(" CAknFileSoundInfo::PlayL() - Exit"));
  1151     LOGTEXT(_L(" CAknFileSoundInfo::PlayL() - Exit"));
  1193     }
  1152     }
  1194 
  1153 
  1195 
  1154 
  1196 void CAknFileSoundInfo::DoPlay()
  1155 void CAknFileSoundInfo::DoPlay()
  1216         LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Prepare failed, delete!"));
  1175         LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Prepare failed, delete!"));
  1217         LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Deleting iAudioPlayer."));
  1176         LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Deleting iAudioPlayer."));
  1218 
  1177 
  1219         delete iAudioPlayer;
  1178         delete iAudioPlayer;
  1220         iAudioPlayer = NULL;
  1179         iAudioPlayer = NULL;
  1221         iWaittingPlay = EFalse;
       
  1222         }
  1180         }
  1223     }
  1181     }
  1224 
  1182 
  1225 
  1183 
  1226 void CAknFileSoundInfo::Stop()
  1184 void CAknFileSoundInfo::Stop()
  1243         LOGTEXT(_L(" CAknFileSoundInfo::Stop(). Deleting iAudioPlayer."));
  1201         LOGTEXT(_L(" CAknFileSoundInfo::Stop(). Deleting iAudioPlayer."));
  1244 
  1202 
  1245         delete iAudioPlayer;
  1203         delete iAudioPlayer;
  1246         iAudioPlayer = NULL;
  1204         iAudioPlayer = NULL;
  1247         iPrepared = EFalse;
  1205         iPrepared = EFalse;
  1248         iWaittingPlay = EFalse;
       
  1249         }
  1206         }
  1250     }
  1207     }
  1251 
  1208 
  1252 void CAknFileSoundInfo::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/,
  1209 void CAknFileSoundInfo::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/,
  1253     TInt /*aCurrentState*/, TInt /*aErrorCode*/)
  1210     TInt /*aCurrentState*/, TInt /*aErrorCode*/)
  1310     }
  1267     }
  1311 
  1268 
  1312 void CAknFileSoundInfo::MapcPlayComplete(TInt /*aError*/)
  1269 void CAknFileSoundInfo::MapcPlayComplete(TInt /*aError*/)
  1313     {
  1270     {
  1314     LOGTEXT(_L("CAknFileSoundInfo::MapcPlayComplete()"));
  1271     LOGTEXT(_L("CAknFileSoundInfo::MapcPlayComplete()"));
  1315     LOGTEXT1(_L(" aError:%d"), aError);
  1272 
  1316     iPlaying = EFalse;
  1273     iPlaying = EFalse;
  1317     iWaittingPlay = EFalse;
       
  1318 
  1274 
  1319     delete iAudioPlayer;
  1275     delete iAudioPlayer;
  1320     iAudioPlayer = NULL;
  1276     iAudioPlayer = NULL;
  1321     iPrepared = EFalse;
  1277     iPrepared = EFalse;
  1322     if(iDestroyAfterPlay)
       
  1323         {
       
  1324         LOGTEXT1(_L("CAknFileSoundInfo::MapcPlayComplete DestroyAfterPlay : %d"),
       
  1325                 TInt(this));
       
  1326         delete this;
       
  1327         }
       
  1328     }
  1278     }
  1329 
  1279 
  1330 // End of file
  1280 // End of file