callbackshandler.h 17.6 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
/****************************************************************************
Sébastien Blin's avatar
Sébastien Blin committed
2
 *    Copyright (C) 2017-2019 Savoir-faire Linux Inc.                                  *
3
4
 *   Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com>             *
 *   Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>           *
Nicolas Jager's avatar
Nicolas Jager committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library 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      *
 *   Lesser 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/>.  *
 ***************************************************************************/
#pragma once

21
22
// Std
#include <memory>
23
24
#include <string>
#include <map>
25

Nicolas Jager's avatar
Nicolas Jager committed
26
27
28
29
30
// Qt
#include <qobject.h>

// Lrc
#include "typedefs.h"
Anthony Léonard's avatar
Anthony Léonard committed
31
#include "api/datatransfer.h"
32
#include "qtwrapper/conversions_wrap.hpp"
Nicolas Jager's avatar
Nicolas Jager committed
33
34
35
36

namespace lrc
{

37
38
39
namespace api
{
class Lrc;
40
41
42
43
44

namespace account
{
    enum class Status;
}
45
46
}

Nicolas Jager's avatar
Nicolas Jager committed
47
48
49
50
class CallbacksHandler : public QObject {
    Q_OBJECT

public:
51
    CallbacksHandler(const api::Lrc& parent);
Nicolas Jager's avatar
Nicolas Jager committed
52
53
    ~CallbacksHandler();

54
55
56
57
    // This connection relies on the behavior controller
    // and needs to be made after the lrc object is constructed
    void subscribeToDebugReceived();

58
59
Q_SIGNALS:
    /**
60
61
62
     * Connect this signal to get incoming text interaction from the DHT.
     * @param accountId interaction receiver.
     * @param from interaction sender.
63
64
     * @param payloads.
     */
65
66
67
    void newAccountMessage(std::string& accountId,
                           std::string& from,
                           std::map<std::string,std::string> payloads);
68
69
    /**
     * Connect this signal to get information when a peer is online.
70
71
72
73
     * @param contactUri the peer.
     * @param present if the peer is online.
     */
    void newBuddySubscription(const std::string& contactUri, bool present);
74
75
76
77
78
79
    /**
     * Connect this signal to get information when peer discovery changes.
     * @param contactUri the peer.
     * @param state is 0 if the peer is added.
     */
    void newPeerSubscription(const std::string& accountId, const std::string& contactUri, int state, const std::string& displayname);
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    /**
     * Connect this signal to know when a contact is removed by the daemon.
     * @param accountId the one who lost a contact.
     * @param contactUri the contact removed.
     * @param banned if the contact was banned
     */
    void contactRemoved(const std::string& accountId, const std::string& contactUri, bool banned);
    /**
     * Connect this signal to know when a contact is added by the daemon.
     * @param accountId the one who got a new contact.
     * @param contactUri the new contact.
     * @param confirmed if the contact is trusted.
     */
    void contactAdded(const std::string& accountId, const std::string& contactUri, bool confirmed);
    /**
     * Connect this signal to know when an incoming request is added by the daemon
     * @param accountId the one who got the request
     * @param ringId the peer contact
     * @param payload the VCard
     */
    void incomingContactRequest(const std::string& accountId, const std::string& ringId, const std::string& payload);
    /**
     * Connect this signal to know when a call arrives
     * @param accountId the one who receives the call
     * @param callId the call id
     * @param fromUri the caller uri
     */
    void incomingCall(const std::string& accountId,
                      const std::string& callId,
                      const std::string& fromUri);
    /**
     * Connect this signal to know when a call is updated
     * @param callId the call id
     * @param state the new state
     * @param code
     */
    void callStateChanged(const std::string& callId, const std::string &state, int code);
117
118
119
120
121
122
123
    /**
     * Connect this signal to know when the account details have changed
     * @param accountId the one who changes
     * @param details the new details
     */
    void accountDetailsChanged(const std::string& accountId,
                               const std::map<std::string,std::string>& details);
124
125
126
127
    /**
     * Connect this signal to know when the accounts list changed
     */
    void accountsChanged();
128
129
130
131
132
133
    /**
     * Connect this signal to know when the account status changed
     * @param accountId the one who changes
     * @param status the new status
     */
    void accountStatusChanged(const std::string& accountId, const api::account::Status status);
134
    /**
135
136
137
138
139
140
     * Connect this signal to know where a VCard is incoming
     * @param callId the call linked to this VCard
     * @param from the sender URI
     * @param part the number of the part
     * @param numberOfParts of the VCard
     * @param payload content of the VCard
141
     */
142
143
144
145
146
    void incomingVCardChunk(const std::string& callId,
                            const std::string& from,
                            int part,
                            int numberOfParts,
                            const std::string& payload);
147
    /**
148
149
150
151
     * Connect this signal to get incoming text interaction from SIP.
     * @param callId the call linked.
     * @param from interaction sender.
     * @param body the text received.
152
     */
153
154
    void incomingCallMessage(const std::string& callId,
                             const std::string& from,
155
156
157
158
159
160
161
162
163
164
165
166

                             const std::string& body) const;
    /**
     * Connect this signal to know when a new conference is created
     * @param callId of the conference
     */
    void conferenceCreated(const std::string& callId);
    /**
     * Connect this signal to know when a conference is removed
     * @param callId of the conference
     */
    void conferenceRemoved(const std::string& callId);
167
168
169
170
171
172
173
174
175
176
    /**
     * Connect this signal to know when a message sent get a new status
     * @param accountId, account linked
     * @param id of the message
     * @param to, peer uri
     * @param status, new status for this message
     */
    void accountMessageStatusChanged(const std::string& accountId,
                                     const uint64_t id,
                                     const std::string& to, int status);
177

Anthony Léonard's avatar
Anthony Léonard committed
178
179
    void transferStatusCreated(long long dringId, api::datatransfer::Info info);
    void transferStatusCanceled(long long dringId, api::datatransfer::Info info);
180
181
    void transferStatusAwaitingPeer(long long dringId, api::datatransfer::Info info);
    void transferStatusAwaitingHost(long long dringId, api::datatransfer::Info info);
Anthony Léonard's avatar
Anthony Léonard committed
182
183
184
    void transferStatusOngoing(long long dringId, api::datatransfer::Info info);
    void transferStatusFinished(long long dringId, api::datatransfer::Info info);
    void transferStatusError(long long dringId, api::datatransfer::Info info);
185
    void transferStatusTimeoutExpired(long long dringId, api::datatransfer::Info info);
186
    void transferStatusUnjoinable(long long dringId, api::datatransfer::Info info);
Nicolas Jager's avatar
Nicolas Jager committed
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    /**
     * Connect this signal to get when a device name changed or a device is added
     * @param accountId interaction receiver.
     * @param devices A map of device IDs with corresponding labels.
     */
    void knownDevicesChanged(std::string& accountId,
                             std::map<std::string,std::string> devices);

