-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIdleSession.cpp
More file actions
57 lines (43 loc) · 1.69 KB
/
IdleSession.cpp
File metadata and controls
57 lines (43 loc) · 1.69 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the GNU General Public License v3.
* See gpl-3.0.txt for more information.
*/
#include "IdleSession.h"
#include <iostream>
#include <boost/bind.hpp>
using namespace Swift;
IdleSession::IdleSession(AccountDataProvider* accountDataProvider, Swift::NetworkFactories* networkFactories, Swift::CertificateTrustChecker* trustChecker, bool noCompression, bool noTLS, const Swift::URL& boshURL) : noCompression(noCompression), noTLS(noTLS), boshURL(boshURL) {
AccountDataProvider::Account account = accountDataProvider->getAccount();
client = new CoreClient(Swift::JID(account.jid), createSafeByteArray(account.password), networkFactories);
client->setCertificateTrustChecker(trustChecker);
client->onConnected.connect(boost::bind(&IdleSession::handleConnected, this));
client->onDisconnected.connect(boost::bind(&IdleSession::handleDisconnected, this, _1));
}
IdleSession::~IdleSession() {
}
void IdleSession::start() {
ClientOptions options;
options.allowPLAINWithoutTLS = true;
options.useStreamCompression = !noCompression;
options.useAcks = false;
options.useTLS = noTLS ? ClientOptions::NeverUseTLS : ClientOptions::UseTLSWhenAvailable;
options.boshURL = boshURL;
client->connect(options);
}
void IdleSession::stop() {
client->disconnect();
}
void IdleSession::benchmark(const boost::posix_time::ptime& now) {
// no op; we're idle here
onDoneBenchmarking();
}
void IdleSession::handleConnected() {
onReadyToBenchmark();
}
void IdleSession::handleDisconnected(const boost::optional<ClientError>& error) {
if (error) {
std::cout << "Idle session disconnected with error ( " << error.get().getType() << " )!" << std::endl;
}
onStopped();
}