LinphoneManager.cs 5.24 KB
Newer Older
1 2
using Microsoft.Phone.Networking.Voip;
using System;
Sylvain Berfini's avatar
Sylvain Berfini committed
3 4
using System.Collections.Generic;
using System.Collections.ObjectModel;
5
using System.Diagnostics;
Sylvain Berfini's avatar
Sylvain Berfini committed
6 7 8 9 10 11 12 13
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Linphone.Model
{
    public class LinphoneManager
    {
14
        private static LinphoneManager singleton;
Sylvain Berfini's avatar
Sylvain Berfini committed
15 16
        public static LinphoneManager Instance
        {
17 18 19 20 21 22 23
            get
            {
                if (LinphoneManager.singleton == null)
                    LinphoneManager.singleton = new LinphoneManager();

                return LinphoneManager.singleton;
            }
Sylvain Berfini's avatar
Sylvain Berfini committed
24 25 26
        }

        private List<CallLogs> _history;
27 28
        private bool BackgroundProcessConnected;

29 30 31
        /// <summary>
        /// Starts and connects the LinphoneManager to the background process (linphonecore)
        /// </summary>
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
        public void ConnectBackgroundProcessToInterface()
        {
            if (BackgroundProcessConnected)
            {
                Debug.WriteLine("[LinphoneManager] Background process already connected to interface");
                return;
            }

            int backgroundProcessID;
            try
            {
                //VoipBackgroundProcess.Launch(out backgroundProcessID);
            }
            catch (Exception e)
            {
                Debug.WriteLine("[LinphoneManager] Error launching VoIP background process. Exception: " + e.Message);
                throw;
            }

            BackgroundProcessConnected = true;
            Debug.WriteLine("[LinphoneManager] Background process connected to interface");
        }

55 56 57
        /// <summary>
        /// disconnects the LinphoneManager from the background process (linphonecore)
        /// </summary>
58 59 60 61 62 63 64 65 66 67 68
        public void DisconnectBackgroundProcessFromInterface()
        {
            if (!BackgroundProcessConnected)
            {
                Debug.WriteLine("[LinphoneManager] Background process not connected to interface yet");
                return;
            }

            BackgroundProcessConnected = false;
            Debug.WriteLine("[LinphoneManager] Background process disconnected from interface");
        }
Sylvain Berfini's avatar
Sylvain Berfini committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

        /// <summary>
        /// Set the debug value for liblinphone
        /// </summary>
        /// <param name="enable">true to enable debug traces, false to disable them</param>
        public void EnableDebug(bool enable)
        {

        }

        /// <summary>
        /// Get the calls' history
        /// </summary>
        /// <returns>A list of CallLogs, each one representing a type of calls (All, Missed, ...)</returns>
        public List<CallLogs> GetCallsHistory()
        {
            _history = new List<CallLogs>();

            ObservableCollection<CallLog> calls = new ObservableCollection<CallLog>();
            ObservableCollection<CallLog> missedCalls = new ObservableCollection<CallLog>();

            CallLogs all = new CallLogs("All", calls);
            _history.Add(all);

            CallLogs missed = new CallLogs("Missed", missedCalls);
            _history.Add(missed);

            return _history;
        }

        /// <summary>
        /// Remove one or many entries from the calls' history
        /// </summary>
102
        /// <param name="logsToRemove">A list of CallLog to remove from history</param>
Sylvain Berfini's avatar
Sylvain Berfini committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        /// <returns>A list of CallLogs, without the removed entries</returns>
        public List<CallLogs> RemoveCallLogs(IEnumerable<CallLog> logsToRemove)
        {
            // When removing log from history, it will be removed from logsToRemove list too. 
            // Using foreach causing the app to crash on a InvalidOperationException, so we are using while
            while (logsToRemove.Count() > 0)
            {
                CallLog logToRemove = logsToRemove.First();
                foreach (CallLogs logs in _history)
                {
                    logs.Calls.Remove(logToRemove);
                }
            }

            return _history;
        }

        /// <summary>
        /// Remove all calls' history from LinphoneCore
        /// </summary>
        public void ClearCallLogs()
        {

        }

        /// <summary>
        /// Start a new call to a sip address
        /// </summary>
        /// <param name="sipAddress">SIP address to call</param>
        public void NewOutgoingCall(String sipAddress)
        {
134 135
            //TileManager tileManager = TileManager.Instance;
            //tileManager.UpdateTileWithMissedCalls(new Random().Next(10));
Sylvain Berfini's avatar
Sylvain Berfini committed
136
        }
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

        /// <summary>
        /// Stops the current call if any
        /// </summary>
        public void EndCurrentCall()
        {

        }


        /// <summary>
        /// Pauses the current call if any and if it's running
        /// </summary>
        public void PauseCurrentCall()
        {

        }

        /// <summary>
        /// Resume the current call if any and if it's paused
        /// </summary>
        public void ResumeCurrentCall()
        {

        }

        /// <summary>
        /// Hang up the current call if any
        /// </summary>
        public void HangUp()
        {

        }
Sylvain Berfini's avatar
Sylvain Berfini committed
170 171
    }
}