From ed643353b100bee75459c4ef2d0330e7a04e1f2a Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Fri, 16 Aug 2002 18:00:00 +0200 Subject: =?UTF-8?q?Version=201.1.7=20-=20Adapted=20VDR=20to=20the=20NEWSTR?= =?UTF-8?q?UCT=20driver.=20To=20use=20the=20new=20driver,=20compile=20VDR?= =?UTF-8?q?=20with=20=20=20'make=20NEWSTRUCT=3D1'=20(thanks=20to=20Holger?= =?UTF-8?q?=20W=C3=A4chtler=20for=20some=20valuable=20advice).=20=20=20By?= =?UTF-8?q?=20default=20it=20currently=20still=20uses=20the=20old=20driver?= =?UTF-8?q?.=20-=20Added=20some=20missing=20#includes=20(thanks=20to=20Mar?= =?UTF-8?q?tin=20Hammerschmid).=20-=20Changed=20the=20log=20error=20messag?= =?UTF-8?q?e=20"can't=20record=20MPEG1!"=20to=20"error=20in=20data=20strea?= =?UTF-8?q?m!",=20=20=20since=20the=20mentioning=20of=20MPEG1=20has=20irri?= =?UTF-8?q?tated=20many=20people.=20-=20Consistently=20using=20malloc/free?= =?UTF-8?q?=20and=20new/delete=20(thanks=20to=20Andreas=20Schultz).=20-=20?= =?UTF-8?q?Temporarily=20made=20cDevice::ProvidesCa()=20virtual=20(Andreas?= =?UTF-8?q?=20Schultz=20needs=20this=20=20=20in=20his=20DXR3=20plugin).=20?= =?UTF-8?q?-=20cDevice=20no=20longer=20exposes=20a=20file=20handle=20to=20?= =?UTF-8?q?cPlayer.=20A=20derived=20cPlayer=20class=20=20=20can=20now=20ca?= =?UTF-8?q?ll=20DevicePoll()=20to=20see=20whether=20the=20replay=20device?= =?UTF-8?q?=20is=20ready=20for=20=20=20further=20data.=20A=20derived=20cDe?= =?UTF-8?q?vice=20class=20must=20implement=20Poll()=20and=20shall=20=20=20?= =?UTF-8?q?check=20if=20any=20of=20its=20file=20handles=20is=20ready=20for?= =?UTF-8?q?=20data.=20-=20Implemented=20several=20replay=20modes=20to=20al?= =?UTF-8?q?low=20players=20that=20play=20only=20audio=20(thanks=20=20=20to?= =?UTF-8?q?=20Stefan=20Huelswitt).=20-=20Improved=20cCondVar::Wait()=20and?= =?UTF-8?q?=20implemented=20cCondVar::TimedWait()=20(thanks=20to=20=20=20S?= =?UTF-8?q?tefan=20Huelswitt).=20-=20VDR=20no=20longer=20gives=20up=20if?= =?UTF-8?q?=20there=20is=20no=20DVB=20device.=20It=20continues=20to=20work?= =?UTF-8?q?=20if=20=20=20there=20is=20at=20least=20one=20device,=20either?= =?UTF-8?q?=20a=20DVB=20device=20found=20by=20the=20core=20VDR=20code=20?= =?UTF-8?q?=20=20itself,=20or=20a=20device=20implemented=20by=20a=20plugin?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index 6449a1b..29c5f2d 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.68 2002/08/03 15:44:53 kls Exp $ + * $Id: tools.c 1.70 2002/08/16 13:43:40 kls Exp $ */ #include "tools.h" @@ -80,7 +80,7 @@ char *strcpyrealloc(char *dest, const char *src) esyslog("ERROR: out of memory"); } else { - delete dest; + free(dest); dest = NULL; } return dest; @@ -239,7 +239,7 @@ bool isnumber(const char *s) const char *AddDirectory(const char *DirName, const char *FileName) { static char *buf = NULL; - delete buf; + free(buf); asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName); return buf; } @@ -303,7 +303,7 @@ bool MakeDirs(const char *FileName, bool IsDirectory) else break; } - delete s; + free(s); return result; } @@ -321,7 +321,7 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks) asprintf(&buffer, "%s/%s", FileName, e->d_name); if (FollowSymlinks) { int size = strlen(buffer) * 2; // should be large enough - char *l = new char[size]; + char *l = MALLOC(char, size); int n = readlink(buffer, l, size); if (n < 0) { if (errno != EINVAL) @@ -335,12 +335,12 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks) } else esyslog("ERROR: symlink name length (%d) exceeded anticipated buffer size (%d)", n, size); - delete l; + free(l); } dsyslog("removing %s", buffer); if (remove(buffer) < 0) LOG_ERROR_STR(buffer); - delete buffer; + free(buffer); } } closedir(d); @@ -384,10 +384,10 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) } else { LOG_ERROR_STR(buffer); - delete buffer; + free(buffer); return false; } - delete buffer; + free(buffer); } } closedir(d); @@ -429,7 +429,7 @@ bool SpinUpDisk(const char *FileName) { static char *buf = NULL; for (int n = 0; n < 10; n++) { - delete buf; + free(buf); if (DirectoryOk(FileName)) asprintf(&buf, "%s/vdr-%06d", *FileName ? FileName : ".", n); else @@ -482,6 +482,42 @@ const char *DayDateTime(time_t t) return buffer; } +// --- cPoller --------------------------------------------------------------- + +cPoller::cPoller(int FileHandle, bool Out) +{ + numFileHandles = 0; + Add(FileHandle, Out); +} + +bool cPoller::Add(int FileHandle, bool Out) +{ + if (FileHandle >= 0) { + for (int i = 0; i < numFileHandles; i++) { + if (pfd[i].fd == FileHandle) + return true; + } + if (numFileHandles < MaxPollFiles) { + pfd[numFileHandles].fd = FileHandle; + pfd[numFileHandles].events = Out ? POLLOUT : POLLIN; + numFileHandles++; + return true; + } + esyslog("ERROR: too many file handles in cPoller"); + } + return false; +} + +bool cPoller::Poll(int TimeoutMs) +{ + if (numFileHandles) { + if (poll(pfd, numFileHandles, TimeoutMs) != 0) + return true; // returns true even in case of an error, to let the caller + // access the file and thus see the error code + } + return false; +} + // --- cFile ----------------------------------------------------------------- bool cFile::files[FD_SETSIZE] = { false }; @@ -594,7 +630,7 @@ cSafeFile::cSafeFile(const char *FileName) { f = NULL; fileName = ReadLink(FileName); - tempName = fileName ? new char[strlen(fileName) + 5] : NULL; + tempName = fileName ? MALLOC(char, strlen(fileName) + 5) : NULL; if (tempName) strcat(strcpy(tempName, fileName), ".$$$"); } @@ -604,8 +640,8 @@ cSafeFile::~cSafeFile() if (f) fclose(f); unlink(tempName); - delete fileName; - delete tempName; + free(fileName); + free(tempName); } bool cSafeFile::Open(void) @@ -657,7 +693,7 @@ cLockFile::cLockFile(const char *Directory) cLockFile::~cLockFile() { Unlock(); - delete fileName; + free(fileName); } bool cLockFile::Lock(int WaitSeconds) -- cgit v1.2.3