Commit MetaInfo

Revisionbe98a6a361b0b1bbd37fabbd04edfc3fb6c93870 (tree)
Time2018-10-08 09:45:30
AuthorSergey Gusarov
CommiterSergey Gusarov

Log Message

Remove modems which are not present in the system anymore

Change Summary

Incremental Difference

diff -r 5b166653c6fe -r be98a6a361b0 include/qtmodem/modem_thread.hpp
--- a/include/qtmodem/modem_thread.hpp Mon Oct 08 03:02:44 2018 +0300
+++ b/include/qtmodem/modem_thread.hpp Mon Oct 08 03:45:30 2018 +0300
@@ -10,9 +10,9 @@
1010 #include <ctools/predef/external_headers.h>
1111
1212 CT_BEGIN_EXTERNAL_HEADERS
13-# include <list>
1413 # include <mutex>
1514
15+# include <QList>
1616 # include <QThread>
1717 CT_END_EXTERNAL_HEADERS
1818
@@ -44,6 +44,21 @@
4444
4545 void terminateThread();
4646
47+ bool isPortsAliveInOs() const
48+ {
49+ bool isAlive = true;
50+
51+ for (const auto& serialCommandsController : serialCommandsControllerList)
52+ {
53+ isAlive = isAlive && serialCommandsController->isPortAliveInOs();
54+
55+ if (!isAlive)
56+ break;
57+ }
58+
59+ return isAlive;
60+ }
61+
4762 void getModemInfoFromPorts(ModemInfo& modemInfo)
4863 {
4964 std::lock_guard<std::mutex> lock(accessMutex);
@@ -154,7 +169,7 @@
154169 void slotReadyRead();
155170 };
156171
157-using ModemThreadList = std::list<std::shared_ptr<ModemThread>>;
172+using ModemThreadList = QList<std::shared_ptr<ModemThread>>;
158173
159174 /* *INDENT-OFF* */
160175 } // namespace qtmodem
diff -r 5b166653c6fe -r be98a6a361b0 include/qtmodem/serial_commands_controller.hpp
--- a/include/qtmodem/serial_commands_controller.hpp Mon Oct 08 03:02:44 2018 +0300
+++ b/include/qtmodem/serial_commands_controller.hpp Mon Oct 08 03:45:30 2018 +0300
@@ -34,6 +34,8 @@
3434
3535 virtual ~SerialCommandsController() CT_NOEXCEPT CPT_OVERRIDE;
3636
37+ bool isPortAliveInOs();
38+
3739 virtual void createUnsolicitedController(const enum atmodem::UnsolicitedController::Mode mode, const std::set<atmodem::UnsolicitedCommand> commandSet) CPT_OVERRIDE;
3840
3941 virtual std::string getPortName() CPT_OVERRIDE
diff -r 5b166653c6fe -r be98a6a361b0 src/modem_scaner.cpp
--- a/src/modem_scaner.cpp Mon Oct 08 03:02:44 2018 +0300
+++ b/src/modem_scaner.cpp Mon Oct 08 03:45:30 2018 +0300
@@ -114,9 +114,29 @@
114114 {
115115 // CT_TRACE_DEBUG("%d", QThread::currentThread());
116116
117+ bool changedModemList = false;
118+
119+ int i = 0;
120+
121+ // Removed threads that is not associated with devices
122+ while (i < modemThreadList.size())
123+ {
124+ std::shared_ptr<ModemThread> modemThread = modemThreadList[i];
125+
126+ if (modemThread->isPortsAliveInOs())
127+ {
128+ i++;
129+ }
130+ else
131+ {
132+ changedModemList = true;
133+ modemThread->terminateThread();
134+ modemThreadList.removeAt(i);
135+ }
136+ }
137+
117138 SerialPortInfoList availablePorts = QSerialPortInfo::availablePorts();
118139 ModemInfoList modemInfoList;
119- bool changedModemList = false;
120140
121141 while (availablePorts.count())
122142 {
diff -r 5b166653c6fe -r be98a6a361b0 src/serial_commands_controller.cpp
--- a/src/serial_commands_controller.cpp Mon Oct 08 03:02:44 2018 +0300
+++ b/src/serial_commands_controller.cpp Mon Oct 08 03:45:30 2018 +0300
@@ -11,6 +11,7 @@
1111 # include <QCoreApplication>
1212 CT_END_EXTERNAL_HEADERS
1313
14+#include <ctools/os/io.h>
1415 #include <ctools/trace.h>
1516
1617 #include <cpptools/exceptions/runtime.hpp>
@@ -46,6 +47,11 @@
4647 closeComPort();
4748 }
4849
50+bool SerialCommandsController::isPortAliveInOs()
51+{
52+ return ctools::isFileExists(QTT_LATIN_PRINTABLE(serialPortInfo.systemLocation()));
53+}
54+
4955 void SerialCommandsController::createUnsolicitedController(const enum atmodem::UnsolicitedController::Mode mode, const std::set<atmodem::UnsolicitedCommand> commandSet)
5056 {
5157 CPT_THROW_IF(unsolicitedController.get(), cpptools::exceptions::IllegalStateException,
Show on old repository browser