forked from borisRobson/onvif_rtsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml_handler.cpp
More file actions
203 lines (155 loc) · 4.8 KB
/
xml_handler.cpp
File metadata and controls
203 lines (155 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "xml_handler.h"
xml_handler::xml_handler()
{
filepath = "./tcpComms/xmltemplates/";
#ifdef IMX6
if(!createDir())
qDebug() << "could not create temp directory";
#endif
//load defalut values
width = "640";
height = "480";
framerate = "15";
emit updateVidSrcConfig();
create_getDevInfoRes();
create_getScopes();
create_getVidSourcesRes();
create_getDNSRes();
create_getNtwkInterfacesRes();
create_getCapabilitiesRes();
create_getServicesRes();
create_getProfilesRes();
create_getSnapshotRes();
create_getProfileRes();
create_getStreamUriRes();
create_getVideoSourceConfigRes();
}
void xml_handler::create_getVideoSourceConfigRes()
{
QDomDocument doc = loadFile(QString("getVideoSourceConfigurationRes.xml"));
writeFile(doc,"getVideoSourceConfigurationRes.xml" );
}
void xml_handler::create_getStreamUriRes()
{
QDomDocument doc = loadFile(QString("getStreamUriRes.xml"));
QDomDocument getUriRes = xmlcreator.createGetStreamUriRes(doc);
writeFile(getUriRes,"getStreamUriRes.xml" );
}
void xml_handler::create_getProfileRes()
{
QDomDocument doc = loadFile(QString("getProfileRes.xml"));
writeFile(doc,"getProfileRes.xml" );
}
void xml_handler::create_getSnapshotRes()
{
QDomDocument doc = loadFile(QString("getSnapshotRes.xml"));
writeFile(doc,"getSnapshotRes.xml" );
}
void xml_handler::create_getProfilesRes()
{
QDomDocument doc = loadFile(QString("getProfilesRes.xml"));
writeFile(doc,"getProfilesRes.xml" );
}
void xml_handler::create_getServicesRes()
{
QDomDocument doc = loadFile(QString("getServicesRes.xml"));
QDomDocument servicesDoc = xmlcreator.createGetServicesRes(doc);
writeFile(servicesDoc,"getServicesRes.xml" );
}
void xml_handler::create_getCapabilitiesRes()
{
QDomDocument doc = loadFile(QString("getCapabilitiesRes.xml"));
QDomDocument ntwkIntDoc = xmlcreator.createGetCapabilitiesRes(doc);
writeFile(ntwkIntDoc,"getCapabilitiesRes.xml" );
}
void xml_handler::create_getNtwkInterfacesRes()
{
QDomDocument doc = loadFile(QString("getNetworkInterfacesRes.xml"));
QDomDocument ntwkIntDoc = xmlcreator.createGetNetworkInterfacesRes(doc);
writeFile(ntwkIntDoc,"getNetworkInterfacesRes.xml" );
}
void xml_handler::create_getScopes()
{
QDomDocument doc = loadFile(QString("getScopesRes.xml"));
writeFile(doc,"getScopesRes.xml" );
}
void xml_handler::create_getSysDTRes()
{
QDomDocument doc = loadFile(QString("getSysDateTimeRes.xml"));
QDomDocument sysDTDoc = xmlcreator.createGetSysDTRes(doc);
writeFile(sysDTDoc,"getSysDateTimeRes.xml" );
}
void xml_handler::create_getDevInfoRes()
{
QDomDocument doc = loadFile(QString("getDevInfoRes.xml"));
QDomDocument devInfoDoc = xmlcreator.createGetDevInfoRes(doc);
writeFile(devInfoDoc,"getDevInfoRes.xml" );
}
void xml_handler::create_getVidSourcesRes()
{
QDomDocument doc = loadFile(QString("getVideoSourcesRes.xml"));
QDomDocument vidSrcConfigDoc = xmlcreator.createGetVideoSourcesRes(doc, width, height, framerate);
writeFile(vidSrcConfigDoc,"getVideoSourcesRes.xml");
}
void xml_handler::create_getDNSRes()
{
QDomDocument doc = loadFile(QString("getDNSRes.xml"));
QDomDocument devInfoDoc = xmlcreator.createGetDNSRes(doc);
writeFile(devInfoDoc,"getDNSRes.xml" );
}
QDomDocument xml_handler::loadFile(QString filename)
{
qDebug() << __FUNCTION__;
QString file = filepath + (QString(filename));
QFile tempfile(file);
QDomDocument doc;
if(!tempfile.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug() << "could not open template";
}else{
doc.setContent(&tempfile);
tempfile.close();
}
return doc;
}
void xml_handler::writeFile(QDomDocument doc, QString filename)
{
QString prefix;
#ifdef IMX6
prefix = "/nvdata/tftpboot/xmlFiles/";
#else
prefix = "./xmlFiles/";
#endif
QString file = prefix + filename;
QFile xmlfile(file);
if(!xmlfile.open(QIODevice::WriteOnly | QIODevice::Unbuffered))
{
qDebug() << "Failed to write file";
}
QTextStream stream(&xmlfile);
stream.setCodec("UTF-8");
QString fstring(doc.toString());
fstring = fstring.simplified();
fstring.replace("> ",">");
fstring.replace("\n", "");
stream << fstring;
xmlfile.close();
}
void xml_handler::storeVidSrcCnfg( QString configWidth, QString configHeight, QString configFramerate)
{
width = configWidth;
height = configHeight;
framerate = configFramerate;
create_getVidSourcesRes();
}
bool xml_handler::createDir()
{
QString process = QString("mkdir /nvdata/tftpboot/xmlFiles");
QProcess *mkdir = new QProcess();
mkdir->start(process);
if(mkdir->waitForFinished())
{
if (mkdir->exitCode() == 0)
return true;
}
return false;
}