diff options
author | Karlson2k <k2k@narod.ru> | 2014-07-21 16:50:17 +0400 |
---|---|---|
committer | Karlson2k <k2k@narod.ru> | 2014-08-22 15:57:07 +0400 |
commit | 24640f6cc66d8dd480b34560c6fda22d14f743d2 (patch) | |
tree | 31739acfd66eee4a9c3a599b4b8848c76c365259 | |
parent | a0acde7189f77b1a028a2d60dd8213628f14f7de (diff) |
[posix] Implement class CPosixInterfaceForCLog
-rw-r--r-- | XBMC.xcodeproj/project.pbxproj | 18 | ||||
-rw-r--r-- | xbmc/utils/Makefile.in | 1 | ||||
-rw-r--r-- | xbmc/utils/posix/PosixInterfaceForCLog.cpp | 108 | ||||
-rw-r--r-- | xbmc/utils/posix/PosixInterfaceForCLog.h | 38 |
4 files changed, 165 insertions, 0 deletions
diff --git a/XBMC.xcodeproj/project.pbxproj b/XBMC.xcodeproj/project.pbxproj index 7272e0915b..10a2e89576 100644 --- a/XBMC.xcodeproj/project.pbxproj +++ b/XBMC.xcodeproj/project.pbxproj @@ -1113,6 +1113,9 @@ AE84CB5A15A5B8A600A3810E /* TagLibVFSStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE84CB5915A5B8A600A3810E /* TagLibVFSStream.cpp */; }; AE89ACA61621DAB800E17DBC /* DVDDemuxBXA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE89ACA41621DAB800E17DBC /* DVDDemuxBXA.cpp */; }; AEC0083115ACAC6E0099888C /* TagLoaderTagLib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AEC0083015ACAC6E0099888C /* TagLoaderTagLib.cpp */; }; + B542632B197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5426329197D353B00726998 /* PosixInterfaceForCLog.cpp */; }; + B542632C197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5426329197D353B00726998 /* PosixInterfaceForCLog.cpp */; }; + B542632D197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5426329197D353B00726998 /* PosixInterfaceForCLog.cpp */; }; C807114D135DB5CC002F601B /* InputOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C807114B135DB5CC002F601B /* InputOperations.cpp */; }; C84828C0156CFCD8005A996F /* PVRClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C8482874156CFCD8005A996F /* PVRClient.cpp */; }; C84828C1156CFCD8005A996F /* PVRClients.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C8482876156CFCD8005A996F /* PVRClients.cpp */; }; @@ -4646,6 +4649,8 @@ AEC0083015ACAC6E0099888C /* TagLoaderTagLib.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagLoaderTagLib.cpp; sourceTree = "<group>"; }; AEC0083315ACAC7C0099888C /* TagLoaderTagLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagLoaderTagLib.h; sourceTree = "<group>"; }; B542632E19917D3500726998 /* params_check_macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = params_check_macros.h; sourceTree = "<group>"; }; + B5426329197D353B00726998 /* PosixInterfaceForCLog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PosixInterfaceForCLog.cpp; sourceTree = "<group>"; }; + B542632A197D353B00726998 /* PosixInterfaceForCLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PosixInterfaceForCLog.h; sourceTree = "<group>"; }; C807114B135DB5CC002F601B /* InputOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InputOperations.cpp; sourceTree = "<group>"; }; C807114C135DB5CC002F601B /* InputOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputOperations.h; sourceTree = "<group>"; }; C8482874156CFCD8005A996F /* PVRClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PVRClient.cpp; sourceTree = "<group>"; }; @@ -7928,6 +7933,15 @@ path = media; sourceTree = "<group>"; }; + B5426323197D2AB300726998 /* posix */ = { + isa = PBXGroup; + children = ( + B5426329197D353B00726998 /* PosixInterfaceForCLog.cpp */, + B542632A197D353B00726998 /* PosixInterfaceForCLog.h */, + ); + path = posix; + sourceTree = "<group>"; + }; C6859E96029091FE04C91782 /* docs */ = { isa = PBXGroup; children = ( @@ -9811,6 +9825,7 @@ AE4E87A617354C4A00D15206 /* XSLTUtils.h */, 18B7C9811294385F009E7A26 /* XMLUtils.cpp */, 18B7C9821294385F009E7A26 /* XMLUtils.h */, + B5426323197D2AB300726998 /* posix */, ); path = utils; sourceTree = "<group>"; @@ -10886,6 +10901,7 @@ E38E22800D25F9FE00618676 /* MusicInfoScanner.cpp in Sources */, E38E22970D25F9FE00618676 /* NfoFile.cpp in Sources */, E38E22A00D25F9FE00618676 /* PartyModeManager.cpp in Sources */, + B542632B197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */, E38E22A10D25F9FE00618676 /* Picture.cpp in Sources */, E38E22A20D25F9FE00618676 /* PictureInfoLoader.cpp in Sources */, E38E22A30D25F9FE00618676 /* PictureInfoTag.cpp in Sources */, @@ -11971,6 +11987,7 @@ DFF0F19817528350002DA3A4 /* DVDPlayerAudio.cpp in Sources */, DFF0F19917528350002DA3A4 /* DVDPlayerSubtitle.cpp in Sources */, DFF0F19A17528350002DA3A4 /* DVDPlayerTeletext.cpp in Sources */, + B542632D197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */, DFF0F19B17528350002DA3A4 /* DVDPlayerVideo.cpp in Sources */, DFF0F19C17528350002DA3A4 /* DVDStreamInfo.cpp in Sources */, DFF0F19D17528350002DA3A4 /* DVDTSCorrection.cpp in Sources */, @@ -13206,6 +13223,7 @@ E499122B174E5D6100741B6D /* qry_dat.cpp in Sources */, E499122C174E5D6100741B6D /* sqlitedataset.cpp in Sources */, E499122D174E5D6800741B6D /* Epg.cpp in Sources */, + B542632C197D353B00726998 /* PosixInterfaceForCLog.cpp in Sources */, E499122E174E5D6800741B6D /* EpgContainer.cpp in Sources */, E499122F174E5D6800741B6D /* EpgDatabase.cpp in Sources */, E4991230174E5D6800741B6D /* EpgInfoTag.cpp in Sources */, diff --git a/xbmc/utils/Makefile.in b/xbmc/utils/Makefile.in index de33bb40ea..5d2280616e 100644 --- a/xbmc/utils/Makefile.in +++ b/xbmc/utils/Makefile.in @@ -44,6 +44,7 @@ SRCS += Mime.cpp SRCS += Observer.cpp SRCS += PerformanceSample.cpp SRCS += PerformanceStats.cpp +SRCS += posix/PosixInterfaceForCLog.cpp SRCS += POUtils.cpp SRCS += RecentlyAddedJob.cpp SRCS += RegExp.cpp diff --git a/xbmc/utils/posix/PosixInterfaceForCLog.cpp b/xbmc/utils/posix/PosixInterfaceForCLog.cpp new file mode 100644 index 0000000000..0b93ece98d --- /dev/null +++ b/xbmc/utils/posix/PosixInterfaceForCLog.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2014 Team XBMC + * http://xbmc.org + * + * 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, 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 XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "PosixInterfaceForCLog.h" +#include <stdio.h> +#include <time.h> + +#if defined(TARGET_DARWIN) +#include "DarwinUtils.h" +#elif defined(TARGET_ANDROID) +#include "android/activity/XBMCApp.h" +#endif // TARGET_ANDROID + +struct FILEWRAP : public FILE +{}; + + +CPosixInterfaceForCLog::CPosixInterfaceForCLog() : + m_file(NULL) +{ } + +CPosixInterfaceForCLog::~CPosixInterfaceForCLog() +{ + if (m_file) + fclose(m_file); +} + +bool CPosixInterfaceForCLog::OpenLogFile(const std::string &logFilename, const std::string &backupOldLogToFilename) +{ + if (m_file) + return false; // file was already opened + + (void)remove(backupOldLogToFilename.c_str()); // if it's failed, try to continue + (void)rename(logFilename.c_str(), backupOldLogToFilename.c_str()); // if it's failed, try to continue + + m_file = (FILEWRAP*)fopen(logFilename.c_str(), "wb"); + if (!m_file) + return false; // error, can't open log file + + static const unsigned char BOM[3] = { 0xEF, 0xBB, 0xBF }; + (void)fwrite(BOM, sizeof(BOM), 1, m_file); // write BOM, ignore possible errors + + return true; +} + +void CPosixInterfaceForCLog::CloseLogFile() +{ + if (m_file) + { + fclose(m_file); + m_file = NULL; + } +} + +bool CPosixInterfaceForCLog::WriteStringToLog(const std::string &logString) +{ + if (!m_file) + return false; + + const bool ret = (fwrite(logString.data(), logString.size(), 1, m_file) == 1) && + (fwrite("\n", 1, 1, m_file) == 1); + (void)fflush(m_file); + + return ret; +} + +void CPosixInterfaceForCLog::PrintDebugString(const std::string &debugString) +{ +#ifdef _DEBUG +#if defined(TARGET_DARWIN) + DarwinPrintDebugString(debugString); +#elif defined(TARGET_ANDROID) + //print to adb + CXBMCApp::android_printf("Debug Print: %s", debugString.c_str()); +#endif // TARGET_ANDROID +#endif // _DEBUG +} + +void CPosixInterfaceForCLog::GetCurrentLocalTime(int &hour, int &minute, int &second) +{ + time_t curTime; + struct tm localTime; + if (time(&curTime) != -1 && localtime_r(&curTime, &localTime) != NULL) + { + hour = localTime.tm_hour; + minute = localTime.tm_min; + second = localTime.tm_sec; + } + else + hour = minute = second = 0; +} diff --git a/xbmc/utils/posix/PosixInterfaceForCLog.h b/xbmc/utils/posix/PosixInterfaceForCLog.h new file mode 100644 index 0000000000..bb534427c1 --- /dev/null +++ b/xbmc/utils/posix/PosixInterfaceForCLog.h @@ -0,0 +1,38 @@ +#pragma once +/* + * Copyright (C) 2014 Team XBMC + * http://xbmc.org + * + * 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, 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 XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include <string> + +struct FILEWRAP; // forward declaration, wrapper for FILE + +class CPosixInterfaceForCLog +{ +public: + CPosixInterfaceForCLog(); + ~CPosixInterfaceForCLog(); + bool OpenLogFile(const std::string& logFilename, const std::string& backupOldLogToFilename); + void CloseLogFile(void); + bool WriteStringToLog(const std::string& logString); + void PrintDebugString(const std::string& debugString); + static void GetCurrentLocalTime(int& hour, int& minute, int& second); +private: + FILEWRAP* m_file; +}; |