License and Privilege changes
[apps/osp/Call.git] / src / CallSoundManager.cpp
index 3e52598..d9b939e 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -41,6 +41,10 @@ SoundManager::SoundManager(void)
        , __pVibrator(null)
        , __pPlayer(null)
        , __lastEndedConferenceCall(false)
+       , __pConnectPlayer(null)
+       , __pDisconnectPlayer(null)
+       , __pReminderPlayer(null)
+       , __pWaitingTonePlayer(null)
 {
        __timer.Construct(*this);
        __isSoundStatusOn = false;
@@ -56,10 +60,32 @@ SoundManager::~SoundManager(void)
        if (__pVibrator != null)
        {
                delete __pVibrator;
+               __pVibrator = null;
        }
        if (__pPlayer != null)
        {
                delete __pPlayer;
+               __pPlayer = null;
+       }
+       if(__pConnectPlayer != null)
+       {
+               delete __pConnectPlayer;
+               __pConnectPlayer = null;
+       }
+       if(__pDisconnectPlayer != null)
+       {
+               delete __pDisconnectPlayer;
+               __pDisconnectPlayer = null;
+       }
+       if(__pReminderPlayer != null)
+       {
+               delete __pReminderPlayer;
+               __pReminderPlayer = null;
+       }
+       if(__pWaitingTonePlayer != null)
+       {
+               delete __pWaitingTonePlayer;
+               __pWaitingTonePlayer = null;
        }
 
 }
@@ -198,27 +224,64 @@ SoundManager::OnTimerExpired(Timer& timer)
 {
        String reminderTonePath;
        int unknownRejectStatus = -1;
-               vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
-               bool ReminderToneSetStatus = unknownRejectStatus;
+       vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
+       bool ReminderToneSetStatus = unknownRejectStatus;
+       result res = E_FAILURE;
+       reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
 
        if(ReminderToneSetStatus == true)
        {
 
-               if(__pPlayer == null)
+               if(__pReminderPlayer == null)
                {
-                       __pPlayer =  new (std::nothrow) Player();
-                       __pPlayer->Construct(*this);
+
+                       if(reminderTonePath.IsEmpty() == false)
+                       {
+                               __pReminderPlayer =  new (std::nothrow) Player();
+                               res = __pReminderPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer Construct failed with %d",res);
+                                       delete __pReminderPlayer;
+                                       __pReminderPlayer = null;
+                                       return;
+                               }
+                               res = __pReminderPlayer->OpenFile(reminderTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer OpenFile failed with %d",res);
+                                       delete __pReminderPlayer;
+                                       __pReminderPlayer = null;
+                                       return;
+                               }
+                               res = __pReminderPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer SetLooping failed with %d",res);
+                                       delete __pReminderPlayer;
+                                       __pReminderPlayer = null;
+                                       return;
+                               }
+                               res = __pReminderPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer SetVolume failed with %d",res);
+                                       delete __pReminderPlayer;
+                                       __pReminderPlayer = null;
+                                       return;
+                               }
+                       }
                }
 
-               reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
-               if(reminderTonePath.IsEmpty() == false)
+               if(__pReminderPlayer != null)
                {
-                       __pPlayer->Close();
-                       __pPlayer->OpenFile(reminderTonePath,false);
-                       __pPlayer->SetLooping(false);
-                       __pPlayer->SetVolume(80);
                        SetSoundMode(SOUND_MODE_MEDIA);
-                       __pPlayer->Play();
+                       res = __pReminderPlayer->Play();
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pReminderPlayer Play failed with %d",res);
+                               return;
+                       }
                        SetSoundMode(SOUND_MODE_VOICE);
                }
        }
@@ -240,135 +303,271 @@ SoundManager::SetDisconnectTone(void)
        String disconnectTonePath=L"";
        vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
        bool disconnectToneSetStatus = unknownRejectStatus;