    /**
     * Emit deviceRevocationEnded
     * @param accountId
     * @param deviceId
     * @param status SUCCESS = 0, WRONG_PASSWORD = 1, UNKNOWN_DEVICE = 2
     */
    void deviceRevocationEnded(const std::string& accountId,
                               const std::string& deviceId,
                               const int status);

206
207
208
209
210
211
212
213
    /**
     * Emit exportOnRingEnded
     * @param accountId
     * @param status SUCCESS = 0, WRONG_PASSWORD = 1, NETWORK_ERROR = 2
     * @param pin
     */
    void exportOnRingEnded(const std::string& accountId, int status, const std::string& pin);

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
    /**
     * Name registration has ended
     * @param accountId
     * @param status
     * @param name
     */
    void nameRegistrationEnded(const std::string& accountId, int status, const std::string& name);

    /**
     * Name registration has been found
     * @param accountId
     * @param status
     * @param name
     */
    void registeredNameFound(const std::string& accountId, int status, const std::string& address, const std::string& name);

230
231
232
233
234
235
236
    /**
     * Migration ended
     * @param accountId
     * @param ok if migration succeed
     */
    void migrationEnded(const std::string& accountId, bool ok);

237
238
239
240
241
242
    /**
    * Debug message received
    * @param message
    */
    void debugMessageReceived(const std::string& message);

Sébastien Blin's avatar
Sébastien Blin committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
    /**
     * Renderer is started
     * @param id
     * @param shmrenderer
     * @param width
     * @param height
     */
    void startedDecoding(const std::string& id, const std::string& shmPath, int width, int height);

