SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
SWGAudioDevices.cpp
Go to the documentation of this file.
1 
14 #include "SWGAudioDevices.h"
15 
16 #include "SWGHelpers.h"
17 
18 #include <QJsonDocument>
19 #include <QJsonArray>
20 #include <QObject>
21 #include <QDebug>
22 
23 namespace SWGSDRangel {
24 
26  init();
27  this->fromJson(*json);
28 }
29 
31  nb_input_devices = 0;
33  input_devices = nullptr;
34  m_input_devices_isSet = false;
37  output_devices = nullptr;
38  m_output_devices_isSet = false;
39 }
40 
42  this->cleanup();
43 }
44 
45 void
47  nb_input_devices = 0;
49  input_devices = new QList<SWGAudioInputDevice*>();
50  m_input_devices_isSet = false;
53  output_devices = new QList<SWGAudioOutputDevice*>();
54  m_output_devices_isSet = false;
55 }
56 
57 void
59 
60  if(input_devices != nullptr) {
61  auto arr = input_devices;
62  for(auto o: *arr) {
63  delete o;
64  }
65  delete input_devices;
66  }
67 
68  if(output_devices != nullptr) {
69  auto arr = output_devices;
70  for(auto o: *arr) {
71  delete o;
72  }
73  delete output_devices;
74  }
75 }
76 
78 SWGAudioDevices::fromJson(QString &json) {
79  QByteArray array (json.toStdString().c_str());
80  QJsonDocument doc = QJsonDocument::fromJson(array);
81  QJsonObject jsonObject = doc.object();
82  this->fromJsonObject(jsonObject);
83  return this;
84 }
85 
86 void
87 SWGAudioDevices::fromJsonObject(QJsonObject &pJson) {
88  ::SWGSDRangel::setValue(&nb_input_devices, pJson["nbInputDevices"], "qint32", "");
89 
90 
91  ::SWGSDRangel::setValue(&input_devices, pJson["inputDevices"], "QList", "SWGAudioInputDevice");
92  ::SWGSDRangel::setValue(&nb_output_devices, pJson["nbOutputDevices"], "qint32", "");
93 
94 
95  ::SWGSDRangel::setValue(&output_devices, pJson["outputDevices"], "QList", "SWGAudioOutputDevice");
96 }
97 
98 QString
100 {
101  QJsonObject* obj = this->asJsonObject();
102 
103  QJsonDocument doc(*obj);
104  QByteArray bytes = doc.toJson();
105  delete obj;
106  return QString(bytes);
107 }
108 
109 QJsonObject*
111  QJsonObject* obj = new QJsonObject();
113  obj->insert("nbInputDevices", QJsonValue(nb_input_devices));
114  }
115  if(input_devices->size() > 0){
116  toJsonArray((QList<void*>*)input_devices, obj, "inputDevices", "SWGAudioInputDevice");
117  }
119  obj->insert("nbOutputDevices", QJsonValue(nb_output_devices));
120  }
121  if(output_devices->size() > 0){
122  toJsonArray((QList<void*>*)output_devices, obj, "outputDevices", "SWGAudioOutputDevice");
123  }
124 
125  return obj;
126 }
127 
128 qint32
130  return nb_input_devices;
131 }
132 void
134  this->nb_input_devices = nb_input_devices;
135  this->m_nb_input_devices_isSet = true;
136 }
137 
138 QList<SWGAudioInputDevice*>*
140  return input_devices;
141 }
142 void
143 SWGAudioDevices::setInputDevices(QList<SWGAudioInputDevice*>* input_devices) {
144  this->input_devices = input_devices;
145  this->m_input_devices_isSet = true;
146 }
147 
148 qint32
150  return nb_output_devices;
151 }
152 void
154  this->nb_output_devices = nb_output_devices;
155  this->m_nb_output_devices_isSet = true;
156 }
157 
158 QList<SWGAudioOutputDevice*>*
160  return output_devices;
161 }
162 void
163 SWGAudioDevices::setOutputDevices(QList<SWGAudioOutputDevice*>* output_devices) {
164  this->output_devices = output_devices;
165  this->m_output_devices_isSet = true;
166 }
167 
168 
169 bool
171  bool isObjectUpdated = false;
172  do{
173  if(m_nb_input_devices_isSet){ isObjectUpdated = true; break;}
174  if(input_devices->size() > 0){ isObjectUpdated = true; break;}
175  if(m_nb_output_devices_isSet){ isObjectUpdated = true; break;}
176  if(output_devices->size() > 0){ isObjectUpdated = true; break;}
177  }while(false);
178  return isObjectUpdated;
179 }
180 }
181 
QList< SWGAudioOutputDevice * > * output_devices
virtual QString asJson() override
virtual bool isSet() override
virtual QJsonObject * asJsonObject() override
void setNbOutputDevices(qint32 nb_output_devices)
QList< SWGAudioInputDevice * > * getInputDevices()
QList< SWGAudioInputDevice * > * input_devices
virtual void fromJsonObject(QJsonObject &json) override
void setNbInputDevices(qint32 nb_input_devices)
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void toJsonArray(QList< void *> *value, QJsonObject *output, QString innerName, QString innerType)
Definition: SWGHelpers.cpp:445
QList< SWGAudioOutputDevice * > * getOutputDevices()
virtual SWGAudioDevices * fromJson(QString &jsonString) override
void setInputDevices(QList< SWGAudioInputDevice *> *input_devices)
void setOutputDevices(QList< SWGAudioOutputDevice *> *output_devices)