callbackshandler.h 18.5 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
/****************************************************************************
Sébastien Blin's avatar
Sébastien Blin committed
2
 *    Copyright (C) 2017-2020 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 21
 *                                                                          *
 *   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

#include "typedefs.h"
Anthony Léonard's avatar
Anthony Léonard committed
22
#include "api/datatransfer.h"
23
#include "qtwrapper/conversions_wrap.hpp"
Nicolas Jager's avatar
Nicolas Jager committed
24

25 26 27 28
#include <QObject>

#include <memory>

Nicolas Jager's avatar
Nicolas Jager committed
29 30 31
namespace lrc
{

32 33 34
namespace api
{
class Lrc;
35 36 37 38 39

namespace account
{
    enum class Status;
}
40 41
}

Nicolas Jager's avatar
Nicolas Jager committed
42 43 44 45
class CallbacksHandler : public QObject {
    Q_OBJECT

public:
46
    CallbacksHandler(const api::Lrc& parent);
Nicolas Jager's avatar
Nicolas Jager committed
47 48
    ~CallbacksHandler();

49 50 51 52
    // This connection relies on the behavior controller
    // and needs to be made after the lrc object is constructed
    void subscribeToDebugReceived();

53 54
Q_SIGNALS:
    /**
55 56
     * Connect this signal to get incoming text interaction from the DHT.
     * @param accountId interaction receiver.
57 58
     * @param msgId     interaction's id.
     * @param from      interaction sender.
59 60
     * @param payloads.
     */
61 62 63 64
    void newAccountMessage(const QString& accountId,
                           const QString& msgId,
                           const QString& from,
                           const MapStringString& payloads);
65 66
    /**
     * Connect this signal to get information when a peer is online.
67 68 69
     * @param contactUri the peer.
     * @param present if the peer is online.
     */
70
    void newBuddySubscription(const QString& contactUri, bool present);
71 72 73 74 75
    /**
     * Connect this signal to get information when peer discovery changes.
     * @param contactUri the peer.
     * @param state is 0 if the peer is added.
     */
76
    void newPeerSubscription(const QString& accountId, const QString& contactUri, int state, const QString& displayname);
77 78 79 80 81 82
    /**
     * 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
     */
83
    void contactRemoved(const QString& accountId, const QString& contactUri, bool banned);
84 85 86 87 88 89
    /**
     * 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.
     */
90
    void contactAdded(const QString& accountId, const QString& contactUri, bool confirmed);
91 92 93 94 95 96
    /**
     * 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
     */
97
    void incomingContactRequest(const QString& accountId, const QString& ringId, const QString& payload);
98 99 100 101 102
    /**
     * 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
103
     * @param displayName the display name of incoming call
104
     */
105 106 107 108
    void incomingCall(const QString& accountId,
                      const QString& callId,
                      const QString& fromUri,
                      const QString& displayName);
109 110 111 112 113 114
    /**
     * Connect this signal to know when a call is updated
     * @param callId the call id
     * @param state the new state
     * @param code
     */
115
    void callStateChanged(const QString& callId, const QString& state, int code);
116 117 118 119 120
    /**
     * Connect this signal to know when the account details have changed
     * @param accountId the one who changes
     * @param details the new details
     */
121 122
    void accountDetailsChanged(const QString& accountId,
                               const MapStringString& details);
123 124 125 126 127
    /**
     * Connect this signal to know when the volatile account details have changed
     * @param accountId the one who changes
     * @param details the new details
     */
128 129
    void volatileAccountDetailsChanged(const QString& accountId,
                                       const MapStringString& details);
130 131 132 133
    /**
     * Connect this signal to know when the accounts list changed
     */
    void accountsChanged();
134 135 136 137 138
    /**
     * Connect this signal to know when the account status changed
     * @param accountId the one who changes
     * @param status the new status
     */
139
    void accountStatusChanged(const QString& accountId, const api::account::Status status);
140
    /**
141 142 143 144 145 146
     * 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
147
     */