+       result res = E_FAILURE;
 
        if(disconnectToneSetStatus == true)
        {
                AppLogDebug("disconnectToneSetStatus == true");
                disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
-               if(__pPlayer == null)
+               if(disconnectTonePath.IsEmpty() == false)
                {
-                       AppLogDebug("__pPlayer == null");
+                       if(__pDisconnectPlayer == null)
+                       {
+                               AppLogDebug("__pConnectPlayer == null");
+                               __pDisconnectPlayer =  new (std::nothrow) Player();
+                               res = __pDisconnectPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer Construct failed with %d",res);
+                                       delete __pDisconnectPlayer;
+                                       __pDisconnectPlayer = null;
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->OpenFile(disconnectTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer OpenFile failed with %d",res);
+                                       delete __pDisconnectPlayer;
+                                       __pDisconnectPlayer = null;
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer SetLooping failed with %d",res);
+                                       delete __pDisconnectPlayer;
+                                       __pDisconnectPlayer = null;
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer SetLooping SetVolume with %d",res);
+                                       delete __pDisconnectPlayer;
+                                       __pDisconnectPlayer = null;
+                                       return;
+                               }
 
-                       __pPlayer =  new (std::nothrow) Player();
-                       __pPlayer->Construct(*this);
-                       AppLogDebug("__pPlayer Construct");
+                       }
                }
-               if(disconnectTonePath.IsEmpty() == false)
+
+               if(__pDisconnectPlayer != null)
                {
-                       AppLogDebug("__pPlayer OpenFile %ls",disconnectTonePath.GetPointer());
-                       __pPlayer->OpenFile(disconnectTonePath,false);
-                       AppLogDebug("__pPlayer OpenFile");
-                       __pPlayer->SetLooping(false);
-                       AppLogDebug("__pPlayer SetLooping");
-                       __pPlayer->SetVolume(80);
-                       AppLogDebug("__pPlayer SetVolume");
+                       AppLogDebug("__pDisconnectPlayer OpenFile %ls",disconnectTonePath.GetPointer());
                        SetSoundMode(SOUND_MODE_MEDIA);
-                       AppLogDebug("__pPlayer SetVolume");
-                       __pPlayer->Play();
+                       AppLogDebug("__pDisconnectPlayer SetVolume");
+                       if(__pDisconnectPlayer->GetState() == PLAYER_STATE_PLAYING)
+                       {
+                               __pDisconnectPlayer->Stop();
+                       }
+                       res = __pDisconnectPlayer->Play();
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pDisconnectPlayer Play with %d",res);
+                               return;
+                       }
                }
+
        }
+
+
+
+
        AppLogDebug("Exit");
 
 }
 
 void
-SoundManager::SetMinuteReminderTone()
+SoundManager::SetMinuteReminderTone(void)
 {
-
-       int unknownRejectStatus = -1;
-       vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
-       bool reminderToneSetStatus = unknownRejectStatus;
-
-       if(reminderToneSetStatus == true)
-       {
-               __timer.StartAsRepeatable(60000);
-       }
-
+       __timer.StartAsRepeatable(60000);
 }
 
 
 void
-SoundManager::SetConnectTone()
+SoundManager::SetConnectTone(void)
 {
 
-       result r = E_FAILURE;
        String connectTonePath;
        int unknownRejectStatus = -1;
        vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
        bool connectToneSetStatus = unknownRejectStatus;
+       result res = E_FAILURE;
 
        connectTonePath.Append(CALLCONNECTTONE_PATH);
 
        if(connectToneSetStatus == true)
        {
 
-               if(__pPlayer == null)
+               if(__pConnectPlayer == null)
                {
-                       __pPlayer =  new (std::nothrow) Player();
-                       r = __pPlayer->Construct(*this);
+                       if (connectTonePath.IsEmpty() == false)
+                       {
+                               __pConnectPlayer =  new (std::nothrow) Player();
+                               res = __pConnectPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer Construct failed with %d",res);
+                                       delete __pConnectPlayer;
+                                       __pConnectPlayer = null;
+                                       return;
+                               }
+                               res = __pConnectPlayer->OpenFile(connectTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer OpenFile failed with %d",res);
+                                       delete __pConnectPlayer;
+                                       __pConnectPlayer = null;
+                                       return;
+                               }
+                               res = __pConnectPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer SetLooping failed with %d",res);
+                                       delete __pConnectPlayer;
+                                       __pConnectPlayer = null;
+                                       return;
+                               }
+                               res = __pConnectPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer SetVolume failed with %d",res);
+                                       delete __pConnectPlayer;
+                                       __pConnectPlayer = null;
+                                       return;
+                               }
+                       }
                }
