RingD.h 6.19 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
delegate void SummonWizard();
38
delegate void AccountUpdated(Account^ account);
39

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

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_;
        }
    }
63
    property StartingStatus _startingStatus;
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, String^ archivePassword, bool upnp);
    void createSIPAccount(String^ alias, String^ sipPassword, String^ sipHostname, String^ sipusername);
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
    CallStatus translateCallStatus(String^ state);
90
    String^ getUserName();
91
    Vector<String^>^ translateKnownRingDevices(const std::map<std::string, std::string> devices);
92 93

    void hangUpCall2(String^ callId);
94 95
    void pauseCall(String ^ callId);
    void unPauseCall(String ^ callId);
96
    void askToRefreshKnownDevices(String^ accountId);
97
    void askToExportOnRing(String^ accountId, String^ password);
98
    void eraseCacheFolder();
99
    void updateAccount(String^ accountId);
100
    void deleteAccount(String^ accountId);
101
    void registerThisDevice(String^ pin, String^ archivePassword);
atraczyk's avatar
atraczyk committed
102 103

    /* TODO : move members */
104
    String ^ currentCallId; // to save ongoing call id during visibility change
atraczyk's avatar
atraczyk committed
105 106 107 108

    /* events */
    event IncomingCall^ incomingCall;
    event StateChange^ stateChange;
109
    event IncomingAccountMessage^ incomingAccountMessage;
110
    event IncomingMessage^ incomingMessage;
111
    event CallPlaced^ callPlaced;
112 113
    event DevicesListRefreshed^ devicesListRefreshed;
    event ExportOnRingEnded^ exportOnRingEnded;
114
    event SummonWizard^ summonWizard;
115
    event AccountUpdated^ accountUpdated;
atraczyk's avatar
atraczyk committed
116 117 118

private:
    /* sub classes */
119 120 121
    enum class Request {
        None,
        AddRingAccount,
122 123
        AddSIPAccount,
        RefuseIncommingCall,
Nicolas Jager's avatar
Nicolas Jager committed
124
        AcceptIncommingCall,
125
        CancelOutGoingCall,
126
        HangUpCall,
127 128
        PauseCall,
        UnPauseCall,
129
        RegisterDevice,
130
        GetKnownDevices,
131
        ExportOnRing,
132 133
        UpdateAccount,
        DeleteAccount
134
    };
135 136 137 138


    Vector<String^>^ callIdsList_;

atraczyk's avatar
atraczyk committed
139 140
    ref class Task
    {
141
    internal:
142 143 144
        Task(Request r) {
            request = r;
        }
145
        Task(Request r, String^ c) {
146 147 148
            request = r;
            _callId = c;
        }
149 150 151 152 153
        Task(Request r, String^ p, String^ P) {
            request = r;
            _pin = p;
            _password = P;
        }
atraczyk's avatar
atraczyk committed
154 155
    public:
        property Request request;
156
        property String^ _alias;
157
        property String^ _callId;
158
        property String^ _pin;
159
        property String^ _password; // refacto : is it safe ? are tasks destroy quickly after been used ?
160
        property String^ _accountId;
161 162 163 164
        property bool _upnp;
        property String^ _sipPassword;
        property String^ _sipHostname;
        property String^ _sipUsername;
atraczyk's avatar
atraczyk committed
165 166 167 168 169
    };

    /* functions */
    RingD(); // singleton
    void dequeueTasks();
170
//    CallStatus translateCallStatus(String^ state);
atraczyk's avatar
atraczyk committed
171 172 173 174 175

    /* members */
    std::string localFolder_;
    bool daemonRunning_ = false;
    std::queue<Task^> tasksList_;
176
    StartingStatus startingStatus_ = StartingStatus::NORMAL;
177
    bool editModeOn_ = false;
atraczyk's avatar
atraczyk committed
178
};
Nicolas Jager's avatar
Nicolas Jager committed
179
}