148 149
    void incomingVCardChunk(const QString& callId,
                            const QString& from,
150 151
                            int part,
                            int numberOfParts,
152
                            const QString& payload);
153
    /**
154 155 156 157
     * Connect this signal to get incoming text interaction from SIP.
     * @param callId the call linked.
     * @param from interaction sender.
     * @param body the text received.
158
     */
159 160 161
    void incomingCallMessage(const QString& callId,
                             const QString& from,
                             const QString& body) const;
162 163 164 165
    /**
     * Connect this signal to know when a new conference is created
     * @param callId of the conference
     */
166
    void conferenceCreated(const QString& callId);
167 168 169 170
    /**
     * Connect this signal to know when a conference is removed
     * @param callId of the conference
     */
171
    void conferenceRemoved(const QString& callId);
172 173 174 175 176 177 178
    /**
     * 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
     */
179
    void accountMessageStatusChanged(const QString& accountId,
180
                                     const uint64_t id,
181
                                     const QString& to, int status);
182

Anthony Léonard's avatar
Anthony Léonard committed
183 184
    void transferStatusCreated(long long dringId, api::datatransfer::Info info);
    void transferStatusCanceled(long long dringId, api::datatransfer::Info info);
185 186
    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
187 188 189
    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);
190
    void transferStatusTimeoutExpired(long long dringId, api::datatransfer::Info info);
191
    void transferStatusUnjoinable(long long dringId, api::datatransfer::Info info);
Nicolas Jager's avatar
Nicolas Jager committed
192

193 194 195 196 197
    /**
     * 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.
     */
198 199
    void knownDevicesChanged(const QString& accountId,
                             const MapStringString& devices);
200 201 202 203 204 205 206

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

211
    /**
212
     * Account profile has been received
213
     * @param accountId
214
     * @param displayName
215 216
     * @param userPhoto
     */
217
    void accountProfileReceived(const QString& accountId, const QString& displayName, const QString& userPhoto);
218

219 220 221 222 223 224
    /**
     * Emit exportOnRingEnded
     * @param accountId
     * @param status SUCCESS = 0, WRONG_PASSWORD = 1, NETWORK_ERROR = 2
     * @param pin
     */
225
    void exportOnRingEnded(const QString& accountId, int status, const QString& pin);
226

227 228 229 230 231 232
    /**
     * Name registration has ended
     * @param accountId
     * @param status
     * @param name
     */
233
    void nameRegistrationEnded(const QString& accountId, int status, const QString& name);
234 235 236 237 238 239 240

    /**
     * Name registration has been found
     * @param accountId
     * @param status
     * @param name
     */
241
    void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name);
242

243 244 245 246 247
    /**
     * Migration ended
     * @param accountId
     * @param ok if migration succeed
     */
248
    void migrationEnded(const QString& accountId, bool ok);
249

250 251 252 253
    /**
    * Debug message received
    * @param message
    */
254
    void debugMessageReceived(const QString& message);
255

Sébastien Blin's avatar
Sébastien Blin committed
256 257 258 259 260 261 262
    /**
     * Renderer is started
     * @param id
     * @param shmrenderer
     * @param width
     * @param height
     */
263
    void startedDecoding(const QString& id, const QString& shmPath, int width, int height);
Sébastien Blin's avatar
Sébastien Blin committed
264 265 266 267 268 269

    /**
     * Renderer is stopped
     * @param id
     * @param shmrenderer
     */
270
    void stoppedDecoding(const QString& id, const QString& shmPath);
Sébastien Blin's avatar
Sébastien Blin committed
271

272 273 274 275 276
    /**
     * Emitted when a device is plugged or unplugged
     */
    void deviceEvent();

277 278 279 280 281
    /**
     * Emitted when an audio level is received
     * @param id of the ringbuffer level
     * @param level
     */
282
    void audioMeter(const QString& id, float level);
283

284 285 286 287
    /**
     * Emitted when an local recorder is finished
     * @param filePath
     */
288
    void recordPlaybackStopped(const QString& filePath);
289

