dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
boardmanager.cpp
Go to the documentation of this file.
1 
28 /*
29  * This program is free software; you can redistribute it and/or modify
30  * it under the terms of the GNU General Public License as published by
31  * the Free Software Foundation; either version 3 of the License, or
32  * (at your option) any later version.
33  *
34  * This program is distributed in the hope that it will be useful, but
35  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
36  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37  * for more details.
38  *
39  * You should have received a copy of the GNU General Public License along
40  * with this program; if not, see <http://www.gnu.org/licenses/>
41  */
42 
43 #include "boardmanager.h"
44 #include <aggregation/aggregate.h>
46 
47 #include <QDebug>
48 
49 namespace Core {
50 
52 {
53 }
54 
56 {
57 }
58 
60 {
61  // register to the plugin manager so we can receive
62  // new connection object from plugins
63  QObject::connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject *)),
64  this, SLOT(objectAdded(QObject *)));
65  QObject::connect(ExtensionSystem::PluginManager::instance(),
66  SIGNAL(aboutToRemoveObject(QObject *)), this,
67  SLOT(aboutToRemoveObject(QObject *)));
68 }
69 
77 {
78  QSet<int> res;
79  for (const auto board : qAsConst(m_boardTypesList)) {
80  auto vids = board->getVendorIDs();
81  for (const auto vid : vids)
82  res.insert(vid);
83  }
84  return res.toList();
85 }
86 
92 void BoardManager::objectAdded(QObject *obj)
93 {
94  // Check if a plugin added a board type object to the pool
95  IBoardType *board = Aggregation::query<IBoardType>(obj);
96  if (!board)
97  return;
98 
99  // Keep track of the registration
100  m_boardTypesList.append(board);
101 }
102 
107 void BoardManager::aboutToRemoveObject(QObject *obj)
108 {
109  // Check if a plugin removed a board type from the pool
110  IBoardType *board = Aggregation::query<IBoardType>(obj);
111  if (!board)
112  return;
113 
114  if (m_boardTypesList.contains(board))
115  m_boardTypesList.removeAt(m_boardTypesList.indexOf(board));
116 }
117 
119 {
120  foreach (IBoardType *board, m_boardTypesList) {
121  if (board->getBoardType() == type) {
122  return board;
123  }
124  }
125  return nullptr;
126 }
127 
129 {
131  for (const auto board : qAsConst(m_boardTypesList)) {
132  const auto infos = board->firmwareUSBInfo();
133  for (const auto &info : qAsConst(infos))
134  res.append(info);
135  }
136  return res;
137 }
138 
140 {
142  for (const auto board : qAsConst(m_boardTypesList)) {
143  const auto infos = board->bootloaderUSBInfo();
144  for (const auto &info : qAsConst(infos))
145  res.append(info);
146  }
147  return res;
148 }
149 
150 } // Core
virtual ~BoardManager()
QList< IBoardType * > m_boardTypesList
Definition: boardmanager.h:96
QList< int > getKnownVendorIDs()
getKnownVendorIDs Get all USB VendorIDs known by the board manager. This can be used by any plugin wh...
QList< IBoardType::USBInfo > getKnownFirmwareUSBInfo()
getKnownFirmwareUSBInfo
int getBoardType()
Get the board type number.
Definition: iboardtype.h:147
QList< IBoardType::USBInfo > getKnownBootloaderUSBInfo()
getKnownBootloaderUSBInfo
IBoardType * getBoard(int type)
Find a board from it's type.