Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
55bc70ff
Commit
55bc70ff
authored
Nov 26, 2014
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix LinkManager link removal
parent
ac45d022
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
497 additions
and
46 deletions
+497
-46
LinkInterface.h
src/comm/LinkInterface.h
+5
-0
LinkManager.cc
src/comm/LinkManager.cc
+22
-28
LinkManager.h
src/comm/LinkManager.h
+4
-4
LinkManagerTest.cc
src/qgcunittest/LinkManagerTest.cc
+409
-0
LinkManagerTest.h
src/qgcunittest/LinkManagerTest.h
+56
-0
UASUnitTest.cc
src/qgcunittest/UASUnitTest.cc
+0
-9
CommConfigurationWindow.cc
src/ui/CommConfigurationWindow.cc
+1
-4
QGCMAVLinkLogPlayer.cc
src/ui/QGCMAVLinkLogPlayer.cc
+0
-1
No files found.
src/comm/LinkInterface.h
View file @
55bc70ff
...
...
@@ -138,6 +138,11 @@ public:
{
return
getCurrentDataRate
(
outDataIndex
,
outDataWriteTimes
,
outDataWriteAmounts
);
}
// These are left unimplemented in order to cause linker errors which indicate incorrect usage of
// connect/disconnect on link directly. All connect/disconnect calls should be made through LinkManager.
bool
connect
(
void
);
bool
disconnect
(
void
);
public
slots
:
...
...
src/comm/LinkManager.cc
View file @
55bc70ff
...
...
@@ -92,7 +92,7 @@ void LinkManager::add(LinkInterface* link)
if
(
!
_links
.
contains
(
link
))
{
connect
(
link
,
SIGNAL
(
destroyed
(
QObject
*
)),
this
,
SLOT
(
removeObj
(
QObject
*
)));
connect
(
link
,
SIGNAL
(
destroyed
(
QObject
*
)),
this
,
SLOT
(
_removeLink
(
QObject
*
)));
_links
.
append
(
link
);
_dataMutex
.
unlock
();
emit
newLink
(
link
);
...
...
@@ -174,7 +174,7 @@ bool LinkManager::disconnectAll()
foreach
(
LinkInterface
*
link
,
_links
)
{
Q_ASSERT
(
link
);
if
(
!
link
->
disconnect
(
))
{
if
(
!
disconnectLink
(
link
))
{
allDisconnected
=
false
;
}
}
...
...
@@ -200,39 +200,33 @@ bool LinkManager::disconnectLink(LinkInterface* link)
return
link
->
_disconnect
();
}
void
LinkManager
::
removeObj
(
QObject
*
link
)
void
LinkManager
::
_removeLink
(
QObject
*
obj
)
{
// Be careful of the fact that by the time this signal makes it through the queue
// the link object has already been destructed.
removeLink
((
LinkInterface
*
)
link
);
}
bool
LinkManager
::
removeLink
(
LinkInterface
*
link
)
{
if
(
link
)
Q_ASSERT
(
obj
);
LinkInterface
*
link
=
static_cast
<
LinkInterface
*>
(
obj
);
_dataMutex
.
lock
();
for
(
int
i
=
0
;
i
<
_links
.
size
();
i
++
)
{
_dataMutex
.
lock
();
for
(
int
i
=
0
;
i
<
_links
.
size
();
i
++
)
{
if
(
link
==
_links
.
at
(
i
))
{
_links
.
removeAt
(
i
);
//remove from link list
}
}
// Remove link from protocol map
QList
<
ProtocolInterface
*
>
protocols
=
_protocolLinks
.
keys
(
link
);
foreach
(
ProtocolInterface
*
proto
,
protocols
)
if
(
link
==
_links
.
at
(
i
))
{
_
protocolLinks
.
remove
(
proto
,
link
);
_
links
.
removeAt
(
i
);
//remove from link list
}
_dataMutex
.
unlock
();
// Emit removal of link
emit
linkRemoved
(
link
);
return
true
;
}
return
false
;
// Remove link from protocol map
QList
<
ProtocolInterface
*
>
protocols
=
_protocolLinks
.
keys
(
link
);
foreach
(
ProtocolInterface
*
proto
,
protocols
)
{
_protocolLinks
.
remove
(
proto
,
link
);
}
_dataMutex
.
unlock
();
// Emit removal of link
emit
linkRemoved
(
link
);
}
/**
...
...
src/comm/LinkManager.h
View file @
55bc70ff
...
...
@@ -88,13 +88,11 @@ public:
void
setConnectionsAllowed
(
void
)
{
_connectionsSuspended
=
false
;
}
public
slots
:
/// @brief Adds the link to the LinkManager. No need to remove a link you added. Just delete it and LinkManager will pick up on
/// that and remove the link from the list.
void
add
(
LinkInterface
*
link
);
void
addProtocol
(
LinkInterface
*
link
,
ProtocolInterface
*
protocol
);
void
removeObj
(
QObject
*
obj
);
bool
removeLink
(
LinkInterface
*
link
);
bool
connectAll
();
bool
connectLink
(
LinkInterface
*
link
);
...
...
@@ -111,6 +109,8 @@ private:
static
LinkManager
*
_instance
;
void
_removeLink
(
QObject
*
obj
);
QList
<
LinkInterface
*>
_links
;
QMultiMap
<
ProtocolInterface
*
,
LinkInterface
*>
_protocolLinks
;
QMutex
_dataMutex
;
...
...
src/qgcunittest/LinkManagerTest.cc
0 → 100644
View file @
55bc70ff
This diff is collapsed.
Click to expand it.
src/qgcunittest/LinkManagerTest.h
0 → 100644
View file @
55bc70ff
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef UASUNITTEST_H
#define UASUNITTEST_H
#include <QObject>
#include "LinkManager.h"
/// @file
/// @brief LinkManager Unit Test
///
/// @author Don Gagne <don@thegagnes.com>
class
LinkManagerTest
:
public
QObject
{
Q_OBJECT
public:
LinkManagerTest
(
void
);
private
slots
:
void
initTestCase
(
void
);
void
init
(
void
);
void
cleanup
(
void
);
void
_setUAS_test
(
void
);
void
_minRCChannels_test
(
void
);
void
_fullCalibration_test
(
void
);
};
DECLARE_TEST
(
LinkManagerTest
)
#endif
src/qgcunittest/UASUnitTest.cc
View file @
55bc70ff
...
...
@@ -341,10 +341,7 @@ void UASUnitTest::signalUASLink_test()
QCOMPARE
(
links
.
count
(),
uas
->
getLinks
()
->
count
());
QCOMPARE
(
uas
->
getLinks
()
->
count
(),
2
);
LinkInterface
*
ff99
=
static_cast
<
LinkInterface
*>
(
links
.
at
(
1
));
LinkManager
::
instance
()
->
removeLink
(
ff99
);
delete
link2
;
QCOMPARE
(
LinkManager
::
instance
()
->
getLinks
().
count
(),
1
);
QCOMPARE
(
uas
->
getLinks
()
->
count
(),
1
);
...
...
@@ -359,10 +356,8 @@ void UASUnitTest::signalUASLink_test()
//all the links in LinkManager must be deleted because LinkManager::instance
//is static.
LinkManager
::
instance
()
->
removeLink
(
link3
);
delete
link3
;
QCOMPARE
(
LinkManager
::
instance
()
->
getLinks
().
count
(),
1
);
LinkManager
::
instance
()
->
removeLink
(
link
);
delete
link
;
QCOMPARE
(
LinkManager
::
instance
()
->
getLinks
().
count
(),
0
);
...
...
@@ -405,13 +400,9 @@ void UASUnitTest::signalIdUASLink_test()
QCOMPARE
(
c
->
getName
(),
QString
(
"COM 19"
));
QCOMPARE
(
d
->
getName
(),
QString
(
"COM 20"
));
LinkManager
::
instance
()
->
removeLink
(
myLink4
);
delete
myLink4
;
LinkManager
::
instance
()
->
removeLink
(
myLink3
);
delete
myLink3
;
LinkManager
::
instance
()
->
removeLink
(
myLink2
);
delete
myLink2
;
LinkManager
::
instance
()
->
removeLink
(
myLink
);
delete
myLink
;
QCOMPARE
(
LinkManager
::
instance
()
->
getLinks
().
count
(),
0
);
...
...
src/ui/CommConfigurationWindow.cc
View file @
55bc70ff
...
...
@@ -376,10 +376,7 @@ void CommConfigurationWindow::remove()
action
=
NULL
;
if
(
link
)
{
LinkManager
::
instance
()
->
removeLink
(
link
);
//remove link from LinkManager list
link
->
disconnect
();
//disconnect port, and also calls terminate() to stop the thread
if
(
link
->
isRunning
())
link
->
terminate
();
// terminate() the serial thread just in case it is still running
link
->
wait
();
// wait() until thread is stoped before deleting
LinkManager
::
instance
()
->
disconnectLink
(
link
);
// disconnect connection
link
->
deleteLater
();
}
link
=
NULL
;
...
...
src/ui/QGCMAVLinkLogPlayer.cc
View file @
55bc70ff
...
...
@@ -330,7 +330,6 @@ bool QGCMAVLinkLogPlayer::loadLogFile(const QString& file)
if
(
logLink
)
{
LinkManager
::
instance
()
->
disconnectLink
(
logLink
);
LinkManager
::
instance
()
->
removeLink
(
logLink
);
logLink
->
deleteLater
();
}
logLink
=
new
MAVLinkSimulationLink
(
""
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment