Merge lp:~phablet-team/messaging-framework/detect-network-switch into lp:messaging-framework

Proposed by Roberto Mier Escandon
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 56
Merged at revision: 47
Proposed branch: lp:~phablet-team/messaging-framework/detect-network-switch
Merge into: lp:messaging-framework
Prerequisite: lp:~phablet-team/messaging-framework/avoid-removing-tp-connection-after-disconnect
Diff against target: 312 lines (+223/-1)
6 files modified
include/messaging/qt/network_monitor.h (+71/-0)
include/messaging/qt/tp/connection.h (+4/-0)
src/CMakeLists.txt (+3/-1)
src/messaging/connection.cpp (+2/-0)
src/messaging/qt/network_monitor.cpp (+139/-0)
src/messaging/qt/tp/connection.cpp (+4/-0)
To merge this branch: bzr merge lp:~phablet-team/messaging-framework/detect-network-switch
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Approve
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+300164@code.launchpad.net

This proposal supersedes a proposal from 2016-07-15.

Commit message

Reconnects on network switching

NOTE: the time it takes login in the new network depends on the attached plugin. In some cases you have to be patient ;)

Description of the change

Reconnects on network switching

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote : Posted in a previous version of this proposal

PASSED: Continuous integration, rev:52
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/19/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/980
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/181
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/980
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=vivid+overlay/882
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=xenial+overlay/882
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=yakkety/882
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/879/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/879
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/879/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/19/rebuild

review: Approve (continuous-integration)
53. By Roberto Mier Escandon

using ssid to detect network switch

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:52
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/20/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/981
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/182
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/981
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=vivid+overlay/883
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=xenial+overlay/883
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=yakkety/883
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/880/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/880
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/880/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/20/rebuild

review: Approve (continuous-integration)
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:53
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/21/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/982
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/183
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/982
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=vivid+overlay/884
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=xenial+overlay/884
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=yakkety/884
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/881/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/881
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/881/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/21/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Some things to look at.

review: Needs Fixing
54. By Roberto Mier Escandon

updated copyright for network-monitor class!

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:54
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/22/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/988
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/186
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/988
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=vivid+overlay/890
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=xenial+overlay/890
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=yakkety/890
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/887/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/887
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/887/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/22/rebuild

review: Approve (continuous-integration)
55. By Roberto Mier Escandon

merged trunk

56. By Roberto Mier Escandon

avoid using threads when evaluating network state

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:56
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/23/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/991
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/187
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/991
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=vivid+overlay/893
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=xenial+overlay/893
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-1-sourcepkg/release=yakkety/893
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/888/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/888
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/888/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-messaging-framework-ci/23/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good now.

