lrc.cpp 4.49 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
/****************************************************************************
2
 *    Copyright (C) 2017-2019 Savoir-faire Linux Inc.                       *
Nicolas Jager's avatar
Nicolas Jager committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *   Author : Nicolas Jäger <nicolas.jager@savoirfairelinux.com>            *
 *   Author : Sébastien Blin <sebastien.blin@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 GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include "api/lrc.h"

21
22
23
24
25
26
#ifndef _MSC_VER
#include <unistd.h>
#else
#include "../../daemon/MSVC/unistd.h"
#endif // !_MSC_VER

Nicolas Jager's avatar
Nicolas Jager committed
27
// Models and database
28
#include "api/avmodel.h"
29
#include "api/behaviorcontroller.h"
30
31
#include "api/datatransfermodel.h"
#include "api/newaccountmodel.h"
Nicolas Jager's avatar
Nicolas Jager committed
32
#include "callbackshandler.h"
33
#include "dbus/callmanager.h"
34
#include "dbus/configurationmanager.h"
35
#include "dbus/instancemanager.h"
36
#include "dbus/configurationmanager.h"
37
#include "authority/storagehelper.h"
Nicolas Jager's avatar
Nicolas Jager committed
38
39
40
41
42
43
44
45
46
47

namespace lrc
{

using namespace api;

class LrcPimpl
{

public:
48
    LrcPimpl(Lrc& linked, MigrationCb& willMigrateCb, MigrationCb& didMigrateCb);
Nicolas Jager's avatar
Nicolas Jager committed
49

Nicolas Jager's avatar
Nicolas Jager committed
50
    const Lrc& linked;
51
    std::unique_ptr<BehaviorController> behaviorController;
Nicolas Jager's avatar
Nicolas Jager committed
52
    std::unique_ptr<CallbacksHandler> callbackHandler;
Nicolas Jager's avatar
Nicolas Jager committed
53
    std::unique_ptr<NewAccountModel> accountModel;
Anthony Léonard's avatar
Anthony Léonard committed
54
    std::unique_ptr<DataTransferModel> dataTransferModel;
55
    std::unique_ptr<AVModel> AVModel_;
56

Nicolas Jager's avatar
Nicolas Jager committed
57
58
};

59
Lrc::Lrc(MigrationCb willDoMigrationCb, MigrationCb didDoMigrationCb)
Nicolas Jager's avatar
Nicolas Jager committed
60
{
61
62
63
    // Ensure Daemon is running/loaded (especially on non-DBus platforms)
    // before instantiating LRC and its members
    InstanceManager::instance();
64
    lrcPimpl_ = std::make_unique<LrcPimpl>(*this, willDoMigrationCb, didDoMigrationCb);
Nicolas Jager's avatar
Nicolas Jager committed
65
66
67
68
}

Lrc::~Lrc()
{
69
70
71
72
73
74
    //Unregister from the daemon
    InstanceManagerInterface& instance = InstanceManager::instance();
    Q_NOREPLY instance.Unregister(getpid());
#ifndef ENABLE_LIBWRAP
    instance.connection().disconnectFromBus(instance.connection().baseService());
#endif //ENABLE_LIBWRAP
Nicolas Jager's avatar
Nicolas Jager committed
75
76
}

77
NewAccountModel&
Nicolas Jager's avatar
Nicolas Jager committed
78
Lrc::getAccountModel() const
Nicolas Jager's avatar
Nicolas Jager committed
79
{
80
    return *lrcPimpl_->accountModel;
Nicolas Jager's avatar
Nicolas Jager committed
81
82
}

83
BehaviorController&
84
85
86
87
88
Lrc::getBehaviorController() const
{
    return *lrcPimpl_->behaviorController;
}

Anthony Léonard's avatar
Anthony Léonard committed
89
90
91
92
93
94
DataTransferModel&
Lrc::getDataTransferModel() const
{
    return *lrcPimpl_->dataTransferModel;
}

95
96
97
98
99
100
AVModel&
Lrc::getAVModel() const
{
    return *lrcPimpl_->AVModel_;
}

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
void
Lrc::connectivityChanged() const
{
    ConfigurationManager::instance().connectivityChanged();
}

bool
Lrc::isConnected()
{
#ifdef ENABLE_LIBWRAP
    return true;
#else
    return ConfigurationManager::instance().connection().isConnected();
#endif
}

bool
Lrc::dbusIsValid()
{
#ifdef ENABLE_LIBWRAP
    return true;
#else
    return ConfigurationManager::instance().isValid();
#endif
}

127
128
129
130
131
132
void
Lrc::subscribeToDebugReceived()
{
    lrcPimpl_->callbackHandler->subscribeToDebugReceived();
}

133
134
135
136
137
138
139
140
141
142
143
144
std::vector<std::string>
Lrc::activeCalls()
{
    QStringList callLists = CallManager::instance().getCallList();
    std::vector<std::string> result;
    result.reserve(callLists.size());
    for (const auto &call : callLists) {
        result.emplace_back(call.toStdString());
    }
    return result;
}

145
LrcPimpl::LrcPimpl(Lrc& linked, MigrationCb& willMigrateCb, MigrationCb& didMigrateCb)
Nicolas Jager's avatar
Nicolas Jager committed
146
: linked(linked)
147
, behaviorController(std::make_unique<BehaviorController>())
148
, callbackHandler(std::make_unique<CallbacksHandler>(linked))
149
, accountModel(std::make_unique<NewAccountModel>(linked, *callbackHandler, *behaviorController, willMigrateCb, didMigrateCb))
Anthony Léonard's avatar
Anthony Léonard committed
150
, dataTransferModel {std::make_unique<DataTransferModel>()}
Sébastien Blin's avatar
Sébastien Blin committed
151
, AVModel_ {std::make_unique<AVModel>(*callbackHandler)}
Nicolas Jager's avatar
Nicolas Jager committed
152
153
154
{
}

155
} // namespace lrc