configurationmanager_mock.h 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/******************************************************************************
*   Copyright (C) 2014-2017 Savoir-faire Linux                                 *
*   Author : Philippe Groarke <philippe.groarke@savoirfairelinux.com>        *
*   Author : Alexandre Lision <alexandre.lision@savoirfairelinux.com>        *
*                                                                            *
*   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 Lesser GNU General Public License *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
*****************************************************************************/
#pragma once

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QTimer>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

#include <future>

#include <configurationmanager_interface.h>
#include <account_const.h>

#include "typedefs.h"
#include "qtwrapper/conversions_wrap.hpp"

/*
 * Proxy class for interface org.ring.Ring.ConfigurationManager
 */
class ConfigurationManagerInterface: public QObject
{
    Q_OBJECT

45 46 47 48
private:
    QMap<QString, VectorMapStringString> accountToContactsMap;
    QStringList availableContacts_;

49 50 51 52 53 54 55
public:

   std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;

   ConfigurationManagerInterface()
   {
      setObjectName("ConfigurationManagerInterface");
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
      availableContacts_ << "contact0";
      availableContacts_ << "contact1";
      availableContacts_ << "contact2";
      availableContacts_ << "dummy";
      for (auto& account: getAccountList()) {
          auto contacts = VectorMapStringString();
          if (account.indexOf("ring") != -1) {
              for (auto& contactUri: availableContacts_) {
                  if (contactUri == "dummy") break;
                  auto contact = QMap<QString, QString>();
                  contact.insert("id", contactUri);
                  contact.insert("added", "true");
                  contact.insert("removed", "false");
                  contact.insert("confirmed", "true");
                  contact.insert("banned", "false");
                  contacts.push_back(contact);
              }
          }
          accountToContactsMap.insert(account, contacts);
      }
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 102 103 104 105 106 107 108 109
   }

   ~ConfigurationManagerInterface() {}

   void emitIncomingAccountMessage(const QString& accountId, const QString& from, const QMap<QString,QString>& payloads)
   {
       emit incomingAccountMessage(accountId, from, payloads);
   }

public Q_SLOTS: // METHODS
    QString addAccount(MapStringString details)
    {
        Q_UNUSED(details)
        QString temp;
        return temp;
    }

