LinkManager.h 3.61 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

#ifndef _LINKMANAGER_H_
#define _LINKMANAGER_H_

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

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

40 41
class LinkManagerTest;

42 43 44 45 46 47
/// 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.

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

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

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

65
    /// Sets the flag to suspend the all new connections
66 67 68
    ///     @param reason User visible reason to suspend connections
    void setConnectionsSuspended(QString reason);
    
69
    /// Sets the flag to allow new connections to be made
70
    void setConnectionsAllowed(void) { _connectionsSuspended = false; }
71
    
72 73 74 75 76
    /// 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.
77 78
    void deleteLink(LinkInterface* link);
    
79
    /// Re-connects all existing links
pixhawk's avatar
pixhawk committed
80
    bool connectAll();
81 82
    
    /// Disconnects all existing links
pixhawk's avatar
pixhawk committed
83
    bool disconnectAll();
84 85 86 87 88
    
    /// Connect the specified link
    bool connectLink(LinkInterface* link);
    
    /// Disconnect the specified link
pixhawk's avatar
pixhawk committed
89
    bool disconnectLink(LinkInterface* link);
90
    
pixhawk's avatar
pixhawk committed
91 92
signals:
    void newLink(LinkInterface* link);
93
    void linkDeleted(LinkInterface* link);
94 95 96 97 98 99
    void linkConnected(LinkInterface* link);
    void linkDisconnected(LinkInterface* link);
    
private slots:
    void _linkConnected(void);
    void _linkDisconnected(void);
100 101
    
private:
102
    /// All access to LinkManager is through LinkManager::instance
Don Gagne's avatar
Don Gagne committed
103 104
    LinkManager(QObject* parent = NULL);
    ~LinkManager();
105 106
    
    virtual void _shutdown(void);
Don Gagne's avatar
Don Gagne committed
107

108
    bool _connectionsSuspendedMsg(void);
Don Gagne's avatar
Don Gagne committed
109
    
110 111 112 113 114
    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
pixhawk's avatar
pixhawk committed
115 116
};

117
#endif