Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / uavobjectutil / uavobjecthelper.h
blob14ecf7df3072be72f4a00096c4fe1f2f865383ca
1 /**
2 ******************************************************************************
4 * @file uavobjecthelper.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup [Group]
7 * @{
8 * @addtogroup UAVObjectHelper
9 * @{
10 * @brief [Brief]
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef UAVOBJECTHELPER_H
29 #define UAVOBJECTHELPER_H
31 #include <QObject>
32 #include <QEventLoop>
33 #include <QMutex>
34 #include <QMutexLocker>
36 #include "uavobjectutil_global.h"
37 #include "uavobject.h"
39 class UAVOBJECTUTIL_EXPORT AbstractUAVObjectHelper : public QObject {
40 Q_OBJECT
41 public:
42 explicit AbstractUAVObjectHelper(QObject *parent = 0);
43 virtual ~AbstractUAVObjectHelper();
45 enum Result { SUCCESS, FAIL, TIMEOUT };
47 // default timeout = 3 x 250ms + 50ms safety margin = 800ms
48 // where 3 is the number of UAVTalk retries and 250ms is the UAVTalk timeout
49 Result doObjectAndWait(UAVObject *object, int timeout = 800);
51 protected:
52 virtual void doObjectAndWaitImpl() = 0;
53 UAVObject *m_object;
55 private slots:
56 void transactionCompleted(UAVObject *object, bool success);
58 private:
59 QMutex m_mutex;
60 QEventLoop m_eventLoop;
61 bool m_transactionResult;
62 bool m_transactionCompleted;
65 class UAVOBJECTUTIL_EXPORT UAVObjectUpdaterHelper : public AbstractUAVObjectHelper {
66 Q_OBJECT
67 public:
68 explicit UAVObjectUpdaterHelper(QObject *parent = 0);
69 virtual ~UAVObjectUpdaterHelper();
71 protected:
72 virtual void doObjectAndWaitImpl();
75 class UAVOBJECTUTIL_EXPORT UAVObjectRequestHelper : public AbstractUAVObjectHelper {
76 Q_OBJECT
77 public:
78 explicit UAVObjectRequestHelper(QObject *parent = 0);
79 virtual ~UAVObjectRequestHelper();
81 protected:
82 virtual void doObjectAndWaitImpl();
85 #endif // UAVOBJECTHELPER_H