RingD.h 5.57 KB
Newer Older
1
/**************************************************************************
atraczyk's avatar
atraczyk committed
2
* Copyright (C) 2016 by Savoir-faire Linux                                *
3 4
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com>          *
atraczyk's avatar
atraczyk committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
*                                                                         *
* 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 3 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, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/

using namespace concurrency;

namespace RingClientUWP
{
24 25 26 27
// its ok to keep this enum here and to use it with the wizard, because in pch.h headers are a-z sorted,
// but it would be much more consistent to move this enum in globals.h when merged

public enum class StartingStatus { NORMAL, REGISTERING_ON_THIS_PC, REGISTERING_THIS_DEVICE };
atraczyk's avatar
atraczyk committed
28 29 30

/* delegate */
delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
Nicolas Jager's avatar
Nicolas Jager committed
31
delegate void StateChange(String^ callId, CallStatus state, int code);
32
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
33
delegate void CallPlaced(String^ callId);
34
delegate void IncomingMessage(String^ callId, String^ payload);
35 36
delegate void DevicesListRefreshed(Vector<String^>^ devicesList);
delegate void ExportOnRingEnded(String^ accountId, String^ pin);
37

atraczyk's avatar
atraczyk committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

public ref class RingD sealed
{
public:
    /* functions */

    /* properties */
    static property RingD^ instance
    {
        RingD^ get()
        {
            static RingD^ instance_ = ref new RingD();
            return instance_;
        }
    }

    property bool daemonRunning
    {
        bool get()
        {
            return daemonRunning_;
        }
    }
61 62 63
    property StartingStatus _startingStatus;
    property String^ _pin;
    property String^ _password;
atraczyk's avatar
atraczyk committed
64

65 66
    void cancelOutGoingCall2(String^ callId); // marche

67 68 69 70 71 72 73 74 75
internal: // why this property has to be internal and not public ?
    property Vector<String^>^ _callIdsList
    {
        Vector<String^>^ get()
        {
            return callIdsList_;
        }
    }

76

atraczyk's avatar
atraczyk committed
77 78 79 80
internal:
    /* functions */
    void startDaemon();
    void reloadAccountList();
81
    void sendAccountTextMessage(String^ message);
82
    void sendSIPTextMessage(String^ message);
83 84
    void createRINGAccount(String^ alias);
    void createSIPAccount(String^ alias);
85 86
    void refuseIncommingCall(String^ call);
    void acceptIncommingCall(String^ call);
Nicolas Jager's avatar
Nicolas Jager committed
87
    void placeCall(Contact^ contact);
88
    /*void cancelOutGoingCall2(String^ callId);*/ // marche pas
89 90
    CallStatus translateCallStatus(String^ state);
    Vector<String^>^ translateKnownRingDevices(const std::map<std::string, std::string> devices);
91 92

    void hangUpCall2(String^ callId);
93 94
    void pauseCall(String ^ callId);
    void unPauseCall(String ^ callId);
95
    void askToRefreshKnownDevices(String^ accountId);
96
    void askToExportOnRing(String^ accountId, String^ password);
97
    void eraseCacheFolder();
atraczyk's avatar
atraczyk committed
98 99

    /* TODO : move members */
100
    ///bool hasConfig; // replaced by startingStatus
atraczyk's avatar
atraczyk committed
101
    std::string accountName;
102
    String ^ currentCallId; // to save ongoing call id during visibility change
atraczyk's avatar
atraczyk committed
103 104 105 106

    /* events */
    event IncomingCall^ incomingCall;
    event StateChange^ stateChange;
107
    event IncomingAccountMessage^ incomingAccountMessage;
108
    event IncomingMessage^ incomingMessage;
109
    event CallPlaced^ callPlaced;
110 111
    event DevicesListRefreshed^ devicesListRefreshed;
    event ExportOnRingEnded^ exportOnRingEnded;
atraczyk's avatar
atraczyk committed
112 113 114

private:
    /* sub classes */
115 116 117
    enum class Request {
        None,
        AddRingAccount,
118 119
        AddSIPAccount,
        RefuseIncommingCall,
Nicolas Jager's avatar
Nicolas Jager committed
120
        AcceptIncommingCall,
121
        CancelOutGoingCall,
122
        HangUpCall,
123 124
        PauseCall,
        UnPauseCall,
125
        RegisterDevice,
126 127
        GetKnownDevices,
        ExportOnRing
128
    };
129 130 131 132


    Vector<String^>^ callIdsList_;

atraczyk's avatar
atraczyk committed
133 134
    ref class Task
    {
135
    internal:
136 137 138
        Task(Request r) {
            request = r;
        }
139
        Task(Request r, String^ c) {
140 141 142
            request = r;
            _callId = c;
        }
143 144 145 146 147
        Task(Request r, String^ p, String^ P) {
            request = r;
            _pin = p;
            _password = P;
        }
atraczyk's avatar
atraczyk committed
148 149
    public:
        property Request request;
150
        property String^ _callId;
151 152
        property String^ _pin;
        property String^ _password;
153
        property String^ _accountId;
atraczyk's avatar
atraczyk committed
154 155 156 157 158
    };

    /* functions */
    RingD(); // singleton
    void dequeueTasks();
159
//    CallStatus translateCallStatus(String^ state);
atraczyk's avatar
atraczyk committed
160 161 162 163 164

    /* members */
    std::string localFolder_;
    bool daemonRunning_ = false;
    std::queue<Task^> tasksList_;
165
    StartingStatus startingStatus_ = StartingStatus::NORMAL;
atraczyk's avatar
atraczyk committed
166
};
Nicolas Jager's avatar
Nicolas Jager committed
167
}