review: Approve
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'include/messaging/qt/network_monitor.h'
--- include/messaging/qt/network_monitor.h 1970-01-01 00:00:00 +0000
+++ include/messaging/qt/network_monitor.h 2016-07-18 11:43:17 +0000
@@ -0,0 +1,71 @@
1/*
2 * Copyright 2014-2016 Canonical Ltd.
3 *
4 * This file and its implementation is adaptation of sync-monitor.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef MESSAGING_QT_NETWORK_MONITOR
20#define MESSAGING_QT_NETWORK_MONITOR
21
22#include <QtNetwork/QNetworkConfigurationManager>
23#include <QTimer>
24
25#include <memory>
26
27namespace messaging
28{
29
30//Handy fw declaration
31class Connection;
32
33namespace qt
34{
35
36class NetworkMonitor : public QObject
37{
38 Q_OBJECT
39public:
40 enum NetworkState {
41 NetworkOffline = 0,
42 NetworkPartialOnline,
43 NetworkOnline
44 };
45 NetworkMonitor(const std::weak_ptr<Connection> &connection, QObject *parent=0);
46 virtual ~NetworkMonitor();
47
48 void stop_monitoring();
49 void set_connection_ready(bool ready);
50
51private Q_SLOTS:
52 void refresh();
53 void idle_refresh();
54
55private:
56 QNetworkConfigurationManager network_config_manager_;
57 QTimer refresh_timer_;
58 std::weak_ptr<Connection> connection_;
59 std::string current_ssid_;
60 bool is_connection_ready_;
61
62
63 void start_monitoring();
64 void dump(const QNetworkConfiguration &config);
65};
66
67}
68}
69
70#endif // MESSAGING_QT_NETWORK_MONITOR
71
072
=== modified file 'include/messaging/qt/tp/connection.h'
--- include/messaging/qt/tp/connection.h 2016-06-07 18:15:24 +0000
+++ include/messaging/qt/tp/connection.h 2016-07-18 11:43:17 +0000
@@ -23,6 +23,7 @@
23#include <messaging/group_starter.h>23#include <messaging/group_starter.h>
2424
25#include <messaging/qt/variant_map_facade.h>25#include <messaging/qt/variant_map_facade.h>
26#include <messaging/qt/network_monitor.h>
2627
27#include <TelepathyQt/BaseChannel>28#include <TelepathyQt/BaseChannel>
28#include <TelepathyQt/BaseConnection>29#include <TelepathyQt/BaseConnection>
@@ -40,6 +41,7 @@
40{41{
41// A handy fwd declaration42// A handy fwd declaration
42class Runtime;43class Runtime;
44class NetworkMonitor;
4345
44namespace tp46namespace tp
45{47{
@@ -178,6 +180,8 @@
178 Tp::BaseConnectionContactsInterfacePtr contacts;180 Tp::BaseConnectionContactsInterfacePtr contacts;
179 Tp::BaseConnectionSimplePresenceInterfacePtr simplePresenceIface;181 Tp::BaseConnectionSimplePresenceInterfacePtr simplePresenceIface;
180 QString connection_id;182 QString connection_id;
183
184 NetworkMonitor network_monitor_;
181};185};
182}186}
183}187}
184188
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2016-07-04 15:53:42 +0000
+++ src/CMakeLists.txt 2016-07-18 11:43:17 +0000
@@ -1,7 +1,8 @@
1# Expose internal headers under sensible paths to the impl.1# Expose internal headers under sensible paths to the impl.
2include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/messaging ${PROCESS_CPP_INCLUDE_DIRS} ${LibPhoneNumber_INCLUDE_DIRS})2include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/messaging ${PROCESS_CPP_INCLUDE_DIRS} ${LibPhoneNumber_INCLUDE_DIRS})
33
4qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h4qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/network_monitor.h
5 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h
5 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/connection.h6 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/connection.h
6 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable.h7 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable.h
7 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h)8 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h)
@@ -33,6 +34,7 @@
33 messaging/user.cpp34 messaging/user.cpp
34 messaging/utils.cpp35 messaging/utils.cpp
3536
37 messaging/qt/network_monitor.cpp
36 messaging/qt/runtime.cpp38 messaging/qt/runtime.cpp
37 messaging/qt/variant.cpp39 messaging/qt/variant.cpp
38 messaging/qt/variant_map_facade.cpp40 messaging/qt/variant_map_facade.cpp
3941
=== modified file 'src/messaging/connection.cpp'
--- src/messaging/connection.cpp 2016-03-30 19:19:19 +0000
+++ src/messaging/connection.cpp 2016-07-18 11:43:17 +0000
@@ -16,6 +16,8 @@
1616
17#include <messaging/connection.h>17#include <messaging/connection.h>
1818
19#include <messaging/qt/network_monitor.h>
20
19struct messaging::Connection::Private21struct messaging::Connection::Private
20{22{
21 std::shared_ptr<messaging::Connection::Observer> observer;23 std::shared_ptr<messaging::Connection::Observer> observer;
2224
=== added file 'src/messaging/qt/network_monitor.cpp'
--- src/messaging/qt/network_monitor.cpp 1970-01-01 00:00:00 +0000
+++ src/messaging/qt/network_monitor.cpp 2016-07-18 11:43:17 +0000
@@ -0,0 +1,139 @@
1#include <messaging/qt/network_monitor.h>
2
3#include <messaging/connection.h>
4
5#include <QtNetwork/QNetworkConfigurationManager>
6
7#include <glog/logging.h>
8
9namespace mq = messaging::qt;
10
11mq::NetworkMonitor::NetworkMonitor(const std::weak_ptr<Connection> &connection, QObject *parent)
12 : QObject(parent)
13 , network_config_manager_{this}
14 , connection_{connection}
15 , current_ssid_{}
16 , is_connection_ready_{false}
17{
18 start_monitoring();
19}
20
21mq::NetworkMonitor::~NetworkMonitor()
22{
23}
24
25/*!
26 * \brief starts monitoring current connection. The monitoring will restart in case a new
27 * connection is created but this one won't be monitored anymore
28 */
29void mq::NetworkMonitor::start_monitoring()
30{
31 connect(&network_config_manager_,
32 SIGNAL(onlineStateChanged(bool)),
33 SLOT(refresh()), Qt::QueuedConnection);
34 connect(&network_config_manager_,
35 SIGNAL(configurationAdded(QNetworkConfiguration)),
36 SLOT(refresh()), Qt::QueuedConnection);
37 connect(&network_config_manager_,
38 SIGNAL(configurationChanged(QNetworkConfiguration)),
39 SLOT(refresh()), Qt::QueuedConnection);
40 connect(&network_config_manager_,
41 SIGNAL(configurationRemoved(QNetworkConfiguration)),
42 SLOT(refresh()), Qt::QueuedConnection);
43 connect(&network_config_manager_,
44 SIGNAL(updateCompleted()),
45 SLOT(refresh()), Qt::QueuedConnection);
46
47 refresh_timer_.setSingleShot(true);
48 connect(&refresh_timer_,
49 SIGNAL(timeout()),
50 SLOT(idle_refresh()));
51}
52
53/*!
54 * \brief stops monitoring network switch in this connection
55 */
56void mq::NetworkMonitor::stop_monitoring()
57{
58 disconnect(&network_config_manager_,
59 SIGNAL(onlineStateChanged(bool)),
60 this,
61 SLOT(refresh()));
62 disconnect(&network_config_manager_,
63 SIGNAL(configurationAdded(QNetworkConfiguration)),
64 this,
65 SLOT(refresh()));
66 disconnect(&network_config_manager_,
67 SIGNAL(configurationChanged(QNetworkConfiguration)),
68 this,
69 SLOT(refresh()));
70 disconnect(&network_config_manager_,
71 SIGNAL(configurationRemoved(QNetworkConfiguration)),
72 this,
73 SLOT(refresh()));
74 disconnect(&network_config_manager_,
75 SIGNAL(updateCompleted()),
76 this,
77 SLOT(refresh()));
78}
79
80/*!
81 * \brief flag needed to know when the connection object has become effectively online.
82 * This is needed to determinate if a received ssid different from the previous one should be taken
83 * as the trigger
84 */
85void mq::NetworkMonitor::set_connection_ready(bool ready)
86{
87 is_connection_ready_ = ready;
88}
89
90void mq::NetworkMonitor::refresh()
91{
92 refresh_timer_.start(3000);
93}
94
95void mq::NetworkMonitor::idle_refresh()
96{
97 // Check if is online
98 QList<QNetworkConfiguration> active_configs = network_config_manager_.allConfigurations(QNetworkConfiguration::Active);
99 bool is_online = active_configs.size() > 0;
100 if (is_online) {
101 // Check if the connection is wifi or ethernet
102 QNetworkConfiguration default_config = network_config_manager_.defaultConfiguration();
103
104 // while connecting, we admit updating over an empty current_ssid. In the case
105 // of being effectively connected, that means a network switch
106 if (not is_connection_ready_)
107 {
108 if (current_ssid_.empty())
109 {
110 dump(default_config);
111 current_ssid_ = default_config.name().toStdString();
112 }
113 }
114
115 if (current_ssid_ != default_config.name().toStdString())
116 {
117 // network is switched at this point, so desconnect the registered connection in case is valid.
118 LOG(INFO) << "detected network switch";
119 auto sp = connection_.lock();
120 if (sp)
121 {
122 sp->disconnect();
123 stop_monitoring();
124 }
125 }
126
127 } else {
128 LOG(INFO) << "Network is offline";
129 }
130}
131
132void mq::NetworkMonitor::dump(const QNetworkConfiguration &config)
133{
134 LOG(INFO) << "New network connection:\nType: " << config.bearerTypeName().toStdString()
135 << "\nId: " << config.identifier().toStdString()
136 << "\nName: " << config.name().toStdString()
137 << "\nIsValid: " << config.isValid()
138 << "\nRoamingAvailable: " << config.isRoamingAvailable();
139}
0140
=== modified file 'src/messaging/qt/tp/connection.cpp'
--- src/messaging/qt/tp/connection.cpp 2016-07-14 10:34:45 +0000
+++ src/messaging/qt/tp/connection.cpp 2016-07-18 11:43:17 +0000
@@ -145,6 +145,7 @@
145 , connector{connector}145 , connector{connector}
146 , observer{std::make_shared<mqt::tp::Connection::Observer>(runtime, Tp::SharedPtr<mqt::tp::Connection>{this})}146 , observer{std::make_shared<mqt::tp::Connection::Observer>(runtime, Tp::SharedPtr<mqt::tp::Connection>{this})}
147 , connection{connector->request_connection(observer, observer, observer, mqt::VariantMapFacade{parameters})}147 , connection{connector->request_connection(observer, observer, observer, mqt::VariantMapFacade{parameters})}
148 , network_monitor_{connection}
148{149{
149 qRegisterMetaType<messaging::Recipient::shared_ptr>();150 qRegisterMetaType<messaging::Recipient::shared_ptr>();
150151
@@ -243,6 +244,7 @@
243 try244 try
244 {245 {
245 connection->disconnect();246 connection->disconnect();
247 network_monitor_.stop_monitoring();
246 }248 }
247 catch (...)249 catch (...)
248 {250 {
@@ -303,6 +305,8 @@
303305
304 presence.status = QLatin1String("available");306 presence.status = QLatin1String("available");
305 presence.type = Tp::ConnectionPresenceTypeAvailable;307 presence.type = Tp::ConnectionPresenceTypeAvailable;
308
309 network_monitor_.set_connection_ready(true);
306 }310 }
307 else311 else
308 {312 {

Subscribers

People subscribed via source and target branches

to all changes: