Torc  0.1
torcsysteminputs.cpp
Go to the documentation of this file.
1 /* Class TorcSystemInputs
2 *
3 * This file is part of the Torc project.
4 *
5 * Copyright (C) Mark Kendall 2018
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 */
22 
23 // Torc
24 #include "torclogging.h"
25 #include "torccoreutils.h"
26 #include "torcinputs.h"
27 #include "torcsysteminput.h"
28 #include "torcsysteminputs.h"
29 
31 
34  m_inputs()
35 {
36 }
37 
38 void TorcSystemInputs::Create(const QVariantMap &Details)
39 {
40  QWriteLocker locker(&m_handlerLock);
41 
42  QVariantMap::const_iterator i = Details.begin();
43  for ( ; i != Details.end(); ++i)
44  {
45  // network devices can be <sensors> or <outputs>
46  if (i.key() != INPUTS_DIRECTORY)
47  continue;
48 
49  QVariantMap devices = i.value().toMap();
50  QVariantMap::const_iterator j = devices.constBegin();
51  for ( ; j != devices.constEnd(); ++j)
52  {
53  // look for <network>
54  if (j.key() != SYSTEM_INPUTS_STRING)
55  continue;
56 
57  QVariantMap details = j.value().toMap();
58  QVariantMap::const_iterator it = details.constBegin();
59  for ( ; it != details.constEnd(); ++it)
60  {
61  // iterate over known types - currently only 'started'
62  if (it.key() == TorcCoreUtils::EnumToLowerString<TorcInput::Type>(TorcInput::Started))
63  {
64  QVariantMap system = it.value().toMap();
65  QString uniqueid = system.value(QStringLiteral("name")).toString();
66  TorcSystemInput *input = new TorcSystemInput(0, system);
67  m_inputs.insert(uniqueid, input);
68  }
69  }
70  }
71  }
72 }
73 
75 {
76  QWriteLocker locker(&m_handlerLock);
77 
78  QMap<QString,TorcInput*>::const_iterator it = m_inputs.constBegin();
79  for ( ; it != m_inputs.constEnd(); ++it)
80  {
81  it.value()->DownRef();
82  TorcInputs::gInputs->RemoveInput(it.value());
83  }
84  m_inputs.clear();
85 }
static TorcSystemInputs * gSystemInputs
void Create(const QVariantMap &Details) override
#define SYSTEM_INPUTS_STRING
QReadWriteLock m_handlerLock
#define INPUTS_DIRECTORY
Definition: torcinput.h:12
void Destroy(void) override