LogSerializer.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. // LogSerializer.h: interface for the CLogSerializer class.
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. #ifndef _LOGSERIALIZER_HPP__
  17. #define _LOGSERIALIZER_HPP__
  18. #include "jlib.hpp"
  19. #include "jstring.hpp"
  20. #include "jutil.hpp" // for StringArray
  21. #include "jmutex.hpp"
  22. #include <map>
  23. #include <string>
  24. typedef std::map<std::string, std::string> GuidMap;
  25. class CLogSerializer : public CInterface
  26. {
  27. long m_ItemCount;
  28. __int64 m_bytesWritten;
  29. CriticalSection crit;
  30. protected:
  31. IFile* m_file;
  32. IFileIO* m_fileio;
  33. StringBuffer m_FileName;
  34. StringBuffer m_FilePath;
  35. protected:
  36. __int64 WroteBytes();
  37. void Init();
  38. StringBuffer& GetRolloverFileName(StringBuffer& oldFile, StringBuffer& newfile, const char* newExtension);
  39. public:
  40. bool EnsureDirectory(StringBuffer& Dir);
  41. public:
  42. CLogSerializer();
  43. CLogSerializer(const char* fileName);
  44. virtual ~CLogSerializer();
  45. void Open(const char* Directory,const char* NewFileName,const char* Prefix);
  46. void Close();
  47. void Remove();
  48. void Rollover(const char* ClosedPrefix);
  49. void Append(const char* GUID, const char* Data);
  50. void Remove(const char* GUID);
  51. virtual void SplitRecord(StringBuffer& FullStr, StringBuffer& GUID, StringBuffer& Cache){}
  52. const char* queryFileName(){return m_FileName.str();};
  53. const char* queryFilePath(){return m_FilePath.str();};
  54. void SafeRollover(const char* Directory,const char* NewFileName,const char* Prefix, const char* ClosedPrefix);
  55. };
  56. ///////////////////////////////////////////////////////////////////////////////
  57. //
  58. //////////////////////////////////////////////////////////////////////////////
  59. class CSendLogSerializer : public CLogSerializer
  60. {
  61. public:
  62. CSendLogSerializer();
  63. CSendLogSerializer(const char* fileName) : CLogSerializer(fileName)
  64. {
  65. }
  66. virtual void LoadDataMap(GuidMap& ACKMap,StringArray& MissedLogs);
  67. void LoadMap(MemoryBuffer& rawdata,StringBuffer& GUID, StringBuffer& data);
  68. };
  69. void SplitRecord(const char* FullStr, StringBuffer& GUID, StringBuffer& Cache);
  70. ///////////////////////////////////////////////////////////////////////////////
  71. //
  72. //////////////////////////////////////////////////////////////////////////////
  73. class CRecieveLogSerializer : public CLogSerializer
  74. {
  75. public:
  76. CRecieveLogSerializer();
  77. CRecieveLogSerializer(const char* fileName) : CLogSerializer(fileName){}
  78. virtual void LoadDataMap(GuidMap& GUIDmap);
  79. void LoadMap(MemoryBuffer& data,GuidMap& GUIDmap, bool printTrace = false);
  80. };
  81. #endif // !LOGSERIALIZER