-               if (connectTonePath.IsEmpty() == false)
-               {
 
-                       r = __pPlayer->OpenFile(connectTonePath,false);
-                       r = __pPlayer->SetLooping(false);
-                       r = __pPlayer->SetVolume(80);
-                       r = SetSoundMode(SOUND_MODE_MEDIA);
-                       r = __pPlayer->Play();
+               if(__pConnectPlayer != null)
+               {
+                       res = SetSoundMode(SOUND_MODE_MEDIA);
+                       AppLogDebug("__pConnectPlayer Playing connect tone");
+                       res = __pConnectPlayer->Play();
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pConnectPlayer Play failed with %d",res);
+                               return;
+                       }
                }
+
        }
+
+
 }
 
 void
-SoundManager::StartAlert(String& contactRingTone)
+SoundManager::SetWaitTone(void)
 {
-       AppLogDebug("Enter");
-       if(__pSoundCallSession != null)
+       CallAlertStatus status= CALL_ALERT_SOUND;
+       int alertStatus = -1;
+       result res = E_FAILURE;
+       int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
+       if (retVal == 0)
        {
-               CallAlertStatus status= CALL_ALERT_SOUND;
-               int alertStatus = -1;
-               int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
-               if (retVal == 0)
-               {
-                       status = (CallAlertStatus) alertStatus;
-               }
-               AppLogDebug("No Alert already in call");
-               if(status == CALL_ALERT_SOUND)
+               status = (CallAlertStatus) alertStatus;
+       }
+       AppLogDebug("No Alert already in call");
+       if(status == CALL_ALERT_SOUND)
+       {
+               AppLogDebug("Playing alert tone");
+               String waitingTonePath;
+               waitingTonePath.Append(CALLWAITINGTONE_PATH);
+               if(__pWaitingTonePlayer == null)
                {
-                       AppLogDebug("Playing alert tone");
-                       String waitingTonePath;
-                       waitingTonePath.Append(CALLWAITINGTONE_PATH);
-                       if(__pPlayer == null)
+                       if (waitingTonePath.IsEmpty() == false)
                        {
-                               __pPlayer =  new (std::nothrow) Player();
-                               __pPlayer->Construct(*this);
+                               __pWaitingTonePlayer =  new (std::nothrow) Player();
+                               res = __pWaitingTonePlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pWaitingTonePlayer Construct failed with %d",res);
+                                       delete __pWaitingTonePlayer;
+                                       __pWaitingTonePlayer = null;
+                                       return;
+                               }
+                               res = __pWaitingTonePlayer->OpenFile(waitingTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pWaitingTonePlayer OpenFile failed with %d",res);
+                                       delete __pWaitingTonePlayer;
+                                       __pWaitingTonePlayer = null;
+
+                                       return;
+                               }
+                               res = __pWaitingTonePlayer->SetLooping(true);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pWaitingTonePlayer SetLooping failed with %d",res);
+                                       delete __pWaitingTonePlayer;
+                                       __pWaitingTonePlayer = null;
+
+                                       return;
+                               }
+                               res = __pWaitingTonePlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pWaitingTonePlayer SetVolume failed with %d",res);
+                                       delete __pWaitingTonePlayer;
+                                       __pWaitingTonePlayer = null;
+
+                                       return;
+                               }
                        }
-                       if (waitingTonePath.IsEmpty() == false)
+               }
+
+               if( __pWaitingTonePlayer != null )
+               {
+                       SetSoundMode(SOUND_MODE_MEDIA);
+                       res = __pWaitingTonePlayer->Play();
+                       if(res != E_SUCCESS)
                        {
-                               __pPlayer->Close();
-                               __pPlayer->OpenFile(waitingTonePath,false);
-                               __pPlayer->SetLooping(true);
-                               __pPlayer->SetVolume(80);
-                               SetSoundMode(SOUND_MODE_MEDIA);
-                               __pPlayer->Play();
+                               AppLogDebug("__pWaitingTonePlayer Play failed with %d",res);
+                               return;
                        }
                }
