iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoaderLibrary.H
Go to the documentation of this file.
1 /*! @file
2  @author Unknown
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 #ifndef SRC_APPS_NRTDESIGNER_LOADERLIBRARY_H
35 #define SRC_APPS_NRTDESIGNER_LOADERLIBRARY_H
36 
37 #include "Common.H"
40 #include "ModuleHierarchyModel.H"
41 
43 NRT_BEGIN_UNCHECKED_INCLUDES
44 #include <QTableView>
45 #include <QMutex>
46 #include <QQueue>
47 #include <QPair>
48 NRT_END_UNCHECKED_INCLUDES
49 
50 //! Simple struct that contains essential data about a module loader
52 {
53  QString bbuid;
54  QString bbnick;
55  QColor color;
56 
57  QSharedPointer<ModuleHierarchyModel> modulesModel;
58 
59  bool operator==(LoaderSummary const& other) const
60  {
61  return bbuid == other.bbuid && bbnick == other.bbnick;
62  }
63 };
64 
65 //! Needed to create a QSet<LoaderSummary>
66 uint qHash(LoaderSummary const& l);
67 
68 // ######################################################################
69 //! A library of module loaders
70 class LoaderLibrary : public QAbstractTableModel
71 {
72  Q_OBJECT
73 
74  public:
75  //! Constructor
76  LoaderLibrary(QTableView *view, QWidget *parent = 0);
77 
78  //! Destructor
79  virtual ~LoaderLibrary();
80 
81  //! Get number of loaders
82  int rowCount(QModelIndex const& parent = QModelIndex()) const;
83 
84  //! Get number of columns (stuff about each loader)
85  int columnCount(QModelIndex const& parent = QModelIndex()) const;
86 
87  //! Get some data
88  QVariant data(QModelIndex const & index, int role = Qt::DisplayRole) const;
89 
90  //! Get some header data
91  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
92 
93  //! Delete a bunch of loaders
94  void removeLoaders(QSet<LoaderSummary> loaders);
95 
96  //! Add a loader and all the data about all its possible modules
97  void addLoader(std::string const & bbuid, std::string const & bbnick,
98  std::vector<nrt::ModuleDescription> const & lib);
99 
100  QList<LoaderSummary> const & loaders() const { return itsLoaders; }
101 
102  LoaderSummary currentLoader() const;
103 
104  //! Find a ModuleLoader by the nickname
105  LoaderSummary findByNick(QString nick);
106 
107  //! Find a loader by bbuid
108  LoaderSummary const & findByBBuid(QString const & bbuid) const;
109 
110  //! Get the master loader
111  //! TODO FIX ME! This just returns the current loader for now!
112  LoaderSummary master() const;
113 
114  void updateAllUsagesThread();
115 
116  public slots:
117  void itemSelectedSlot(const QModelIndex & index);
118 
119  signals:
120  void loaderSelectedSignal(LoaderSummary);
121 
122  private:
123  QList<LoaderSummary> itsLoaders;
124  QTableView *itsView;
125 
126  QMap<QString/*bbuid*/, nrt::BlackboardUsageData> itsUsages;
127  QMap<QString/*bbuid*/, QList<QVariant>> itsLoadAvgs;
128  QMap<QString/*bbuid*/, QList<QVariant>> itsFreeRams;
129 
130  QMutex itsMtx;
131  bool itsRunning;
132  std::thread itsUpdateThread;
133 };
134 
135 // ######################################################################
136 class LoadAvgDelegate : public QAbstractItemDelegate
137 {
138  public:
139  LoadAvgDelegate(QObject *parent=0);
140  void paint (QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
141  QSize sizeHint (const QStyleOptionViewItem & option, const QModelIndex & index) const;
142 
143  private:
144  QSize itsSize;
145 };
146 
147 // ######################################################################
148 class MemUsageDelegate : public QAbstractItemDelegate
149 {
150  public:
151  MemUsageDelegate(QObject *parent=0);
152  void paint (QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
153  QSize sizeHint (const QStyleOptionViewItem & option, const QModelIndex & index) const;
154 
155  private:
156  QSize itsSize;
157 };
158 
159 // ######################################################################
160 class LoaderNickDelegate : public QAbstractItemDelegate
161 {
162  public:
163  LoaderNickDelegate(QObject *parent=0);
164  void paint (QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
165  QSize sizeHint (const QStyleOptionViewItem & option, const QModelIndex & index) const;
166 
167  private:
168  QSize itsSize;
169 };
170 
171 #endif // SRC_APPS_NRTDESIGNER_LOADERLIBRARY_H
172