Ticket #1773: mythmediamonitor.patch
File mythmediamonitor.patch, 4.0 KB (added by , 19 years ago) |
---|
-
mythmediamonitor.h
80 80 bool CheckMountable(void); 81 81 bool FindPartitions(const QString &dev, bool checkPartitions); 82 82 83 voidAddDevice(MythMediaDevice* pDevice);83 bool AddDevice(MythMediaDevice* pDevice); 84 84 bool AddDevice(const char* dev); 85 85 bool AddDevice(struct fstab* mep); 86 86 bool RemoveDevice(const QString &dev); -
mythmediamonitor.cpp
347 347 return l; 348 348 } 349 349 350 // Given a media de ivce add it to our collection.351 voidMediaMonitor::AddDevice(MythMediaDevice* pDevice)350 // Given a media device add it to our collection. 351 bool MediaMonitor::AddDevice(MythMediaDevice* pDevice) 352 352 { 353 dev_t new_rdev; 354 struct stat sb; 355 356 if (stat(pDevice->getDevicePath(), &sb) < 0) { 357 perror("stat: "); 358 cerr << "MediaMonitor::AddDevice - Failed to stat " << 359 pDevice->getDevicePath() << endl; 360 return false; 361 } 362 new_rdev = sb.st_rdev; 363 364 365 // 366 // Check if this is a duplicate of a device we have already added 367 // 368 QValueList<MythMediaDevice*>::iterator itr = m_Devices.begin(); 369 MythMediaDevice* pDev; 370 while (itr != m_Devices.end()) 371 { 372 pDev = *itr; 373 if (stat(pDev->getDevicePath(), &sb) < 0) { 374 perror("stat: "); 375 cerr << "MediaMonitor::AddDevice - Failed to stat " << 376 pDevice->getDevicePath() << endl; 377 return false; 378 } 379 380 if (sb.st_rdev == new_rdev) { 381 VERBOSE(VB_IMPORTANT, QString("Mediamonitor: Not adding %1, it's a duplicate") 382 .arg(pDevice->getDevicePath())); 383 return false; 384 } 385 } 386 353 387 QMutexLocker locker(&m_DevicesLock); 354 388 355 389 connect(pDevice, SIGNAL(statusChanged(MediaStatus, MythMediaDevice*)), 356 390 this, SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*))); 357 391 m_Devices.push_back( pDevice ); 358 392 m_UseCount[pDevice] = 0; 393 return true; 359 394 } 360 395 361 396 // Given a fstab entry to a media device determine what type of device it is … … 424 459 strncpy(devstr, dev, len); 425 460 devstr[len] = 0; 426 461 if (is_cdrom) 427 MythCDROM::get(this, QString(devstr),462 pDevice = MythCDROM::get(this, QString(devstr), 428 463 is_supermount, m_AllowEject); 429 464 } 430 465 else … … 438 473 .arg(pDevice->getDevicePath())); 439 474 if (pDevice->testMedia() == MEDIAERR_OK) 440 475 { 441 AddDevice(pDevice);442 return true;476 if (AddDevice(pDevice)) 477 return true; 443 478 } 444 else 445 delete pDevice; 479 delete pDevice; 446 480 } 447 481 448 482 return false; … … 520 554 */ 521 555 bool MediaMonitor::FindPartitions(const QString &dev, bool checkPartitions) 522 556 { 557 MythMediaDevice* pDevice = NULL; 558 523 559 if (checkPartitions) 524 560 { 525 561 // check for partitions … … 552 588 QString device_file = GetDeviceFile(dev); 553 589 if (!device_file.isNull()) 554 590 { 555 AddDevice(MythCDROM::get(this, device_file, false, m_AllowEject)); 556 return true; 591 pDevice = MythCDROM::get(this, device_file, false, m_AllowEject); 592 593 if (AddDevice(pDevice)) 594 return true; 557 595 } 558 596 } 559 597 else … … 562 600 QString device_file = GetDeviceFile(dev); 563 601 if (!device_file.isNull()) 564 602 { 565 AddDevice(MythHDD::Get(this, device_file, false, false)); 566 return true; 603 pDevice = MythHDD::Get(this, device_file, false, false); 604 if (AddDevice(pDevice)) 605 return true; 567 606 } 568 607 } 608 if (pDevice != NULL) 609 delete pDevice; 569 610 570 611 return false; 571 612 }