Ticket #6552: 6552-v1.patch
File 6552-v1.patch, 7.5 KB (added by , 15 years ago) |
---|
-
programs/mythbackend/playbacksock.h
78 78 void CancelNextRecording(int capturecardnum, bool cancel); 79 79 80 80 private: 81 bool SendReceiveStringList(QStringList &strlist );81 bool SendReceiveStringList(QStringList &strlist, uint min_reply_length = 0); 82 82 83 83 MythSocket *sock; 84 84 QString hostname; -
programs/mythbackend/playbacksock.cpp
1 #include < qstringlist.h>1 #include <QStringList> 2 2 3 #include <iostream>4 5 3 using namespace std; 6 4 7 5 #include "playbacksock.h" … … 64 62 return false; 65 63 } 66 64 67 bool PlaybackSock::SendReceiveStringList(QStringList &strlist) 65 bool PlaybackSock::SendReceiveStringList( 66 QStringList &strlist, uint min_reply_length) 68 67 { 68 bool ok = false; 69 69 70 sock->Lock(); 70 71 sock->UpRef(); 71 72 72 sockLock.lock(); 73 expectingreply = true; 73 { 74 QMutexLocker locker(&sockLock); 75 expectingreply = true; 74 76 75 sock->writeStringList(strlist);76 boolok = sock->readStringList(strlist);77 sock->writeStringList(strlist); 78 ok = sock->readStringList(strlist); 77 79 78 while (ok && strlist[0] == "BACKEND_MESSAGE") 79 { 80 // oops, not for us 81 QString message = strlist[1]; 82 strlist.pop_front(); strlist.pop_front(); 80 while (ok && strlist[0] == "BACKEND_MESSAGE") 81 { 82 // oops, not for us 83 if (strlist.size() >= 2) 84 { 85 QString message = strlist[1]; 86 strlist.pop_front(); 87 strlist.pop_front(); 88 MythEvent me(message, strlist); 89 gContext->dispatch(me); 90 } 83 91 84 MythEvent me(message,strlist);85 gContext->dispatch(me);92 ok = sock->readStringList(strlist); 93 } 86 94 87 ok = sock->readStringList(strlist);95 expectingreply = false; 88 96 } 89 97 90 expectingreply = false;91 sockLock.unlock();92 93 98 sock->Unlock(); 94 99 sock->DownRef(); 95 100 96 return ok; 101 if (!ok) 102 { 103 VERBOSE(VB_IMPORTANT, 104 "PlaybackSock::SendReceiveStringList(): No response."); 105 return false; 106 } 107 108 if (min_reply_length && ((uint)strlist.size() < min_reply_length)) 109 { 110 VERBOSE(VB_IMPORTANT, 111 "PlaybackSock::SendReceiveStringList(): Response too short"); 112 return false; 113 } 114 115 return true; 97 116 } 98 117 99 118 /** \brief Tells a slave to go to sleep … … 102 121 { 103 122 QStringList strlist( QString("GO_TO_SLEEP") ); 104 123 105 SendReceiveStringList(strlist); 106 107 return (strlist[0] == "OK"); 124 return SendReceiveStringList(strlist, 1) && (strlist[0] == "OK"); 108 125 } 109 126 110 127 /** … … 125 142 QStringList strlist( QString("CHECK_RECORDING") ); 126 143 pginfo->ToStringList(strlist); 127 144 128 SendReceiveStringList(strlist); 145 if (SendReceiveStringList(strlist, 1)) 146 return strlist[0].toInt(); 129 147 130 return strlist[0].toInt();148 return 0; 131 149 } 132 150 133 151 int PlaybackSock::StopRecording(const ProgramInfo *pginfo) … … 135 153 QStringList strlist( QString("STOP_RECORDING")); 136 154 pginfo->ToStringList(strlist); 137 155 138 SendReceiveStringList(strlist); 156 if (SendReceiveStringList(strlist, 1)) 157 return strlist[0].toInt(); 139 158 140 return strlist[0].toInt();159 return 0; 141 160 } 142 161 143 162 int PlaybackSock::DeleteRecording(const ProgramInfo *pginfo, bool forceMetadataDelete) … … 151 170 152 171 pginfo->ToStringList(strlist); 153 172 154 SendReceiveStringList(strlist); 173 if (SendReceiveStringList(strlist, 1)) 174 return strlist[0].toInt(); 155 175 156 return strlist[0].toInt();176 return 0; 157 177 } 158 178 159 179 bool PlaybackSock::FillProgramInfo(ProgramInfo *pginfo, QString &playbackhost) … … 162 182 strlist << playbackhost; 163 183 pginfo->ToStringList(strlist); 164 184 165 SendReceiveStringList(strlist); 185 if (SendReceiveStringList(strlist)) 186 return pginfo->FromStringList(strlist, 0); 166 187 167 return pginfo->FromStringList(strlist, 0);188 return false; 168 189 } 169 190 170 191 QStringList PlaybackSock::GetSGFileList(QString &host, QString &groupname, … … 244 265 strlist << QString::number(0); // don't check slaves 245 266 pginfo->ToStringList(strlist); 246 267 247 SendReceiveStringList(strlist); 268 if (SendReceiveStringList(strlist, 2)) 269 { 270 pginfo->pathname = strlist[1]; 271 return strlist[0].toInt(); 272 } 248 273 249 bool exists = strlist[0].toInt(); 250 pginfo->pathname = strlist[1]; 251 return exists; 274 return false; 252 275 } 253 276 254 277 bool PlaybackSock::IsBusy( … … 259 282 strlist << "IS_BUSY"; 260 283 strlist << QString::number(time_buffer); 261 284 262 SendReceiveStringList(strlist); 285 if (!SendReceiveStringList(strlist, 1)) 286 { 287 VERBOSE(VB_IMPORTANT, LOC_ERR + "IsBusy: " + 288 QString("QUERY_REMOTEENCODER %1").arg(capturecardnum) + 289 " gave us no response."); 290 } 263 291 264 292 QStringList::const_iterator it = strlist.begin(); 265 293 bool state = (*it).toInt(); … … 287 315 QStringList strlist( QString("QUERY_REMOTEENCODER %1").arg(capturecardnum) ); 288 316 strlist << "GET_STATE"; 289 317 290 SendReceiveStringList(strlist); 318 if (!SendReceiveStringList(strlist, 1)) 319 { 320 VERBOSE(VB_IMPORTANT, LOC_ERR + "GetEncoderState: " + 321 QString("QUERY_REMOTEENCODER %1").arg(capturecardnum) + 322 " gave us no response."); 291 323 292 int state = strlist[0].toInt(); 293 return state; 324 return kState_Error; 325 } 326 327 return strlist[0].toInt(); 294 328 } 295 329 296 330 long long PlaybackSock::GetMaxBitrate(int capturecardnum) … … 298 332 QStringList strlist( QString("QUERY_REMOTEENCODER %1").arg(capturecardnum) ); 299 333 strlist << "GET_MAX_BITRATE"; 300 334 301 SendReceiveStringList(strlist); 335 if (SendReceiveStringList(strlist, 2)) 336 return decodeLongLong(strlist, 0); 302 337 303 long long ret = decodeLongLong(strlist, 0); 304 return ret; 338 return 20200000LL; // Peek bit rate for HD-PVR 305 339 } 306 340 307 341 /** \fn *PlaybackSock::GetRecording(int) … … 317 351 318 352 strlist << "GET_CURRENT_RECORDING"; 319 353 320 SendReceiveStringList(strlist); 354 if (!SendReceiveStringList(strlist)) 355 return NULL; 321 356 322 357 ProgramInfo *info = new ProgramInfo(); 323 358 if (!info->FromStringList(strlist, 0)) … … 335 370 strlist << "MATCHES_RECORDING"; 336 371 pginfo->ToStringList(strlist); 337 372 338 SendReceiveStringList(strlist); 373 if (SendReceiveStringList(strlist, 1)) 374 return (bool) strlist[0].toInt(); 339 375 340 bool ret = strlist[0].toInt(); 341 return ret; 376 return false; 342 377 } 343 378 344 379 RecStatusType PlaybackSock::StartRecording(int capturecardnum, … … 348 383 strlist << "START_RECORDING"; 349 384 pginfo->ToStringList(strlist); 350 385 351 SendReceiveStringList(strlist); 386 if (SendReceiveStringList(strlist, 1)) 387 return RecStatusType(strlist[0].toInt()); 352 388 353 return RecStatusType(strlist[0].toInt());389 return rsUnknown; 354 390 } 355 391 356 392 void PlaybackSock::RecordPending(int capturecardnum, const ProgramInfo *pginfo, … … 373 409 strlist << QString::number(rate); 374 410 strlist << QString::number(notifyFrontend); 375 411 376 SendReceiveStringList(strlist); 412 if (SendReceiveStringList(strlist, 1)) 413 return strlist[0].toInt(); 377 414 378 int ret = strlist[0].toInt(); 379 return ret; 415 return -1; 380 416 } 381 417 382 418 void PlaybackSock::SetNextLiveTVDir(int capturecardnum, QString dir)