LinphoneForegroundLifeTimeAgent.cs 2.09 KB
Newer Older
1 2
using Microsoft.Phone.Networking.Voip;
using System.Diagnostics;
3
using Linphone.Core;
4
using System.Threading;
5
using Linphone.Core.OutOfProcess;
6 7 8 9 10 11 12 13 14 15

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

        }

16 17 18
        /// <summary>
        /// Called when the app is in foreground (when it starts or when it's resumed)
        /// </summary>
19 20 21
        protected override void OnLaunched()
        {
            Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] The UI has entered the foreground.");
Ghislain MARY's avatar
Ghislain MARY committed
22
            AgentHost.OnAgentStarted();
Sylvain Berfini's avatar
Sylvain Berfini committed
23
            //Force the callController to be initialized now to avoid creating it at the last moment (workaroud outgoing call crash after app started)
24
            Globals.Instance.CallController.IncomingCallViewDismissed = null;
25 26 27 28 29 30

            // Changes the decline reason if needed.
            if (Customs.DeclineCallWithBusyReason)
            {
                Globals.Instance.CallController.DeclineReason = DeclineReason.LinphoneReasonBusy;
            }
31 32
        }

33 34 35
        /// <summary>
        /// Called when the app is in background
        /// </summary>
36 37 38 39 40 41 42 43 44 45 46 47
        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);
            }

48
            Debug.WriteLine("[LinphoneForegroundLifeTimeAgent] NotifyComplete");
49 50 51
            base.NotifyComplete();
        }
    }
52
}