    bool exportOnRing(const QString& accountId, const QString& password)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(password)
        return false;
    }

    MapStringString getKnownRingDevices(const QString& accountId)
    {
        Q_UNUSED(accountId)
        MapStringString temp;
        return temp;
    }

    bool lookupName(const QString& accountId, const QString& nameServiceURL, const QString& name)
    {
        Q_UNUSED(nameServiceURL)
110
        if (getAccountList().indexOf(accountId) == -1) return false;
111 112
        if (name == "notAContact") return false;
        emit registeredNameFound(accountId, 00, name, name);
113
        return availableContacts_.indexOf(name) != -1;
114 115 116 117 118
    }

    bool lookupAddress(const QString& accountId, const QString& nameServiceURL, const QString& address)
    {
        Q_UNUSED(nameServiceURL)
119 120
        if (getAccountList().indexOf(accountId) == -1) return false;
        return availableContacts_.indexOf(address) != -1;
121 122 123 124 125 126 127 128 129 130 131 132
    }

    bool registerName(const QString& accountId, const QString& password, const QString& name)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(password)
        Q_UNUSED(name)
        return false;
    }

    MapStringString getAccountDetails(const QString& accountId)
    {
133 134 135 136 137 138 139
        auto result = MapStringString();
        if (accountId.indexOf("ring") != -1) {
            result.insert("Account.type", "RING");
        } else {
            result.insert("Account.type", "SIP");
        }
        return result;
140 141 142 143
    }

    QStringList getAccountList()
    {
144
        auto accountList = QStringList();
145 146 147
        accountList << QString("ring0"); // Used in conversationmodeltester
        accountList << QString("ring1"); // Used in contactmodeltester
        accountList << QString("ring2"); // Used in newcallmodeltester
148 149 150
        accountList << QString("sip0");
        accountList << QString("sip1");
        return accountList;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    }

    MapStringString getAccountTemplate(const QString& accountType)
    {
        Q_UNUSED(accountType)
        return MapStringString();
    }

    VectorUInt getActiveCodecList(const QString& accountId)
    {
        Q_UNUSED(accountId)
        return QVector<unsigned int>();
    }

    QString getAddrFromInterfaceName(const QString& interface)
    {
        Q_UNUSED(interface)
        return QString();
    }

    QStringList getAllIpInterface()
    {
        return QStringList();
    }

    QStringList getAllIpInterfaceByName()
    {
        return QStringList();
    }

    MapStringString getCodecDetails(const QString& accountId, int payload)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(payload)
        return MapStringString();
    }

    VectorUInt getCodecList()
    {
        return QVector<unsigned int>();
    }

    VectorMapStringString getContacts(const QString &accountId)
    {
195 196 197 198
        if (accountToContactsMap.find(accountId) == accountToContactsMap.end()) {
            return VectorMapStringString();
        }
        return accountToContactsMap[accountId];
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
    }

    int getAudioInputDeviceIndex(const QString& devname)
    {
        Q_UNUSED(devname)
        return 0;
    }

    QStringList getAudioInputDeviceList()
    {
        return QStringList();
    }

    QString getAudioManager()
    {
        return QString();
    }

    int getAudioOutputDeviceIndex(const QString& devname)
    {
        Q_UNUSED(devname)
        return 0;
    }

    QStringList getAudioOutputDeviceList()
    {
        return QStringList();
    }

    QStringList getAudioPluginList()
    {
        return QStringList();
    }

    VectorMapStringString getCredentials(const QString& accountId)
    {
        Q_UNUSED(accountId)
        return VectorMapStringString();
    }

    QStringList getCurrentAudioDevicesIndex()
    {
        return QStringList();
    }

    QString getCurrentAudioOutputPlugin()
    {
        return QString();
    }

    int getHistoryLimit()
    {
        return 0;
    }

    MapStringString getHookSettings()
    {
        return MapStringString();
    }

    bool getIsAlwaysRecording()
    {
        return false;
    }

    bool getNoiseSuppressState()
    {
        return false;
    }

    QString getRecordPath()
    {
        return QString();
    }

    QStringList getSupportedAudioManagers()
    {
        QStringList temp;
        return temp;
    }

    MapStringString getShortcuts()
    {
        return MapStringString();
    }

    QStringList getSupportedTlsMethod()
    {
        return QStringList();
    }

    MapStringString validateCertificate(const QString& unused, const QString& certificate)
    {
        Q_UNUSED(unused)
        Q_UNUSED(certificate)
        return MapStringString();
    }

    MapStringString validateCertificatePath(const QString& unused, const QString& certificate, const QString& privateKey, const QString& privateKeyPass, const QString& caListPath)
    {
        Q_UNUSED(unused)
        Q_UNUSED(certificate)
        Q_UNUSED(privateKey)
        Q_UNUSED(privateKeyPass)
        Q_UNUSED(caListPath)
        return MapStringString();
    }

    MapStringString getCertificateDetails(const QString& certificate)
    {
        Q_UNUSED(certificate)
        return MapStringString();
    }

    MapStringString getCertificateDetailsPath(const QString& certificate, const QString& privateKey, const QString& privateKeyPass)
    {
        Q_UNUSED(certificate)
        Q_UNUSED(privateKey)
        Q_UNUSED(privateKeyPass)
        return MapStringString();
    }

    QStringList getSupportedCiphers(const QString& accountId)
    {
        Q_UNUSED(accountId)
        return QStringList();
    }

    MapStringString getTlsDefaultSettings()
    {
        return MapStringString();
    }

    double getVolume(const QString& device)
    {
        Q_UNUSED(device)
        return 0;
    }

    bool isAgcEnabled()
    {
        return false;
    }

    bool isCaptureMuted()
    {
        return false;
    }

    bool isDtmfMuted()
    {
        return false;
    }

    bool isPlaybackMuted()
    {
        return false;
    }

    void muteCapture(bool mute)
    {
        Q_UNUSED(mute)
    }

    void muteDtmf(bool mute)
    {
        Q_UNUSED(mute)
    }

    void mutePlayback(bool mute)
    {
        Q_UNUSED(mute)
    }

    void registerAllAccounts()
    {
    }

    void removeAccount(const QString& accountId)
    {
        Q_UNUSED(accountId)
    }

    int  exportAccounts(const QStringList& accountIds, const QString& filePath, const QString& password)
    {
        Q_UNUSED(accountIds)
        Q_UNUSED(filePath)
        Q_UNUSED(password)
        return 0;
    }

    int importAccounts(const QString& filePath, const QString& password)
    {
        Q_UNUSED(filePath)
        Q_UNUSED(password)
        return 0;
    }

