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.
SWGDeviceSet.cpp
Go to the documentation of this file.
1 
14 #include "SWGDeviceSet.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  sampling_device = nullptr;
33  channelcount = 0;
34  m_channelcount_isSet = false;
35  channels = nullptr;
36  m_channels_isSet = false;
37 }
38 
40  this->cleanup();
41 }
42 
43 void
47  channelcount = 0;
48  m_channelcount_isSet = false;
49  channels = new QList<SWGChannel*>();
50  m_channels_isSet = false;
51 }
52 
53 void
55  if(sampling_device != nullptr) {
56  delete sampling_device;
57  }
58 
59  if(channels != nullptr) {
60  auto arr = channels;
61  for(auto o: *arr) {
62  delete o;
63  }
64  delete channels;
65  }
66 }
67 
69 SWGDeviceSet::fromJson(QString &json) {
70  QByteArray array (json.toStdString().c_str());
71  QJsonDocument doc = QJsonDocument::fromJson(array);
72  QJsonObject jsonObject = doc.object();
73  this->fromJsonObject(jsonObject);
74  return this;
75 }
76 
77 void
78 SWGDeviceSet::fromJsonObject(QJsonObject &pJson) {
79  ::SWGSDRangel::setValue(&sampling_device, pJson["samplingDevice"], "SWGSamplingDevice", "SWGSamplingDevice");
80 
81  ::SWGSDRangel::setValue(&channelcount, pJson["channelcount"], "qint32", "");
82 
83 
84  ::SWGSDRangel::setValue(&channels, pJson["channels"], "QList", "SWGChannel");
85 }
86 
87 QString
89 {
90  QJsonObject* obj = this->asJsonObject();
91 
92  QJsonDocument doc(*obj);
93  QByteArray bytes = doc.toJson();
94  delete obj;
95  return QString(bytes);
96 }
97 
98 QJsonObject*
100  QJsonObject* obj = new QJsonObject();
101  if((sampling_device != nullptr) && (sampling_device->isSet())){
102  toJsonValue(QString("samplingDevice"), sampling_device, obj, QString("SWGSamplingDevice"));
103  }
105  obj->insert("channelcount", QJsonValue(channelcount));
106  }
107  if(channels->size() > 0){
108  toJsonArray((QList<void*>*)channels, obj, "channels", "SWGChannel");
109  }
110 
111  return obj;
112 }
113 
116  return sampling_device;
117 }
118 void
120  this->sampling_device = sampling_device;
121  this->m_sampling_device_isSet = true;
122 }
123 
124 qint32
126  return channelcount;
127 }
128 void
130  this->channelcount = channelcount;
131  this->m_channelcount_isSet = true;
132 }
133 
134 QList<SWGChannel*>*
136  return channels;
137 }
138 void
139 SWGDeviceSet::setChannels(QList<SWGChannel*>* channels) {
140  this->channels = channels;
141  this->m_channels_isSet = true;
142 }
143 
144 
145 bool
147  bool isObjectUpdated = false;
148  do{
149  if(sampling_device != nullptr && sampling_device->isSet()){ isObjectUpdated = true; break;}
150  if(m_channelcount_isSet){ isObjectUpdated = true; break;}
151  if(channels->size() > 0){ isObjectUpdated = true; break;}
152  }while(false);
153  return isObjectUpdated;
154 }
155 }
156 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
SWGSamplingDevice * sampling_device
Definition: SWGDeviceSet.h:60
virtual QString asJson() override
virtual SWGDeviceSet * fromJson(QString &jsonString) override
QList< SWGChannel * > * getChannels()
SWGSamplingDevice * getSamplingDevice()
virtual void fromJsonObject(QJsonObject &json) override
virtual QJsonObject * asJsonObject() override
void setChannelcount(qint32 channelcount)
void setSamplingDevice(SWGSamplingDevice *sampling_device)
void setChannels(QList< SWGChannel *> *channels)
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< SWGChannel * > * channels
Definition: SWGDeviceSet.h:66
virtual bool isSet() override