LinphoneForegroundLifeTimeAgent.cs 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
LinphoneForegroundLifeTimeAgent.cs
Copyright (C) 2015  Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17
*/

using Microsoft.Phone.Networking.Voip;
18
using System.Diagnostics;
19
using Linphone.Core;
20
using System.Threading;
21
using Linphone.Core.OutOfProcess;
22 23 24 25 26 27 28 29 30 31

namespace Linphone.Agents
{
    public class LinphoneForegroundLifeTimeAgent : VoipForegroundLifetimeAgent
    {
        public LinphoneForegroundLifeTimeAgent() : base()
        {

        }

32 33 34
        /// <summary>
        /// Called when the app is in foreground (when it starts or when it's resumed)
        /// </summary>
35 36 37
        protected override void OnLaunched()
        {
            Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] The UI has entered the foreground.");
Ghislain MARY's avatar
Ghislain MARY committed
38
            AgentHost.OnAgentStarted();
Sylvain Berfini's avatar
Sylvain Berfini committed
39
            //Force the callController to be initialized now to avoid creating it at the last moment (workaroud outgoing call crash after app started)
40
            Globals.Instance.CallController.IncomingCallViewDismissed = null;
41 42 43 44

            // Changes the decline reason if needed.
            if (Customs.DeclineCallWithBusyReason)
            {
45
                Globals.Instance.CallController.DeclineReason = Reason.LinphoneReasonBusy;
46
            }
47 48
        }

49 50 51
        /// <summary>
        /// Called when the app is in background
        /// </summary>
52 53 54 55 56 57 58 59 60 61 62 63
        protected override void OnCancel()
        {
            Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] The UI is leaving the foreground");

            uint currentProcessId = Globals.GetCurrentProcessId();
            string backgroundProcessReadyEventName = Globals.GetBackgroundProcessReadyEventName(currentProcessId);
            using (EventWaitHandle backgroundProcessReadyEvent = new EventWaitHandle(initialState: false, mode: EventResetMode.ManualReset, name: backgroundProcessReadyEventName))
            {
                backgroundProcessReadyEvent.WaitOne();
                Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] Background process {0} is ready", currentProcessId);
            }

64
            Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] NotifyComplete");
65 66 67
            base.NotifyComplete();
        }
    }
68
}