    /**
     * Renderer is stopped
     * @param id
     * @param shmrenderer
     */
    void stoppedDecoding(const std::string& id, const std::string& shmPath);

259
260
261
262
263
    /**
     * Emitted when a device is plugged or unplugged
     */
    void deviceEvent();

264
265
266
267
268
269
270
    /**
     * Emitted when an audio level is received
     * @param id of the ringbuffer level
     * @param level
     */
    void audioMeter(const std::string& id, float level);

271
272
273
274
275
276
    /**
     * Emitted when an local recorder is finished
     * @param filePath
     */
    void recordPlaybackStopped(const std::string& filePath);

277
278
279
280
281
282
283
284
285
    /**
     * Emitted when an audio level is received
     * @param accountId
     * @param newCount
     * @param oldCount
     * @param urgentCount
     */
    void voiceMailNotify(const std::string& accountId, int newCount, int oldCount, int urgentCount);

286
287
private Q_SLOTS:
    /**
288
     * Emit newAccountMessage
289
290
     * @param accountId
     * @param from
291
     * @param payloads of the interaction
292
     */
293
294
295
    void slotNewAccountMessage(const QString& accountId,
                               const QString& from,
                               const QMap<QString,QString>& payloads);
296
    /**
297
     * Emit newBuddySubscription
298
299
300
301
302
     * @param accountId
     * @param contactUri
     * @param status if the contact is present
     * @param message unused for now
     */
303
304
305
306
    void slotNewBuddySubscription(const QString& accountId,
                                  const QString& contactUri,
                                  bool status,
                                  const QString& message);
307
    /**
308
309
     * Emit contactAdded
     * @param accountId account linked
310
311
312
313
314
     * @param contactUri
     * @param confirmed
     */
    void slotContactAdded(const QString& accountId, const QString& contactUri, bool confirmed);
    /**
315
316
     * Emit contactRemoved
     * @param accountId account linked
317
318
319
320
     * @param contactUri
     * @param banned
     */
    void slotContactRemoved(const QString& accountId, const QString& contactUri, bool banned);
321
322
323
324
325
326
327
328
329
330
    /**
     * Emit incomingContactRequest
     * @param accountId the linked id
     * @param ringId the peer contact
     * @param payload the VCard
     * @param time when the request was received
     */
    void slotIncomingContactRequest(const QString& accountId,
                                    const QString& ringId,
                                    const QByteArray& payload, time_t time);
331
332
333
334
335
336
337
    /**
     * Emit accountDetailsChanged
     * @param accountId
     * @param details
     */
    void slotAccountDetailsChanged(const QString& accountId,
                                   const MapStringString& details);
338
339
340
341
342
    /**
     * Emit accountsChanged
     */
    void slotAccountsChanged();

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
    /**
     * Emit accountStatusChanged
     * @param accountId
     * @param registration_state
     * @param detail_code
     * @param detail_str
     */
    void slotRegistrationStateChanged(const QString& accountId,
                                      const QString& registration_state,
                                      unsigned detail_code,
                                      const QString& detail_str);
    /**
     * Get the URI of the peer and emit incomingCall
     * @param accountId account linked
     * @param callId the incoming call id
     * @param fromQString the uri of the peer
     */
    void slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri);
    /**
     * Emit callStateChanged
     * @param callId the call which changes.
     * @param state the new state
     * @param code unused for now
     */
    void slotCallStateChanged(const QString& callId, const QString &state, int code);
    /**
     * Parse a call message and emit incomingVCardChunk if it's a VCard chunk
     * else incomingCallMessage if it's a text message
     * @param callId call linked
     * @param from the URI
     * @param interaction the content of the Message.
     */
    void slotIncomingMessage(const QString& callId,
                             const QString& from,
                             const QMap<QString,QString>& interaction);
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
    /**
     * Emit conferenceCreated
     * @param callId of the conference
     */
    void slotConferenceCreated(const QString& callId);
    /**
     * Emit conferenceRemove
     * @param callId of the conference
     */
    void slotConferenceRemoved(const QString& callId);
    /**
     * Call slotCallStateChanged
     * @param callId of the conference
     * @param state, new state
     */
    void slotConferenceChanged(const QString& callId, const QString& state);
394
395
396
397
398
399
400
401
402
403
    /**
     * Emit accountMessageStatusChanged
     * @param accountId
     * @param id of the message for the daemon
     * @param to peer uri
     * @param status, new status
     */
    void slotAccountMessageStatusChanged(const QString& accountId,
                                         const uint64_t id,
                                         const QString& to, int status);
404

Nicolas Jager's avatar
Nicolas Jager committed
405
406
    void slotDataTransferEvent(qulonglong id, uint code);

407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    /**
     * Emit knownDevicesChanged
     * @param accountId
     * @param devices A map of device IDs and corresponding labels
     */
    void slotKnownDevicesChanged(const QString& accountId,
                                 const QMap<QString, QString>& devices);