397 398 399 400 401 402 403 404
    bool changeAccountPassword(const QString& id, const QString& currentPassword, const QString& newPassword)
    {
        Q_UNUSED(id)
        Q_UNUSED(currentPassword)
        Q_UNUSED(newPassword)
        return false;
    }

405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
    void sendRegister(const QString& accountId, bool enable)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(enable)
    }

    void setAccountDetails(const QString& accountId, MapStringString details)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(details)
    }

    void setAccountsOrder(const QString& order)
    {
        Q_UNUSED(order)
    }

    void setActiveCodecList(const QString& accountId, VectorUInt &list)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(list)
    }

    void setAgcState(bool enabled)
    {
        Q_UNUSED(enabled)
    }

    void setAudioInputDevice(int index)
    {
        Q_UNUSED(index)
    }

    bool setAudioManager(const QString& api)
    {
        Q_UNUSED(api)
        return false;
    }

    void setAudioOutputDevice(int index)
    {
        Q_UNUSED(index)
    }

    void setAudioPlugin(const QString& audioPlugin)
    {
        Q_UNUSED(audioPlugin)
    }

    void setAudioRingtoneDevice(int index)
    {
        Q_UNUSED(index)
    }

    void setCredentials(const QString& accountId, VectorMapStringString credentialInformation)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(credentialInformation)
    }

    void setHistoryLimit(int days)
    {
        Q_UNUSED(days)
    }

    void setHookSettings(MapStringString settings)
    {
        Q_UNUSED(settings)
    }

    void setIsAlwaysRecording(bool enabled)
    {
        Q_UNUSED(enabled)
    }

    void setNoiseSuppressState(bool state)
    {
        Q_UNUSED(state)
    }

    void setRecordPath(const QString& rec)
    {
        Q_UNUSED(rec)
    }

    void setShortcuts(MapStringString shortcutsMap)
    {
        Q_UNUSED(shortcutsMap)
    }

    void setVolume(const QString& device, double value)
    {
        Q_UNUSED(device)
        Q_UNUSED(value)
    }

    MapStringString getVolatileAccountDetails(const QString& accountId)
    {
        Q_UNUSED(accountId)
        return MapStringString();
    }

    QStringList getPinnedCertificates()
    {
        return QStringList();
    }

    QStringList pinCertificate(const QByteArray& content, bool local)
    {
        Q_UNUSED(content)
        Q_UNUSED(local)
        return QStringList();
    }

    bool unpinCertificate(const QString& certId)
    {
        Q_UNUSED(certId)
        return false;
    }

    void pinCertificatePath(const QString& certPath)
    {
        Q_UNUSED(certPath)
    }

    uint unpinCertificatePath(const QString& certPath)
    {
        Q_UNUSED(certPath)
        return 0;
    }

    bool pinRemoteCertificate(const QString& accountId, const QString& certPath)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(certPath)
        return false;
    }

    bool setCertificateStatus(const QString& accountId, const QString& certPath, const QString& status)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(certPath)
        Q_UNUSED(status)
        return false;
    }

    QStringList getCertificatesByStatus(const QString& accountId, const QString& status)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(status)
        return QStringList();
    }

    VectorMapStringString getTrustRequests(const QString& accountId)
    {
        Q_UNUSED(accountId)
        return VectorMapStringString();
    }

    bool acceptTrustRequest(const QString& accountId, const QString& from)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(from)
        return false;
    }

    bool discardTrustRequest(const QString& accountId, const QString& from)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(from)
        return false;
    }

    void sendTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(from)
        Q_UNUSED(payload)
    }

    void removeContact(const QString &accountId, const QString &uri, bool ban)
    {
587 588 589 590 591 592 593 594 595
        if (getAccountList().indexOf(accountId) == -1) return;
        auto contacts = accountToContactsMap[accountId];
        for (auto c = 0 ; c < contacts.size() ; ++c) {
            if (contacts.at(c)["id"] == uri) {
                contacts.remove(c);
                emit contactRemoved(accountId, uri, ban);
                return;
            }
        }
596 597 598 599
    }

    void addContact(const QString &accountId, const QString &uri)
    {
600 601 602 603 604 605 606 607 608
        if (getAccountList().indexOf(accountId) == -1) return;
        auto contact = QMap<QString, QString>();
        contact.insert("id", uri);
        contact.insert("added", "true");
        contact.insert("removed", "false");
        contact.insert("confirmed", "true");
        contact.insert("banned", "false");
        accountToContactsMap[accountId].push_back(contact);
        emit contactAdded(accountId, uri, true);
609 610 611 612
    }

    uint64_t sendTextMessage(const QString& accountId, const QString& to, const QMap<QString,QString>& payloads)
    {
613
        // NOTE used in ContactModel::sendMessage and ConversationModel::sendMessage
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
        Q_UNUSED(accountId)
        Q_UNUSED(to)
        Q_UNUSED(payloads)
        return 0;
    }

    bool setCodecDetails(const QString& accountId, unsigned int codecId, const MapStringString& details)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(codecId)
        Q_UNUSED(details)
        return false;
    }

    int getMessageStatus(uint64_t id)
    {
        Q_UNUSED(id)
        return 0;
    }

    void connectivityChanged()
    {
    }

    MapStringString getContactDetails(const QString &accountId, const QString &uri)
    {
        Q_UNUSED(accountId)
        Q_UNUSED(uri)
642 643 644 645 646 647 648
        return MapStringString();
    }

    void
    emitIncomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timestamp)
    {
        emit incomingTrustRequest(accountId, from, payload, timestamp);
649 650
    }

Guillaume Roguez's avatar
Guillaume Roguez committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    VectorULongLong dataTransferList() {
        return {};
    }

    uint64_t sendFile(const QString& account_id, const QString& peer_uri, const QString& file_path, const QString& display_name) {
        (void)account_id;
        (void)peer_uri;
        (void)file_path;
        (void)display_name;
        return 0;
    }

    DataTransferInfo dataTransferInfo(uint64_t transfer_id) {
        (void)transfer_id;
        return {};
    }

668
    uint64_t dataTransferBytesProgress(uint64_t transfer_id) {
Guillaume Roguez's avatar
Guillaume Roguez committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682
        (void)transfer_id;
        return 0;
    }

    void acceptFileTransfer(uint64_t transfer_id, const QString& file_path, uint64_t offset) {
        (void)transfer_id;
        (void)file_path;
        (void)offset;
    }

    void cancelDataTransfer(uint64_t transfer_id) {
        (void)transfer_id;
    }

683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
Q_SIGNALS: // SIGNALS
   void volumeChanged(const QString& device, double value);
   void accountsChanged();
   void historyChanged();
   void stunStatusFailure(const QString& reason);
   void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str);
   void stunStatusSuccess(const QString& message);
   void errorAlert(int code);
   void volatileAccountDetailsChanged(const QString& accountId, MapStringString details);
   void certificatePinned(const QString& certId);
   void certificatePathPinned(const QString& path, const QStringList& certIds);
   void certificateExpired(const QString& certId);
   void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status);
   void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp);
   void knownDevicesChanged(const QString& accountId, const MapStringString& devices);
   void exportOnRingEnded(const QString& accountId, int status, const QString& pin);
   void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads);
   void mediaParametersChanged(const QString& accountId);
   void audioDeviceEvent();
   void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status);
   void nameRegistrationEnded(const QString& accountId, int status, const QString& name);
704
   void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel
705 706 707
   void migrationEnded(const QString &accountId, const QString &result);
   void contactAdded(const QString &accountId, const QString &uri, bool banned);
   void contactRemoved(const QString &accountId, const QString &uri, bool banned);
Guillaume Roguez's avatar
Guillaume Roguez committed
708
   void dataTransferEvent(uint64_t transfer_id, uint32_t code);
709 710 711 712 713 714 715 716 717
};

namespace org {
   namespace ring {
      namespace Ring {
         typedef ::ConfigurationManagerInterface ConfigurationManager;
      }
   }
}