BackgroundManager.cs 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
BackgroundManager.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;
Sylvain Berfini's avatar
Sylvain Berfini committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
using Linphone.Core;
using Linphone.Core.OutOfProcess;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Phone.Networking.Voip;
using System.Windows.Media.Imaging;
using Windows.Phone.Media.Devices;
using System.Reflection;
using Microsoft.Phone.Net.NetworkInformation;
using Windows.Storage;
using Linphone.Agents;

namespace Linphone.Agents
{
    public class BackgroundManager
    {
        private static BackgroundManager singleton;
        /// <summary>
        /// Static instance of the class.
        /// </summary>
        public static BackgroundManager Instance
        {
            get
            {
                if (BackgroundManager.singleton == null)
                    BackgroundManager.singleton = new BackgroundManager();

                return BackgroundManager.singleton;
            }
        }

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        private Server oopServer;
        /// <summary>
        /// A proxy to the server object in the background agent host process 
        /// </summary>
        public Server OopServer
        {
            get {
               if (oopServer == null)
                    oopServer = (Server)WindowsRuntimeMarshal.GetActivationFactory(typeof(Server)).ActivateInstance();
               return oopServer;
            }

            set {
                oopServer = value;
            }
        }
Sylvain Berfini's avatar
Sylvain Berfini committed
73 74 75 76 77 78 79

        /// <summary>
        /// Creates a new LinphoneCore (if not created yet) using a LinphoneCoreFactory.
        /// </summary>
        public void InitLinphoneCore()
        {
            // Initiate incoming call processing by creating the Linphone Core
80
            InitManager.CreateLinphoneCore(OopServer, null, OutputTraceLevel.Message);
81
            OopServer.LinphoneCore.NetworkReachable = true;
82
            OopServer.LinphoneCore.IterateEnabled = true;
Sylvain Berfini's avatar
Sylvain Berfini committed
83 84 85
        }
    }
}