290 291 292 293 294 295 296
    /**
     * Emitted when an audio level is received
     * @param accountId
     * @param newCount
     * @param oldCount
     * @param urgentCount
     */
297
    void voiceMailNotify(const QString& accountId, int newCount, int oldCount, int urgentCount);
298

299 300
private Q_SLOTS:
    /**
301
     * Emit newAccountMessage
302
     * @param accountId
303
     * @param msgId
304
     * @param from
305
     * @param payloads of the interaction
306
     */
307
    void slotNewAccountMessage(const QString& accountId,
308
                               const QString& msgId,
309 310
                               const QString& from,
                               const QMap<QString,QString>& payloads);
311
    /**
312
     * Emit newBuddySubscription
313 314 315 316 317
     * @param accountId
     * @param contactUri
     * @param status if the contact is present
     * @param message unused for now
     */
318 319 320 321
    void slotNewBuddySubscription(const QString& accountId,
                                  const QString& contactUri,
                                  bool status,
                                  const QString& message);
322
    /**
323 324
     * Emit contactAdded
     * @param accountId account linked
325 326 327 328 329
     * @param contactUri
     * @param confirmed
     */
    void slotContactAdded(const QString& accountId, const QString& contactUri, bool confirmed);
    /**
330 331
     * Emit contactRemoved
     * @param accountId account linked
332 333 334 335
     * @param contactUri
     * @param banned
     */
    void slotContactRemoved(const QString& accountId, const QString& contactUri, bool banned);
336 337 338 339 340 341 342 343 344 345
    /**
     * 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);
346 347 348 349 350 351 352
    /**
     * Emit accountDetailsChanged
     * @param accountId
     * @param details
     */
    void slotAccountDetailsChanged(const QString& accountId,
                                   const MapStringString& details);
353 354 355 356 357 358 359
    /**
     * Emit volatileAccountDetailsChanged
     * @param accountId
     * @param details
     */
    void slotVolatileAccountDetailsChanged(const QString& accountId,
                                           const MapStringString& details);
360 361 362 363 364
    /**
     * Emit accountsChanged
     */
    void slotAccountsChanged();

365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
    /**
     * 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);
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
    /**
     * 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);
416 417 418 419 420 421 422 423 424 425
    /**
     * 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);
426

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

429 430 431 432 433 434
    /**
     * Emit knownDevicesChanged
     * @param accountId
     * @param devices A map of device IDs and corresponding labels
     */
    void slotKnownDevicesChanged(const QString& accountId,
435
                                 const MapStringString& devices);
436 437 438 439 440 441 442 443 444 445 446

     /**
      * 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);

447 448 449
     /**
     * Emit account avatar has been received
     * @param accountId
450
     * @param displayName
451 452
     * @param userPhoto
     */
453
     void slotAccountProfileReceived(const QString& accountId, const QString& displayName, const QString& userPhoto);
454

455 456 457 458 459 460 461 462
    /**
     * 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);

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
    /**
     * 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);

479 480 481 482 483 484 485
    /**
     * emit migrationEnded
     * @param accountId
     * @param status
     */
    void slotMigrationEnded(const QString& accountId, const QString& status);

486 487 488 489 490 491
    /**
    * emit debugMessageReceived
    * @param message
    */
    void slotDebugMessageReceived(const QString& message);

Sébastien Blin's avatar
Sébastien Blin committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
    /**
     * 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);

508 509 510 511 512
    /**
     * Detect when a device is plugged or unplugged
     */
    void slotDeviceEvent();

513 514 515 516 517 518
    /**
     * 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
519

520 521 522 523 524 525 526 527 528 529 530 531
    /**
     * 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);

532 533 534 535 536 537 538 539 540 541 542 543
    /**
     * 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);

544 545 546 547 548 549
    /**
     * Emit recordPlaybackStopped
     * @param filePath
     */
    void slotRecordPlaybackStopped(const QString& filePath);

550 551
private:
    const api::Lrc& parent;
Nicolas Jager's avatar
Nicolas Jager committed
552 553 554
};

} // namespace lrc