Index: device.c =================================================================== --- device.c (Revision 10504) +++ device.c (Arbeitskopie) @@ -270,14 +270,19 @@ for (int i = 0; i < MAXRECEIVERS; i++) receiver[i] = NULL; - if (numDevices < MAXDEVICES) - device[numDevices++] = this; - else - esyslog("ERROR: too many devices!"); + for (int i = 0; i < MAXDEVICES; i++) + if (!device[i]) { + device[i] = this; + numDevices++; + return; + } + esyslog("ERROR: too many devices!"); } cDevice::~cDevice() { + numDevices--; + device[DeviceNumber()] = NULL; Detach(player); for (int i = 0; i < MAXRECEIVERS; i++) Detach(receiver[i]); @@ -290,7 +295,7 @@ { for (time_t t0 = time(NULL); time(NULL) - t0 < Timeout; ) { bool ready = true; - for (int i = 0; i < numDevices; i++) { + for (int i = 0; i < MAXDEVICES; i++) { if (device[i] && !device[i]->Ready()) ready = false; } @@ -322,7 +327,7 @@ int cDevice::DeviceNumber(void) const { - for (int i = 0; i < numDevices; i++) { + for (int i = 0; i < MAXDEVICES; i++) { if (device[i] == this) return i; } @@ -336,7 +341,7 @@ bool cDevice::SetPrimaryDevice(int n) { n--; - if (0 <= n && n < numDevices && device[n]) { + if (0 <= n && n < MAXDEVICES && device[n]) { isyslog("setting primary device to %d", n + 1); if (primaryDevice) primaryDevice->MakePrimaryDevice(false); @@ -369,15 +374,17 @@ cDevice *cDevice::GetDevice(int Index) { - return (0 <= Index && Index < numDevices) ? device[Index] : NULL; + return (0 <= Index && Index < MAXDEVICES) ? device[Index] : NULL; } cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) { cDevice *d = NULL; uint Impact = 0xFFFFFFFF; // we're looking for a device with the least impact - for (int i = 0; i < numDevices; i++) { + for (int i = 0; i < MAXDEVICES; i++) { bool ndr; + if (device[i] == NULL) + continue; // this device was not allocated #ifdef DETACH_UNUSED_DEVICES if(!device[i]->Receiving()) { isyslog("device %d (%p) not receiving", i, device[i]); @@ -419,10 +426,11 @@ void cDevice::Shutdown(void) { primaryDevice = NULL; - for (int i = 0; i < numDevices; i++) { - delete device[i]; - device[i] = NULL; + for (int i = 0; i < MAXDEVICES; i++) { + if( device[i]) { + delete device[i]; } + } } uchar *cDevice::GrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY) @@ -724,6 +732,16 @@ return -1; } +int cDevice::ReadFilter(int Handle, void *Buffer, size_t Length) +{ + return safe_read(Handle, Buffer, Length); +} + +void cDevice::CloseFilter(int Handle) +{ + close(Handle); +} + void cDevice::AttachFilter(cFilter *Filter) { if (sectionHandler) @@ -753,7 +771,7 @@ bool cDevice::ProvidesTransponderExclusively(const cChannel *Channel) const { - for (int i = 0; i < numDevices; i++) { + for (int i = 0; i < MAXDEVICES; i++) { if (device[i] && device[i] != this && device[i]->ProvidesTransponder(Channel)) return false; } Index: device.h =================================================================== --- device.h (Revision 10504) +++ device.h (Arbeitskopie) @@ -326,6 +326,15 @@ ///< Opens a file handle for the given filter data. ///< A derived device that provides section data must ///< implement this function. + virtual int ReadFilter(int Handle, void *Buffer, size_t Length); + ///< Read from a handle for the given filter data. + ///< a derived class need not implement this function, because this + ///< is done by the default implementation. + virtual void CloseFilter(int Handle); + ///< Closes a file handle that has previously been opened + ///< by OpenFilter(). If this is as simple as calling close(Handle), + ///< a derived class need not implement this function, because this + ///< is done by the default implementation. void AttachFilter(cFilter *Filter); ///< Attaches the given filter to this device. void Detach(cFilter *Filter); Index: sections.c =================================================================== --- sections.c (Revision 10504) +++ sections.c (Arbeitskopie) @@ -105,7 +105,7 @@ for (fh = filterHandles.First(); fh; fh = filterHandles.Next(fh)) { if (fh->filterData.Is(FilterData->pid, FilterData->tid, FilterData->mask)) { if (--fh->used <= 0) { - close(fh->handle); + device->CloseFilter(fh->handle); filterHandles.Del(fh); break; } @@ -198,7 +198,7 @@ if (fh) { // Read section data: unsigned char buf[4096]; // max. allowed size for any EIT section - int r = safe_read(fh->handle, buf, sizeof(buf)); + int r = device->ReadFilter(fh->handle, buf, sizeof(buf)); if (!DeviceHasLock) continue; // we do the read anyway, to flush any data that might have come from a different transponder if (r > 3) { // minimum number of bytes necessary to get section length