LinkManager.h 3.62 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*=====================================================================
2

pixhawk's avatar
pixhawk committed
3
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
4

pixhawk's avatar
pixhawk committed
5
(c) 2009, 2010 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>
6

pixhawk's avatar
pixhawk committed
7
This file is part of the PIXHAWK project
8

pixhawk's avatar
pixhawk committed
9 10 11 12
    PIXHAWK 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.
13

pixhawk's avatar
pixhawk committed
14 15 16 17
    PIXHAWK 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.
18

pixhawk's avatar
pixhawk committed
19 20
    You should have received a copy of the GNU General Public License
    along with PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
21

pixhawk's avatar
pixhawk committed
22
======================================================================*/
23

24 25
/// @file
///     @author Lorenz Meier <mavteam@student.ethz.ch>
pixhawk's avatar
pixhawk committed
26 27 28 29 30 31

#ifndef _LINKMANAGER_H_
#define _LINKMANAGER_H_

#include <QThread>
#include <QList>
32
#include <QMultiMap>
33
#include <QMutex>
34 35 36 37 38

#include "LinkInterface.h"
#include "SerialLink.h"
#include "ProtocolInterface.h"
#include "QGCSingleton.h"
39
#include "MAVLinkProtocol.h"
pixhawk's avatar
pixhawk committed
40

41 42
class LinkManagerTest;

43 44 45 46 47 48
/// Manage communication links
///
/// The Link Manager organizes the physical Links. It can manage arbitrary
/// links and takes care of connecting them as well assigning the correct
/// protocol instance to transport the link data into the application.

49
class LinkManager : public QGCSingleton
50
{
pixhawk's avatar
pixhawk committed
51
    Q_OBJECT
52
    
Don Gagne's avatar
Don Gagne committed
53 54 55 56 57 58
    DECLARE_QGC_SINGLETON(LinkManager, LinkManager)
    
    /// Unit Test has access to private constructor/destructor
    friend class LinkManagerTest;
    
public:
pixhawk's avatar
pixhawk committed
59

60
    /// Returns list of all links
pixhawk's avatar
pixhawk committed
61 62
    const QList<LinkInterface*> getLinks();

63
    // Returns list of all serial links
64 65
    const QList<SerialLink*> getSerialLinks();

66
    /// Sets the flag to suspend the all new connections
67 68 69
    ///     @param reason User visible reason to suspend connections
    void setConnectionsSuspended(QString reason);
    
70
    /// Sets the flag to allow new connections to be made
71
    void setConnectionsAllowed(void) { _connectionsSuspended = false; }
72
    
73 74 75 76 77
    /// Adds the link to the LinkManager. LinkManager takes ownership of this object. To delete
    /// it, call LinkManager::deleteLink.
    void addLink(LinkInterface* link);
    
    /// Deletes the specified link. Will disconnect if connected.
78 79
    void deleteLink(LinkInterface* link);
    
80
    /// Re-connects all existing links
pixhawk's avatar
pixhawk committed
81
    bool connectAll();
82 83
    
    /// Disconnects all existing links
pixhawk's avatar
pixhawk committed
84
    bool disconnectAll();
85 86 87 88 89
    
    /// Connect the specified link
    bool connectLink(LinkInterface* link);
    
    /// Disconnect the specified link
pixhawk's avatar
pixhawk committed
90
    bool disconnectLink(LinkInterface* link);
91 92 93 94
    
    /// Returns the one mavlink protocol object in the system
    MAVLinkProtocol* mavlink(void) { return _mavlink; }
    
pixhawk's avatar
pixhawk committed
95 96
signals:
    void newLink(LinkInterface* link);
97
    void linkDeleted(LinkInterface* link);
98 99
    
private:
100
    /// All access to LinkManager is through LinkManager::instance
Don Gagne's avatar
Don Gagne committed
101
    LinkManager(QObject* parent = NULL);
102
    
Don Gagne's avatar
Don Gagne committed
103 104
    ~LinkManager();

105
    bool _connectionsSuspendedMsg(void);
Don Gagne's avatar
Don Gagne committed
106
    
107 108 109 110 111
    QList<LinkInterface*>   _links;         ///< List of available links
    QMutex                  _linkListMutex; ///< Mutex for thread safe access to _links list
    
    bool    _connectionsSuspended;          ///< true: all new connections should not be allowed
    QString _connectionsSuspendedReason;    ///< User visible reason for suspension
112
    
113
    MAVLinkProtocol* _mavlink;  ///< The one and only mavlink protocol
pixhawk's avatar
pixhawk committed
114 115
};

116
#endif