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
1=== added file 'include/messaging/qt/network_monitor.h'
2--- include/messaging/qt/network_monitor.h 1970-01-01 00:00:00 +0000
3+++ include/messaging/qt/network_monitor.h 2016-07-18 11:43:17 +0000
4@@ -0,0 +1,71 @@
5+/*
6+ * Copyright 2014-2016 Canonical Ltd.
7+ *
8+ * This file and its implementation is adaptation of sync-monitor.
9+ *
10+ * This software is free software; you can redistribute it and/or modify
11+ * it under the terms of the GNU General Public License as published by
12+ * the Free Software Foundation; version 3.
13+ *
14+ * This software is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ */
22+
23+#ifndef MESSAGING_QT_NETWORK_MONITOR
24+#define MESSAGING_QT_NETWORK_MONITOR
25+
26+#include <QtNetwork/QNetworkConfigurationManager>
27+#include <QTimer>
28+
29+#include <memory>
30+
31+namespace messaging
32+{
33+
34+//Handy fw declaration
35+class Connection;
36+
37+namespace qt
38+{
39+
40+class NetworkMonitor : public QObject
41+{
42+ Q_OBJECT
43+public:
44+ enum NetworkState {
45+ NetworkOffline = 0,
46+ NetworkPartialOnline,
47+ NetworkOnline
48+ };
49+ NetworkMonitor(const std::weak_ptr<Connection> &connection, QObject *parent=0);
50+ virtual ~NetworkMonitor();
51+
52+ void stop_monitoring();
53+ void set_connection_ready(bool ready);
54+
55+private Q_SLOTS:
56+ void refresh();
57+ void idle_refresh();
58+
59+private:
60+ QNetworkConfigurationManager network_config_manager_;
61+ QTimer refresh_timer_;
62+ std::weak_ptr<Connection> connection_;
63+ std::string current_ssid_;
64+ bool is_connection_ready_;
65+
66+
67+ void start_monitoring();
68+ void dump(const QNetworkConfiguration &config);
69+};
70+
71+}
72+}
73+
74+#endif // MESSAGING_QT_NETWORK_MONITOR
75+
76
77=== modified file 'include/messaging/qt/tp/connection.h'
78--- include/messaging/qt/tp/connection.h 2016-06-07 18:15:24 +0000
79+++ include/messaging/qt/tp/connection.h 2016-07-18 11:43:17 +0000
80@@ -23,6 +23,7 @@
81 #include <messaging/group_starter.h>
82
83 #include <messaging/qt/variant_map_facade.h>
84+#include <messaging/qt/network_monitor.h>
85
86 #include <TelepathyQt/BaseChannel>
87 #include <TelepathyQt/BaseConnection>
88@@ -40,6 +41,7 @@
89 {
90 // A handy fwd declaration
91 class Runtime;
92+class NetworkMonitor;
93
94 namespace tp
95 {
96@@ -178,6 +180,8 @@
97 Tp::BaseConnectionContactsInterfacePtr contacts;
98 Tp::BaseConnectionSimplePresenceInterfacePtr simplePresenceIface;
99 QString connection_id;
100+
101+ NetworkMonitor network_monitor_;
102 };
103 }
104 }
105
106=== modified file 'src/CMakeLists.txt'
107--- src/CMakeLists.txt 2016-07-04 15:53:42 +0000
108+++ src/CMakeLists.txt 2016-07-18 11:43:17 +0000
109@@ -1,7 +1,8 @@
110 # Expose internal headers under sensible paths to the impl.
111 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/messaging ${PROCESS_CPP_INCLUDE_DIRS} ${LibPhoneNumber_INCLUDE_DIRS})
112
113-qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h
114+qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/network_monitor.h
115+ ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h
116 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/connection.h
117 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable.h
118 ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h)
119@@ -33,6 +34,7 @@
120 messaging/user.cpp
121 messaging/utils.cpp
122
123+ messaging/qt/network_monitor.cpp
124 messaging/qt/runtime.cpp
125 messaging/qt/variant.cpp
126 messaging/qt/variant_map_facade.cpp
127
128=== modified file 'src/messaging/connection.cpp'
129--- src/messaging/connection.cpp 2016-03-30 19:19:19 +0000
130+++ src/messaging/connection.cpp 2016-07-18 11:43:17 +0000
131@@ -16,6 +16,8 @@
132
133 #include <messaging/connection.h>
134
135+#include <messaging/qt/network_monitor.h>
136+
137 struct messaging::Connection::Private
138 {
139 std::shared_ptr<messaging::Connection::Observer> observer;
140
141=== added file 'src/messaging/qt/network_monitor.cpp'
142--- src/messaging/qt/network_monitor.cpp 1970-01-01 00:00:00 +0000
143+++ src/messaging/qt/network_monitor.cpp 2016-07-18 11:43:17 +0000
144@@ -0,0 +1,139 @@
145+#include <messaging/qt/network_monitor.h>
146+
147+#include <messaging/connection.h>
148+
149+#include <QtNetwork/QNetworkConfigurationManager>
150+
151+#include <glog/logging.h>
152+
153+namespace mq = messaging::qt;
154+
155+mq::NetworkMonitor::NetworkMonitor(const std::weak_ptr<Connection> &connection, QObject *parent)
156+ : QObject(parent)
157+ , network_config_manager_{this}
158+ , connection_{connection}
159+ , current_ssid_{}
160+ , is_connection_ready_{false}
161+{
162+ start_monitoring();
163+}
164+
165+mq::NetworkMonitor::~NetworkMonitor()
166+{
167+}
168+
169+/*!
170+ * \brief starts monitoring current connection. The monitoring will restart in case a new
171+ * connection is created but this one won't be monitored anymore
172+ */
173+void mq::NetworkMonitor::start_monitoring()
174+{
175+ connect(&network_config_manager_,
176+ SIGNAL(onlineStateChanged(bool)),
177+ SLOT(refresh()), Qt::QueuedConnection);
178+ connect(&network_config_manager_,
179+ SIGNAL(configurationAdded(QNetworkConfiguration)),
180+ SLOT(refresh()), Qt::QueuedConnection);
181+ connect(&network_config_manager_,
182+ SIGNAL(configurationChanged(QNetworkConfiguration)),
183+ SLOT(refresh()), Qt::QueuedConnection);
184+ connect(&network_config_manager_,
185+ SIGNAL(configurationRemoved(QNetworkConfiguration)),
186+ SLOT(refresh()), Qt::QueuedConnection);
187+ connect(&network_config_manager_,
188+ SIGNAL(updateCompleted()),
189+ SLOT(refresh()), Qt::QueuedConnection);
190+
191+ refresh_timer_.setSingleShot(true);
192+ connect(&refresh_timer_,
193+ SIGNAL(timeout()),
194+ SLOT(idle_refresh()));
195+}
196+
197+/*!
198+ * \brief stops monitoring network switch in this connection
199+ */
200+void mq::NetworkMonitor::stop_monitoring()
201+{
202+ disconnect(&network_config_manager_,
203+ SIGNAL(onlineStateChanged(bool)),
204+ this,
205+ SLOT(refresh()));
206+ disconnect(&network_config_manager_,
207+ SIGNAL(configurationAdded(QNetworkConfiguration)),
208+ this,
209+ SLOT(refresh()));
210+ disconnect(&network_config_manager_,
211+ SIGNAL(configurationChanged(QNetworkConfiguration)),
212+ this,
213+ SLOT(refresh()));
214+ disconnect(&network_config_manager_,
215+ SIGNAL(configurationRemoved(QNetworkConfiguration)),
216+ this,
217+ SLOT(refresh()));
218+ disconnect(&network_config_manager_,
219+ SIGNAL(updateCompleted()),
220+ this,
221+ SLOT(refresh()));
222+}
223+
224+/*!
225+ * \brief flag needed to know when the connection object has become effectively online.
226+ * This is needed to determinate if a received ssid different from the previous one should be taken
227+ * as the trigger
228+ */
229+void mq::NetworkMonitor::set_connection_ready(bool ready)
230+{
231+ is_connection_ready_ = ready;
232+}
233+
234+void mq::NetworkMonitor::refresh()
235+{
236+ refresh_timer_.start(3000);
237+}
238+
239+void mq::NetworkMonitor::idle_refresh()
240+{
241+ // Check if is online
242+ QList<QNetworkConfiguration> active_configs = network_config_manager_.allConfigurations(QNetworkConfiguration::Active);
243+ bool is_online = active_configs.size() > 0;
244+ if (is_online) {
245+ // Check if the connection is wifi or ethernet
246+ QNetworkConfiguration default_config = network_config_manager_.defaultConfiguration();
247+
248+ // while connecting, we admit updating over an empty current_ssid. In the case
249+ // of being effectively connected, that means a network switch
250+ if (not is_connection_ready_)
251+ {
252+ if (current_ssid_.empty())
253+ {
254+ dump(default_config);
255+ current_ssid_ = default_config.name().toStdString();
256+ }
257+ }
258+
259+ if (current_ssid_ != default_config.name().toStdString())
260+ {
261+ // network is switched at this point, so desconnect the registered connection in case is valid.
262+ LOG(INFO) << "detected network switch";
263+ auto sp = connection_.lock();
264+ if (sp)
265+ {
266+ sp->disconnect();
267+ stop_monitoring();
268+ }
269+ }
270+
271+ } else {
272+ LOG(INFO) << "Network is offline";
273+ }
274+}
275+
276+void mq::NetworkMonitor::dump(const QNetworkConfiguration &config)
277+{
278+ LOG(INFO) << "New network connection:\nType: " << config.bearerTypeName().toStdString()
279+ << "\nId: " << config.identifier().toStdString()
280+ << "\nName: " << config.name().toStdString()
281+ << "\nIsValid: " << config.isValid()
282+ << "\nRoamingAvailable: " << config.isRoamingAvailable();
283+}
284
285=== modified file 'src/messaging/qt/tp/connection.cpp'
286--- src/messaging/qt/tp/connection.cpp 2016-07-14 10:34:45 +0000
287+++ src/messaging/qt/tp/connection.cpp 2016-07-18 11:43:17 +0000
288@@ -145,6 +145,7 @@
289 , connector{connector}
290 , observer{std::make_shared<mqt::tp::Connection::Observer>(runtime, Tp::SharedPtr<mqt::tp::Connection>{this})}
291 , connection{connector->request_connection(observer, observer, observer, mqt::VariantMapFacade{parameters})}
292+ , network_monitor_{connection}
293 {
294 qRegisterMetaType<messaging::Recipient::shared_ptr>();
295
296@@ -243,6 +244,7 @@
297 try
298 {
299 connection->disconnect();
300+ network_monitor_.stop_monitoring();
301 }
302 catch (...)
303 {
304@@ -303,6 +305,8 @@
305
306 presence.status = QLatin1String("available");
307 presence.type = Tp::ConnectionPresenceTypeAvailable;
308+
309+ network_monitor_.set_connection_ready(true);
310 }
311 else
312 {

Subscribers

People subscribed via source and target branches

to all changes: