devicelink.h 2.25 KB
Newer Older
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/**
 * Copyright 2013 Albert Vaca <albertvaka@gmail.com>
 *
 * 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 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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/>.
 */

#ifndef DEVICELINK_H
#define DEVICELINK_H

#include <QObject>
25
#include <QtCrypto>
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
26

Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
27
#include "core/networkpackage.h"
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
28

Albert Vaca Cintora's avatar
WIP  
Albert Vaca Cintora committed
29
class PairingHandler;
30
class NetworkPackage;
31
class LinkProvider;
Albert Vaca Cintora's avatar
WIP  
Albert Vaca Cintora committed
32
class Device;
33

Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
34 35 36 37 38 39
class DeviceLink
    : public QObject
{
    Q_OBJECT

public:
40
    enum PairStatus { NotPaired, Paired };
41

42
    DeviceLink(const QString& deviceId, LinkProvider* parent);
43
    virtual ~DeviceLink() = default;
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
44

45 46
    virtual QString name() = 0;

47 48
    const QString& deviceId() const { return m_deviceId; }
    LinkProvider* provider() { return m_linkProvider; }
49

50 51
    virtual bool sendPackage(NetworkPackage& np) = 0;

Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
52
    //user actions
Albert Vaca Cintora's avatar
WIPx4  
Albert Vaca Cintora committed
53 54
    virtual void userRequestsPair() = 0;
    virtual void userRequestsUnpair() = 0;
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
55

56
    PairStatus pairStatus() const { return m_pairStatus; }
57
    virtual void setPairStatus(PairStatus status);
58

59 60 61
    //The daemon will periodically destroy unpaired links if this returns false
    virtual bool linkShouldBeKeptAlive() { return false; }

62
Q_SIGNALS:
63 64
    void pairingRequest(PairingHandler* handler);
    void pairingRequestExpired(PairingHandler* handler);
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
65
    void pairStatusChanged(DeviceLink::PairStatus status);
66
    void pairingError(const QString& error);
67
    void receivedPackage(const NetworkPackage& np);
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
68

69
protected:
70
    QCA::PrivateKey m_privateKey;
71

72
private:
73 74 75
    const QString m_deviceId;
    LinkProvider* m_linkProvider;
    PairStatus m_pairStatus;
76

Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
77 78
};

79
#endif