|
SASC
DVBSoftCAM
|
00001 /* 00002 * Softcam plugin to VDR (C++) 00003 * 00004 * This code is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This code is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 00018 */ 00019 00020 #ifndef ___LOG_H 00021 #define ___LOG_H 00022 00023 #include "misc.h" 00024 00025 class cMutex; 00026 00027 // ---------------------------------------------------------------- 00028 00029 #define LOPT_NUM 27 00030 #define LOPT_MAX (1<<LOPT_NUM) 00031 #define LOPT_MASK (LOPT_MAX-1) 00032 #define LMOD_MAX (1<<(32-LOPT_NUM)) 00033 #define LMOD_MASK (LMOD_MAX-1) 00034 #define LMOD_ENABLE 1 00035 00036 #define LCLASS(m,o) ((((m)&LMOD_MASK)<<LOPT_NUM)|((o)&LOPT_MASK)) 00037 #define LMOD(c) (((c)>>LOPT_NUM)&LMOD_MASK) 00038 #define LOPT(o) ((o)&LOPT_MASK) 00039 #define LALL(o) (((o)<<1)-1) 00040 00041 #define ADD_MODULE(MOD,NAME) static bool __add_mod_ ## NAME = cLogging::AddModule(MOD,&NAME); 00042 00043 #define PRINTF(c,...) cLogging::Printf((c),__VA_ARGS__) 00044 #define PUTS(c,t) cLogging::Puts((c),(t)) 00045 #define PUTLB(c,lb) cLogging::PutLB((c),(lb)) 00046 #define HEXDUMP(c,d,n,...) cLogging::Dump((c),(d),(n),__VA_ARGS__) 00047 #define LDUMP(c,d,n,...) cLogging::LineDump((c),(d),(n),__VA_ARGS__) 00048 #define LOG(c) cLogging::Enabled((c)) 00049 00050 // backward compatibility 00051 #define HexDump(d,n) do { int __n=(n); HEXDUMP(L_GEN_MISC,(d),__n,"dump: n=%d/0x%04x",__n,__n); } while(0) 00052 00053 #define LBSTART(c) do { int __c=(c); if(LOG(__c)) { cLogLineBuff __llb(__c) 00054 #define LBSTARTF(c) do { int __c=(c); { cLogLineBuff __llb(__c) 00055 #define LBPUT(...) __llb.Printf(__VA_ARGS__) 00056 #define LBFLUSH() __llb.Flush() 00057 #define LBEND( ) } } while(0) 00058 00059 // ---------------------------------------------------------------- 00060 00061 #define L_GEN 0 00062 #define L_GEN_ERROR LCLASS(L_GEN,0x2) 00063 #define L_GEN_WARN LCLASS(L_GEN,0x4) 00064 #define L_GEN_INFO LCLASS(L_GEN,0x8) 00065 #define L_GEN_DEBUG LCLASS(L_GEN,0x10) 00066 #define L_GEN_MISC LCLASS(L_GEN,0x20) 00067 00068 #define L_GEN_ALL LALL(L_GEN_MISC) 00069 00070 // ---------------------------------------------------------------- 00071 00072 struct LogConfig { 00073 int logCon, logFile, logSys, logUser, noTimestamp; 00074 int maxFilesize; 00075 char logFilename[128]; 00076 }; 00077 00078 extern struct LogConfig logcfg; 00079 00080 struct LogModule { 00081 int OptSupported, OptDefault; 00082 const char *Name, *OptName[LOPT_NUM]; 00083 }; 00084 00085 struct LogHeader { 00086 int c; 00087 char stamp[32]; 00088 char tag[64]; 00089 }; 00090 00091 class cLogging { 00092 private: 00093 static void (*LogPrint)(const struct LogHeader *lh, const char *txt); 00094 // 00095 static void PrivateLogPrint(const struct LogHeader *lh, const char *txt); 00096 static bool GetHeader(int c, struct LogHeader *lh); 00097 static void LogLine(const struct LogHeader *lh, const char *txt, bool doCrc=true); 00098 static const struct LogModule *GetModule(int c); 00099 static void UpgradeOptions(int m); 00100 public: 00101 static bool AddModule(int m, const struct LogModule *dm); 00102 static void SetLogPrint(void (*lp)(const struct LogHeader *lh, const char *txt)); 00103 // 00104 static void Printf(int c, const char *format, ...) __attribute__ ((format (printf,2,3))); 00105 static void Puts(int c, const char *txt); 00106 static void PutLB(int c, cLineBuff *lb); 00107 static void Dump(int c, const void *data, int n, const char *format, ...) __attribute__ ((format (printf,4,5))); 00108 static void LineDump(int c, const void *data, int n, const char *format, ...) __attribute__ ((format (printf,4,5))); 00109 static bool Enabled(int c); 00110 // 00111 static void SetModuleOptions(int c); 00112 static int GetModuleOptions(int c); 00113 static void SetModuleOption(int c, bool on); 00114 static void SetModuleDefault(int c); 00115 static const char *GetModuleName(int c); 00116 static const char *GetOptionName(int c); 00117 static void ParseConfig(const char *txt); 00118 static bool GetConfig(cLineBuff *lb); 00119 static void ReopenLogfile(void); 00120 static int GetClassByName(const char *name); 00121 }; 00122 00123 // ---------------------------------------------------------------- 00124 00125 class cUserMsg : public cSimpleItem { 00126 private: 00127 char *msg; 00128 public: 00129 cUserMsg(const char *m); 00130 ~cUserMsg(); 00131 const char *Message(void) { return msg; }; 00132 }; 00133 00134 // ---------------------------------------------------------------- 00135 00136 class cUserMsgs : public cSimpleList<cUserMsg> { 00137 private: 00138 cMutex *mutex; 00139 public: 00140 cUserMsgs(void); 00141 ~cUserMsgs(); 00142 void Queue(const char *fmt, ...) __attribute__ ((format (printf,2,3))); 00143 cUserMsg *GetQueuedMsg(void); 00144 }; 00145 00146 extern cUserMsgs ums; 00147 00148 // ---------------------------------------------------------------- 00149 00150 class cLogLineBuff : public cLineBuff { 00151 private: 00152 int c; 00153 public: 00154 cLogLineBuff(int C); 00155 ~cLogLineBuff(); 00156 void Flush(void); 00157 }; 00158 00159 #endif //___LOG_H