lrc.cpp 4.21 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.                             *
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
34
#include "database.h"
#include "dbus/callmanager.h"
35
#include "dbus/configurationmanager.h"
36
#include "dbus/instancemanager.h"
Nicolas Jager's avatar
Nicolas Jager committed
37
38
39
40
41
42
43
44
45
46

namespace lrc
{

using namespace api;

class LrcPimpl
{

public:
Anthony Léonard's avatar
Anthony Léonard committed
47
    LrcPimpl(Lrc& linked);
Nicolas Jager's avatar
Nicolas Jager committed
48

Nicolas Jager's avatar
Nicolas Jager committed
49
    const Lrc& linked;
50
    std::unique_ptr<BehaviorController> behaviorController;
Nicolas Jager's avatar
Nicolas Jager committed
51
    std::unique_ptr<CallbacksHandler> callbackHandler;
52
    std::unique_ptr<Database> database;
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_;
Nicolas Jager's avatar
Nicolas Jager committed
56
57
58
59
};

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

Lrc::~Lrc()
{
68
69
70
71
72
73
    //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
74
75
}

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

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

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

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

100
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
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
}

126
127
128
129
130
131
132
133
134
135
136
137
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;
}

Anthony Léonard's avatar
Anthony Léonard committed
138
LrcPimpl::LrcPimpl(Lrc& linked)
Nicolas Jager's avatar
Nicolas Jager committed
139
: linked(linked)
140
, behaviorController(std::make_unique<BehaviorController>())
141
, callbackHandler(std::make_unique<CallbacksHandler>(linked))
Nicolas Jager's avatar
Nicolas Jager committed
142
, database(std::make_unique<Database>())
Anthony Léonard's avatar
Anthony Léonard committed
143
144
, accountModel(std::make_unique<NewAccountModel>(linked, *database, *callbackHandler, *behaviorController))
, dataTransferModel {std::make_unique<DataTransferModel>()}
Sébastien Blin's avatar
Sébastien Blin committed
145
, AVModel_ {std::make_unique<AVModel>(*callbackHandler)}
Nicolas Jager's avatar
Nicolas Jager committed
146
147
148
{
}

149
} // namespace lrc