+
+       }
+}
+
+void
+SoundManager::StartAlert(String& contactRingTone)
+{
+       result res = E_FAILURE;
+       IntensityDurationVibrationPattern vibration;
+       vibration.duration = 3000;
+       vibration.intensity = -1;
+       AppLogDebug("Enter");
+       if(__pSoundCallSession != null)
+       {
+               SetWaitTone();
                return;
        }
        else
        {
                StartSession();
        }
-       result r = E_FAILURE;
        if(__pVibrator == null)
        {
                __pVibrator = new (std::nothrow) Vibrator();
-               r = __pVibrator->Construct();
+               res = __pVibrator->Construct();
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pVibrator Construct failed with %d",res);
+                       return;
+               }
        }
        if(__pPlayer == null)
        {
                __pPlayer =  new (std::nothrow) Player();
-               r = __pPlayer->Construct(*this);
+               res = __pPlayer->Construct(*this);
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pPlayer Construct failed with %d",res);
+                       delete __pPlayer;
+                       __pPlayer = null;
+                       return;
+               }
        }
        int retVal = -1;
        vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &retVal);
@@ -394,23 +593,43 @@ SoundManager::StartAlert(String& contactRingTone)
 
                //Check if file is present
                File file;
-               result res = file.Construct(ringTonePath, "r");
+               res = file.Construct(ringTonePath, "r");
                if(res != E_SUCCESS )
                {
                        ringTonePath.Clear();
                        ringTonePath.Append(RINGTONE_PATH);
                }
-               __pPlayer->Close();
-               r = __pPlayer->OpenFile(ringTonePath,false);
-               r = __pPlayer->SetLooping(true);
-               r = __pPlayer->SetVolume(80);
-               r = SetSoundMode(SOUND_MODE_RINGTONE);
-               r = __pPlayer->Play();
+
+               res = __pPlayer->OpenFile(ringTonePath,false);
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pPlayer Construct failed with %d",res);
+                       return;
+               }
+               res = __pPlayer->SetLooping(true);
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pPlayer Construct failed with %d",res);
+                       return;
+               }
+               res = __pPlayer->SetVolume(80);
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pPlayer Construct failed with %d",res);
+                       return;
+               }
+               res = SetSoundMode(SOUND_MODE_RINGTONE);
+               res = __pPlayer->Play();
+               if(res != E_SUCCESS)
+               {
+                       AppLogDebug("__pPlayer Construct failed with %d",res);
+                       return;
+               }
        }
        if (__isVibrateStatusOn == true)
        {
                //todo: Get the level from settings
-               r = __pVibrator->Start(3000,1000,1000);
+               __pVibrator->Start(&vibration, 1, 1000);
        }
        AppLogDebug("Exit");
        return;
@@ -419,22 +638,47 @@ SoundManager::StartAlert(String& contactRingTone)
 void
 SoundManager::StopAlert(void)
 {
+       result res = E_FAILURE;
        AppLogDebug("Enter");
        if (__isSoundStatusOn == true)
        {
                //todo: stop player
-               AppLogDebug("Stopping ring tone");
-               __pPlayer->Stop();
-               __pPlayer->Close();
-               SetSoundMode(SOUND_MODE_VOICE);
-               __isSoundStatusOn = false;
-               StopSession();
+               if(__pPlayer != null)
+               {
+                       AppLogDebug("Stopping ring tone");
+                       if(__pPlayer->GetState() == PLAYER_STATE_PLAYING)
+                       {
+                               res = __pPlayer->Stop();
+                       }
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pPlayer Stop failed with %d",res);
+                               return;
+                       }
+                       res = __pPlayer->Close();
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pPlayer Close failed with %d",res);
+                               return;
+                       }
+                       SetSoundMode(SOUND_MODE_VOICE);
+                       __isSoundStatusOn = false;
+                       StopSession();
+               }
        }
        if (__isVibrateStatusOn == true)
        {
                __pVibrator->Stop();
                __isVibrateStatusOn = false;
        }
+       if(__pWaitingTonePlayer != null)
+       {
+               if(__pWaitingTonePlayer->GetState() == PLAYER_STATE_PLAYING)
+               {
+                       __pWaitingTonePlayer->Stop();
+               }
+       }
+
        AppLogDebug("Exit");
 }