     /**
      * Emit deviceRevocationEnded
      * @param accountId
      * @param deviceId
      * @param status SUCCESS = 0, WRONG_PASSWORD = 1, UNKNOWN_DEVICE = 2
      */
     void slotDeviceRevokationEnded(const QString& accountId,
                                    const QString& deviceId,
                                    const int status);

425
426
427
428
429
430
431
432
    /**
     * Emit exportOnRingEnded
     * @param accountId
     * @param status SUCCESS = 0, WRONG_PASSWORD = 1, NETWORK_ERROR = 2
     * @param pin
     */
    void slotExportOnRingEnded(const QString& accountId, int status, const QString& pin);

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
    /**
     * Emit nameRegistrationEnded
     * @param accountId
     * @param status
     * @param name
     */
    void slotNameRegistrationEnded(const QString& accountId, int status, const QString& name);

    /**
     * Emit registeredNameFound
     * @param accountId
     * @param status
     * @param name
     */
    void slotRegisteredNameFound(const QString& accountId, int status, const QString& address, const QString& name);

449
450
451
452
453
454
455
    /**
     * emit migrationEnded
     * @param accountId
     * @param status
     */
    void slotMigrationEnded(const QString& accountId, const QString& status);

456
457
458
459
460
461
462
463
464
465
    /**
    * emit debugMessageReceived
    * @param message
    */
#ifdef ENABLE_LIBWRAP
    void slotDebugMessageReceived(const std::string& message);
#else
    void slotDebugMessageReceived(const QString& message);
#endif

Sébastien Blin's avatar
Sébastien Blin committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    /**
     * Renderer is started
     * @param id
     * @param shmrenderer
     * @param width
     * @param height
     */
    void slotStartedDecoding(const QString& id, const QString& shmPath, int width, int height);

    /**
     * Renderer is stopped
     * @param id
     * @param shmrenderer
     */
    void slotStoppedDecoding(const QString& id, const QString& shmPath);

482
483
484
485
486
    /**
     * Detect when a device is plugged or unplugged
     */
    void slotDeviceEvent();

487
488
489
490
491
492
    /**
     * Called when an audio meter level is received
     * @param id of the ringbuffer level
     * @param level
     */
    void slotAudioMeterReceived(const QString& id, float level);
Sébastien Blin's avatar
Sébastien Blin committed
493

494
495
496
497
498
499
500
501
502
503
504
505
    /**
     * Emit newPeerSubscription
     * @param accountId
     * @param contactUri
     * @param status if the peer is added or removed
     * @param displayname is the account display name
     */
    void slotNearbyPeerSubscription(const QString& accountId,
                                    const QString& contactUri,
                                    int state,
                                    const QString& displayname);

506
507
508
509
510
511
512
513
514
515
516
517
    /**
     * Emit voiceMailNotify
     * @param accountId
     * @param new VM
     * @param old VM
     * @param new Urgent VM
     */
    void slotVoiceMailNotify(const QString& accountId,
                             int newCount,
                             int oldCount,
                             int urgentCount);

518
519
520
521
522
523
    /**
     * Emit recordPlaybackStopped
     * @param filePath
     */
    void slotRecordPlaybackStopped(const QString& filePath);

524
525
private:
    const api::Lrc& parent;
Nicolas Jager's avatar
Nicolas Jager committed
526
527
528
};

} // namespace lrc