diff options
Diffstat (limited to 'libs/vdr/include')
-rw-r--r-- | libs/vdr/include/CharsetConv.h | 115 | ||||
-rw-r--r-- | libs/vdr/include/CondWait.h | 61 | ||||
-rw-r--r-- | libs/vdr/include/FileNameList.h | 41 | ||||
-rw-r--r-- | libs/vdr/include/Logging.h | 45 | ||||
-rw-r--r-- | libs/vdr/include/Mutex.h | 63 | ||||
-rw-r--r-- | libs/vdr/include/ReadDir.h | 53 | ||||
-rw-r--r-- | libs/vdr/include/String.h | 85 | ||||
-rw-r--r-- | libs/vdr/include/StringList.h | 61 | ||||
-rw-r--r-- | libs/vdr/include/Thread.h | 101 | ||||
-rw-r--r-- | libs/vdr/include/TimeMs.h | 50 | ||||
-rw-r--r-- | libs/vdr/include/Vector.h | 119 | ||||
-rw-r--r-- | libs/vdr/include/i18n.h | 108 | ||||
-rw-r--r-- | libs/vdr/include/tools.h | 49 |
13 files changed, 951 insertions, 0 deletions
diff --git a/libs/vdr/include/CharsetConv.h b/libs/vdr/include/CharsetConv.h new file mode 100644 index 0000000..3a05f56 --- /dev/null +++ b/libs/vdr/include/CharsetConv.h @@ -0,0 +1,115 @@ +/** + * File: CharsetConv.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef CHARSETCONV_H +#define CHARSETCONV_H + +#include <stddef.h> +#include <sys/types.h> +#include <iconv.h> +typedef unsigned char uchar; + +// When handling strings that might contain UTF-8 characters, it may be necessary +// to process a "symbol" that consists of several actual character bytes. The +// following functions allow transparently accessing a "char *" string without +// having to worry about what character set is actually used. + +int Utf8CharLen(const char *s); + ///< Returns the number of character bytes at the beginning of the given + ///< string that form a UTF-8 symbol. +uint Utf8CharGet(const char *s, int Length = 0); + ///< Returns the UTF-8 symbol at the beginning of the given string. + ///< Length can be given from a previous call to Utf8CharLen() to avoid calculating + ///< it again. If no Length is given, Utf8CharLen() will be called. +int Utf8CharSet(uint c, char *s = NULL); + ///< Converts the given UTF-8 symbol to a sequence of character bytes and copies + ///< them to the given string. Returns the number of bytes written. If no string + ///< is given, only the number of bytes is returned and nothing is copied. +int Utf8SymChars(const char *s, int Symbols); + ///< Returns the number of character bytes at the beginning of the given + ///< string that form at most the given number of UTF-8 symbols. +int Utf8StrLen(const char *s); + ///< Returns the number of UTF-8 symbols formed by the given string of + ///< character bytes. +char *Utf8Strn0Cpy(char *Dest, const char *Src, int n); + ///< Copies at most n character bytes from Src to Dest, making sure that the + ///< resulting copy ends with a complete UTF-8 symbol. The copy is guaranteed + ///< to be zero terminated. + ///< Returns a pointer to Dest. +int Utf8ToArray(const char *s, uint *a, int Size); + ///< Converts the given character bytes (including the terminating 0) into an + ///< array of UTF-8 symbols of the given Size. Returns the number of symbols + ///< in the array (without the terminating 0). +int Utf8FromArray(const uint *a, char *s, int Size, int Max = -1); + ///< Converts the given array of UTF-8 symbols (including the terminating 0) + ///< into a sequence of character bytes of at most Size length. Returns the + ///< number of character bytes written (without the terminating 0). + ///< If Max is given, only that many symbols will be converted. + ///< The resulting string is always zero-terminated if Size is big enough. + +// When allocating buffer space, make sure we reserve enough space to hold +// a string in UTF-8 representation: + +#define Utf8BufSize(s) ((s) * 4) + +// The following macros automatically use the correct versions of the character +// class functions: + +#define Utf8to(conv, c) (cCharSetConv::SystemCharacterTable() ? to##conv(c) : tow##conv(c)) +#define Utf8is(ccls, c) (cCharSetConv::SystemCharacterTable() ? is##ccls(c) : isw##ccls(c)) + +class cCharSetConv { +public: + cCharSetConv(const char *FromCode = NULL, const char *ToCode = NULL); + ///< Sets up a character set converter to convert from FromCode to ToCode. + ///< If FromCode is NULL, the previously set systemCharacterTable is used + ///< (or "UTF-8" if no systemCharacterTable has been set). + ///< If ToCode is NULL, "UTF-8" is used. + ~cCharSetConv(); + const char *Convert(const char *From, char *To = NULL, size_t ToLength = 0); + ///< Converts the given Text from FromCode to ToCode (as set in the constructor). + ///< If To is given, it is used to copy at most ToLength bytes of the result + ///< (including the terminating 0) into that buffer. If To is not given, + ///< the result is copied into a dynamically allocated buffer and is valid as + ///< long as this object lives, or until the next call to Convert(). The + ///< return value always points to the result if the conversion was successful + ///< (even if a fixed size To buffer was given and the result didn't fit into + ///< it). If the string could not be converted, the result points to the + ///< original From string. + static const char *SystemCharacterTable(void) { return systemCharacterTable; } + static void SetSystemCharacterTable(const char *CharacterTable); + +private: + iconv_t cd; + char *result; + size_t length; + static char *systemCharacterTable; + }; + +#endif /* CHARSETCONV_H */ + diff --git a/libs/vdr/include/CondWait.h b/libs/vdr/include/CondWait.h new file mode 100644 index 0000000..1e663df --- /dev/null +++ b/libs/vdr/include/CondWait.h @@ -0,0 +1,61 @@ +/** + * File: CondWait.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef CONDWAIT_H +#define CONDWAIT_H + +#include <pthread.h> + +class cCondWait { +public: + cCondWait(void); + ~cCondWait(); + + bool Wait(int TimeoutMs = 0); + ///< Waits at most TimeoutMs milliseconds for a call to Signal(), or + ///< forever if TimeoutMs is 0. + ///< \return Returns true if Signal() has been called, false it the given + ///< timeout has expired. + void Signal(void); + ///< Signals a caller of Wait() that the condition it is waiting for is met. + + static void SleepMs(int TimeoutMs); + ///< Creates a cCondWait object and uses it to sleep for TimeoutMs + ///< milliseconds, immediately giving up the calling thread's time + ///< slice and thus avoiding a "busy wait". + ///< In order to avoid a possible busy wait, TimeoutMs will be automatically + ///< limited to values >2. + +private: + pthread_mutex_t mutex; + pthread_cond_t cond; + bool signaled; + }; + +#endif /* CONDWAIT_H */ + diff --git a/libs/vdr/include/FileNameList.h b/libs/vdr/include/FileNameList.h new file mode 100644 index 0000000..c8bc6af --- /dev/null +++ b/libs/vdr/include/FileNameList.h @@ -0,0 +1,41 @@ +/** + * File: FileNameList.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef FILENAMELIST_H +#define FILENAMELIST_H + +#include <StringList.h> + +class cFileNameList : public cStringList { +public: + cFileNameList(const char *Directory = NULL, bool DirsOnly = false); + bool Load(const char *Directory, bool DirsOnly = false); + }; + +#endif /* FILENAMELIST_H */ + diff --git a/libs/vdr/include/Logging.h b/libs/vdr/include/Logging.h new file mode 100644 index 0000000..4dd1300 --- /dev/null +++ b/libs/vdr/include/Logging.h @@ -0,0 +1,45 @@ +/** + * File: Logging.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef LOGGING_H +#define LOGGING_H + +#include <sys/syslog.h> + +extern int SysLogLevel; +extern void syslog_with_tid(int priority, const char *format, ...); + +#define esyslog(a...) void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() ) +#define isyslog(a...) void( (SysLogLevel > 1) ? syslog_with_tid(LOG_ERR, a) : void() ) +#define dsyslog(a...) void( (SysLogLevel > 2) ? syslog_with_tid(LOG_ERR, a) : void() ) + +#define LOG_ERROR esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__) +#define LOG_ERROR_STR(s) esyslog("ERROR (%s,%d): %s: %m", __FILE__, __LINE__, s) + +#endif /* LOGGING_H */ + diff --git a/libs/vdr/include/Mutex.h b/libs/vdr/include/Mutex.h new file mode 100644 index 0000000..5ea6cf2 --- /dev/null +++ b/libs/vdr/include/Mutex.h @@ -0,0 +1,63 @@ +/** + * File: Mutex.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef MUTEX_H +#define MUTEX_H + +#include <pthread.h> + +class cMutex { +public: + cMutex(void); + ~cMutex(); + void Lock(void); + void Unlock(void); + +private: + pthread_mutex_t mutex; + int locked; + friend class cCondVar; + }; + +// cMutexLock can be used to easily set a lock on mutex and make absolutely +// sure that it will be unlocked when the block will be left. Several locks can +// be stacked, so a function that makes many calls to another function which uses +// cMutexLock may itself use a cMutexLock to make one longer lock instead of many +// short ones. +class cMutexLock { +private: + cMutex *mutex; + bool locked; +public: + cMutexLock(cMutex *Mutex = NULL); + ~cMutexLock(); + bool Lock(cMutex *Mutex); + }; + +#endif /* MUTEX_H */ + diff --git a/libs/vdr/include/ReadDir.h b/libs/vdr/include/ReadDir.h new file mode 100644 index 0000000..466976d --- /dev/null +++ b/libs/vdr/include/ReadDir.h @@ -0,0 +1,53 @@ +/** + * File: ReadDir.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef READDIR_H +#define READDIR_H + +#include <stddef.h> +#include <dirent.h> +#include <sys/types.h> + +class cReadDir { +public: + cReadDir(const char *Directory); + ~cReadDir(); + bool Ok(void) { return directory != NULL; } + struct dirent *Next(void); + +private: + DIR *directory; + struct dirent *result; + union { // according to "The GNU C Library Reference Manual" + struct dirent d; + char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; + } u; + }; + +#endif /* READDIR_H */ + diff --git a/libs/vdr/include/String.h b/libs/vdr/include/String.h new file mode 100644 index 0000000..ec03cc1 --- /dev/null +++ b/libs/vdr/include/String.h @@ -0,0 +1,85 @@ +/** + * File: String.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef STRING_H +#define STRING_H + +#include <CharsetConv.h> +#include <stddef.h> +#include <stdarg.h> + +class cString { +public: + cString(const char *S = NULL, bool TakePointer = false); + cString(const cString &String); + virtual ~cString(); + operator const void * () const { return s; } // to catch cases where operator*() should be used + operator const char * () const { return s; } // for use in (const char *) context + const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.) + cString &operator=(const cString &String); + cString &operator=(const char *String); + cString &Truncate(int Index); ///< Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string). + static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); + static cString vsprintf(const char *fmt, va_list &ap); + +private: + char *s; + }; + +char *strcpyrealloc(char *dest, const char *src); +char *strn0cpy(char *dest, const char *src, size_t n); +char *strreplace(char *s, char c1, char c2); +char *strreplace(char *s, const char *s1, const char *s2); ///< re-allocates 's' and deletes the original string if necessary! +inline char *skipspace(const char *s) +{ + if ((uchar)*s > ' ') // most strings don't have any leading space, so handle this case as fast as possible + return (char *)s; + while (*s && (uchar)*s <= ' ') // avoiding isspace() here, because it is much slower + s++; + return (char *)s; +} +char *stripspace(char *s); +char *compactspace(char *s); +cString strescape(const char *s, const char *chars); +bool startswith(const char *s, const char *p); +bool endswith(const char *s, const char *p); +bool isempty(const char *s); +int numdigits(int n); +bool isnumber(const char *s); +int64_t StrToNum(const char *s); + ///< Converts the given string to a number. + ///< The numerical part of the string may be followed by one of the letters + ///< K, M, G or T to abbreviate Kilo-, Mega-, Giga- or Terabyte, respectively + ///< (based on 1024). Everything after the first non-numeric character is + ///< silently ignored, as are any characters other than the ones mentioned here. +cString itoa(int n); + + + +#endif /* STRING_H */ + diff --git a/libs/vdr/include/StringList.h b/libs/vdr/include/StringList.h new file mode 100644 index 0000000..fee534b --- /dev/null +++ b/libs/vdr/include/StringList.h @@ -0,0 +1,61 @@ +/** + * File: StringList.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef STRINGLIST_H +#define STRINGLIST_H + +#include <Vector.h> +#include <string.h> + +inline int CompareStrings(const void *a, const void *b) +{ + return strcmp(*(const char **)a, *(const char **)b); +} + +inline int CompareStringsIgnoreCase(const void *a, const void *b) +{ + return strcasecmp(*(const char **)a, *(const char **)b); +} + +class cStringList : public cVector<char *> { +public: + cStringList(int Allocated = 10): cVector<char *>(Allocated) {} + virtual ~cStringList(); + int Find(const char *s) const; + void Sort(bool IgnoreCase = false) + { + if (IgnoreCase) + cVector<char *>::Sort(CompareStringsIgnoreCase); + else + cVector<char *>::Sort(CompareStrings); + } + virtual void Clear(void); + }; + +#endif /* STRINGLIST_H */ + diff --git a/libs/vdr/include/Thread.h b/libs/vdr/include/Thread.h new file mode 100644 index 0000000..ce8c999 --- /dev/null +++ b/libs/vdr/include/Thread.h @@ -0,0 +1,101 @@ +/** + * File: Thread.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + * ++2012-07-04(rma): + * As I don't like the necessity to subclass what should work in a thread, + * I extended the original sources, so that an arbitrary function can be + * a thread kernel. + */ +#ifndef THREAD_H +#define THREAD_H + +#include <Mutex.h> +#include <stddef.h> +#include <pthread.h> +typedef pid_t tThreadId; + +class cThread { +public: + cThread(const char *Description = NULL); + ///< Creates a new thread. + ///< If Description is present, a log file entry will be made when + ///< the thread starts and stops. The Start() function must be called + ///< to actually start the thread. + cThread(int (*ThreadCallback)(void *opaque, cThread *instance), void *opaque, const char *Description = NULL); + virtual ~cThread(); + + void SetDescription(const char *Description, ...) __attribute__ ((format (printf, 2, 3))); + bool Start(void); + ///< Actually starts the thread. + ///< If the thread is already running, nothing happens. + virtual void Cancel(int WaitSeconds = 0); + ///< Cancels the thread by first setting 'running' to false, so that + ///< the Action() loop can finish in an orderly fashion and then waiting + ///< up to WaitSeconds seconds for the thread to actually end. If the + ///< thread doesn't end by itself, it is killed. + ///< If WaitSeconds is -1, only 'running' is set to false and Cancel() + ///< returns immediately, without killing the thread. + bool Active(void); + ///< used from outside to check whether the thread is still alive. + bool Running(void) { return running; } + ///< used from inside the thread to check whether it may keep on running. + ///< Returns false if a derived cThread object shall leave its Action() + ///< function. Should be public and so available for callback thread kernels + + static tThreadId ThreadId(void); + static tThreadId IsMainThread(void) { return ThreadId() == mainThreadId; } + static void SetMainThreadId(void); + +protected: + void SetPriority(int Priority); + void SetIOPriority(int Priority); + void Lock(void) { mutex.Lock(); } + void Unlock(void) { mutex.Unlock(); } + virtual void Action(void); + ///< A derived cThread class must implement the code it wants to + ///< execute as a separate thread in this function. If this is + ///< a loop, it must check Running() repeatedly to see whether + ///< it's time to stop. + ///< To support callbacks as thread kernels, default implementation now + ///< starts the callback + +private: + bool active; + bool running; + pthread_t childTid; + tThreadId childThreadId; + cMutex mutex; + char *description; + int (*threadCallback)(void *, cThread *); + void *opaque; + static tThreadId mainThreadId; + static void *StartThread(cThread *Thread); + friend class cThreadLock; + }; + +#endif /* THREAD_H */ + diff --git a/libs/vdr/include/TimeMs.h b/libs/vdr/include/TimeMs.h new file mode 100644 index 0000000..dca609f --- /dev/null +++ b/libs/vdr/include/TimeMs.h @@ -0,0 +1,50 @@ +/** + * File: TimeMs.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef TIMEMS_H +#define TIMEMS_H + +#include <inttypes.h> + +class cTimeMs { +public: + cTimeMs(int Ms = 0); + ///< Creates a timer with ms resolution and an initial timeout of Ms. + ///< If Ms is negative the timer is not initialized with the current + ///< time. + void Set(int Ms = 0); + bool TimedOut(void); + uint64_t Elapsed(void); + static uint64_t Now(void); + +private: + uint64_t begin; + }; + +#endif /* TIMEMS_H */ + diff --git a/libs/vdr/include/Vector.h b/libs/vdr/include/Vector.h new file mode 100644 index 0000000..65760ac --- /dev/null +++ b/libs/vdr/include/Vector.h @@ -0,0 +1,119 @@ +/** + * File: Vector.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef VECTOR_H +#define VECTOR_H + +#include <stddef.h> +#include <Logging.h> +#include <stdlib.h> + +template<class T> class cVector { + ///< cVector may only be used for *simple* types, like int or pointers - not for class objects that allocate additional memory! +public: + cVector(int Allocated = 10) + { + allocated = 0; + size = 0; + data = NULL; + Realloc(Allocated); + } + virtual ~cVector() { free(data); } + T& At(int Index) const + { + Realloc(Index); + if (Index >= size) + size = Index + 1; + return data[Index]; + } + const T& operator[](int Index) const + { + return At(Index); + } + T& operator[](int Index) + { + return At(Index); + } + int Size(void) const { return size; } + virtual void Insert(T Data, int Before = 0) + { + if (Before < size) { + Realloc(size); + memmove(&data[Before + 1], &data[Before], (size - Before) * sizeof(T)); + size++; + data[Before] = Data; + } + else + Append(Data); + } + virtual void Append(T Data) + { + if (size >= allocated) + Realloc(allocated * 3 / 2); // increase size by 50% + data[size++] = Data; + } + virtual void Remove(int Index) + { + if (Index < size - 1) + memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T)); + size--; + } + virtual void Clear(void) + { + for (int i = 0; i < size; i++) + data[i] = T(0); + size = 0; + } + void Sort(__compar_fn_t Compare) + { + qsort(data, size, sizeof(T), Compare); + } + +private: + mutable int allocated; + mutable int size; + mutable T *data; + cVector(const cVector &Vector) {} // don't copy... + cVector &operator=(const cVector &Vector) { return *this; } // ...or assign this! + void Realloc(int Index) const + { + if (++Index > allocated) { + data = (T *)realloc(data, Index * sizeof(T)); + if (!data) { + esyslog("ERROR: out of memory - abort!"); + abort(); + } + for (int i = allocated; i < Index; i++) + data[i] = T(0); + allocated = Index; + } + } + }; + +#endif /* VECTOR_H */ + diff --git a/libs/vdr/include/i18n.h b/libs/vdr/include/i18n.h new file mode 100644 index 0000000..40185e4 --- /dev/null +++ b/libs/vdr/include/i18n.h @@ -0,0 +1,108 @@ +/** + * File: i18n.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef __I18N_H +#define __I18N_H + +#include <stdio.h> + +#define I18N_DEFAULT_LOCALE "en_US" +#define I18N_MAX_LOCALE_LEN 16 // for buffers that hold en_US etc. +#define I18N_MAX_LANGUAGES 256 // for buffers that hold all available languages +class cStringList; +void I18nInitialize(const char *LocaleDir = NULL); + ///< Detects all available locales and loads the language names and codes. + ///< If LocaleDir is given, it must point to a static string that lives + ///< for the entire lifetime of the program. +void I18nRegister(const char *Plugin); + ///< Registers the named plugin, so that it can use internationalized texts. +void I18nSetLocale(const char *Locale); + ///< Sets the current locale to Locale. The default locale is "en_US". + ///< If no such locale has been found in the call to I18nInitialize(), + ///< nothing happens. +int I18nCurrentLanguage(void); + ///< Returns the index of the current language. This number stays the + ///< same for any given language while the program is running, but may + ///< be different when the program is run again (for instance because + ///< a locale has been added or removed). The default locale ("en_US") + ///< always has a zero index. +void I18nSetLanguage(int Language); + ///< Sets the current language index to Language. If Language is outside + ///< the range of available languages, nothing happens. +int I18nNumLanguagesWithLocale(void); + ///< Returns the number of entries in the list returned by I18nLanguages() + ///< that actually have a locale. +const cStringList *I18nLanguages(void); + ///< Returns the list of available languages. Values returned by + ///< I18nCurrentLanguage() are indexes into this list. + ///< Only the first I18nNumLanguagesWithLocale() entries in this list + ///< have an actual locale installed. The rest are just dummy entries + ///< to allow having three letter language codes for other languages + ///< that have no actual locale on this system. +const char *I18nTranslate(const char *s, const char *Plugin = NULL) __attribute_format_arg__(1); + ///< Translates the given string (with optional Plugin context) into + ///< the current language. If no translation is available, the original + ///< string will be returned. +const char *I18nLocale(int Language); + ///< Returns the locale code of the given Language (which is an index as + ///< returned by I18nCurrentLanguage()). If Language is outside the range + ///< of available languages, NULL is returned. +const char *I18nLanguageCode(int Language); + ///< Returns the three letter language code of the given Language (which + ///< is an index as returned by I18nCurrentLanguage()). If Language is + ///< outside the range of available languages, NULL is returned. + ///< The returned string may consist of several alternative three letter + ///< language codes, separated by commas (as in "deu,ger"). +int I18nLanguageIndex(const char *Code); + ///< Returns the index of the language with the given three letter + ///< language Code. If no suitable language is found, -1 is returned. +const char *I18nNormalizeLanguageCode(const char *Code); + ///< Returns a 3 letter language code that may not be zero terminated. + ///< If no normalized language code can be found, the given Code is returned. + ///< Make sure at most 3 characters are copied when using it! +bool I18nIsPreferredLanguage(int *PreferredLanguages, const char *LanguageCode, int &OldPreference, int *Position = NULL); + ///< Checks the given LanguageCode (which may be something like "eng" or "eng+deu") + ///< against the PreferredLanguages and returns true if one is found that has an index + ///< smaller than OldPreference (which should be initialized to -1 before the first + ///< call to this function in a sequence of checks). If LanguageCode is not any of + ///< the PreferredLanguages, and OldPreference is less than zero, OldPreference will + ///< be set to a value higher than the highest language index. If Position is given, + ///< it will return 0 if this was a single language code (like "eng"), 1 if it was + ///< the first of two language codes (like "eng" out of "eng+deu") and 2 if it was + ///< the second one (like "deu" out of ""eng+deu"). + +#ifdef PLUGIN_NAME_I18N +#define tr(s) I18nTranslate(s, "vdr-" PLUGIN_NAME_I18N) +#define trVDR(s) I18nTranslate(s) // to use a text that's in the VDR core's translation file +#else +#define tr(s) I18nTranslate(s) +#endif + +#define trNOOP(s) (s) + +#endif //__I18N_H diff --git a/libs/vdr/include/tools.h b/libs/vdr/include/tools.h new file mode 100644 index 0000000..bb159aa --- /dev/null +++ b/libs/vdr/include/tools.h @@ -0,0 +1,49 @@ +/** + * File: tools.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef TOOLS_H +#define TOOLS_H + +#include <stddef.h> + +#define MALLOC(type, size) (type *)malloc(sizeof(type) * (size)) + +template<class T> inline void DELETENULL(T *&p) { T *q = p; p = NULL; delete q; } + +#define CHECK(s) { if ((s) < 0) LOG_ERROR; } // used for 'ioctl()' calls +#define FATALERRNO (errno && errno != EAGAIN && errno != EINTR) + +#ifndef __STL_CONFIG_H // in case some plugin needs to use the STL +template<class T> inline T min(T a, T b) { return a <= b ? a : b; } +template<class T> inline T max(T a, T b) { return a >= b ? a : b; } +template<class T> inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; } +template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; } +#endif + +#endif /* TOOLS_H */ + |