diff options
| author | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-04-02 16:24:46 +0200 |
|---|---|---|
| committer | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-04-02 16:24:46 +0200 |
| commit | 62a15a2e7cc5186661bef2ec172422989c72e5db (patch) | |
| tree | 8561ea8bfabbb1136a6ca7b222f18c7a6f343eb7 /lib/MiddleWare | |
| parent | f02f0b3c6b8801584884fb2e4da0707417374185 (diff) | |
new crash types
Diffstat (limited to 'lib/MiddleWare')
| -rw-r--r-- | lib/MiddleWare/CrashTypes.h | 110 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 77 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 14 | ||||
| -rw-r--r-- | lib/MiddleWare/Reporter.h | 2 |
4 files changed, 89 insertions, 114 deletions
diff --git a/lib/MiddleWare/CrashTypes.h b/lib/MiddleWare/CrashTypes.h index 65dff90..81e1612 100644 --- a/lib/MiddleWare/CrashTypes.h +++ b/lib/MiddleWare/CrashTypes.h @@ -5,80 +5,64 @@ #include <map> #include <vector> -typedef std::map<std::string, std::string> map_crash_t; +// SYS - system value, should not be displayed +// BIN - binary value, should be displayed +// TXT = text value, should be displayed +typedef enum { CD_SYS, CD_BIN, CD_TXT } content_crash_data_t; -typedef struct SCrashInfo -{ - std::string m_sUUID; - std::string m_sUID; - std::string m_sCount; - std::string m_sExecutable; - std::string m_sPackage; - std::string m_sDescription; - std::string m_sTime; - std::string m_sReported; - - const map_crash_t GetMap() - { - map_crash_t mci; - mci["UUID"] = m_sUUID; - mci["UID"] = m_sUID; - mci["Count"] = m_sCount; - mci["Executable"] = m_sExecutable; - mci["Package"] = m_sPackage; - mci["Description"] = m_sDescription; - mci["Time"] = m_sTime; - mci["Reported"] = m_sReported; - - return mci; - } -} crash_info_t; +const char* const type_crash_data_t_str[] = { "s", "b", "t" }; -typedef std::vector<crash_info_t> vector_crash_infos_t; +typedef enum { CI_UUID, + CI_UID, + CI_COUNT, + CI_EXECUTABLE, + CI_PACKAGE, + CI_DESCRIPTION, + CI_TIME, + CI_REPORTED, + CI_MWANALYZER, + CI_MWUID, + CI_MWUUID } item_crash_into_t; -// text value, should be displayed -#define TYPE_TXT "t" -// binary value, should be displayed -#define TYPE_BIN "b" -// system value, should not be displayed -#define TYPE_SYS "s" +const char* const item_crash_into_t_str[] = { "UUID", + "UID", + "Count", + "Executable", + "Package", + "Time", + "Reported", + "_MWAnalyzer", + "_MWUID", + "_MWUUID" }; -typedef struct CCrashFile -{ - std::string m_sType; - std::string m_sContent; -} crash_file_t; +typedef enum { CD_TYPE, CD_CONTENT } item_crash_data_t; -// < key, type, value, key, type, value, ....> +// now, size of a vecor is always 2 -> <type, content> typedef std::vector<std::string> vector_strings_t; -typedef std::map<std::string, crash_file_t> crash_report_t; +// <key, data> +typedef std::map<std::string, vector_strings_t> map_crash_data_t; + +typedef map_crash_data_t map_crash_info_t; +typedef std::vector<map_crash_info_t> vector_crash_infos_t; +typedef map_crash_data_t map_crash_report_t; -inline vector_strings_t crash_report_to_vector_strings(const crash_report_t& pCrashReport) +inline void add_crash_data_to_crash_info(map_crash_info_t& pCrashInfo, + const item_crash_into_t& pItem, + const content_crash_data_t& pType, + const std::string& pContent) { - vector_strings_t vec; - crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) - { - vec.push_back(it->first); - vec.push_back(it->second.m_sType); - vec.push_back(it->second.m_sContent); - } - return vec; + pCrashInfo[type_crash_data_t_str[pItem]].push_back(type_crash_data_t_str[pType]); + pCrashInfo[type_crash_data_t_str[pItem]].push_back(pContent); } -inline crash_report_t vector_strings_to_crash_report(const vector_strings_t& pVectorStrings) +inline void add_crash_data_to_crash_report(map_crash_report_t& pCrashReport, + const std::string& pFileName, + const content_crash_data_t& pType, + const std::string& pContent) { - unsigned int ii; - crash_report_t crashReport; - for (ii = 0; ii < pVectorStrings.size(); ii += 3) - { - crash_file_t crashFile; - std::string fileName = pVectorStrings[ii]; - crashFile.m_sType = pVectorStrings[ii + 1]; - crashFile.m_sContent = pVectorStrings[ii + 2]; - crashReport[fileName] = crashFile; - } - return crashReport; + pCrashReport[pFileName].push_back(type_crash_data_t_str[pType]); + pCrashReport[pFileName].push_back(pContent); } + #endif /* CRASHTYPES_H_ */ diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 56709db..cf2f699 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -37,7 +37,7 @@ CMiddleWare::~CMiddleWare() delete m_pPluginManager; } -void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, crash_report_t& pCrashReport) +void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport) { CDebugDump dd; dd.Open(pDebugDumpDir); @@ -57,15 +57,14 @@ void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, crash dd.InitGetNextFile(); while (dd.GetNextFile(fileName, content, isTextFile)) { - crash_file_t crashFile; - crashFile.m_sType = TYPE_TXT; if (!isTextFile) { - crashFile.m_sType = TYPE_BIN; - content = pDebugDumpDir + "/" + fileName; + add_crash_data_to_crash_report(pCrashReport, fileName, CD_BIN, pDebugDumpDir + "/" + fileName); + } + else + { + add_crash_data_to_crash_report(pCrashReport, fileName, CD_TXT, content); } - crashFile.m_sContent = content; - pCrashReport[fileName] = crashFile; } dd.Close(); } @@ -104,7 +103,7 @@ void CMiddleWare::CreateReport(const std::string& pAnalyzer, void CMiddleWare::CreateCrashReport(const std::string& pUUID, const std::string& pUID, - crash_report_t& pCrashReport) + map_crash_report_t& pCrashReport) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); database_row_t row; @@ -140,27 +139,22 @@ void CMiddleWare::CreateCrashReport(const std::string& pUUID, RunAnalyzerActions(analyzer, row.m_sDebugDumpDir); DebugDumpToCrashReport(row.m_sDebugDumpDir, pCrashReport); - crash_file_t file; - file.m_sType = TYPE_SYS; - file.m_sContent = analyzer; - pCrashReport["_MWAnalyzer"] = file; - file.m_sContent = pUID; - pCrashReport["_MWUID"] = file; - file.m_sContent = pUUID; - pCrashReport["_MWUUID"] = file; + add_crash_data_to_crash_report(pCrashReport, item_crash_into_t_str[CI_MWANALYZER], CD_SYS, analyzer); + add_crash_data_to_crash_report(pCrashReport, item_crash_into_t_str[CI_MWUID], CD_SYS, pUID); + add_crash_data_to_crash_report(pCrashReport, item_crash_into_t_str[CI_MWUUID], CD_SYS, pUUID); } -void CMiddleWare::Report(const crash_report_t& pCrashReport) +void CMiddleWare::Report(const map_crash_report_t& pCrashReport) { - if (pCrashReport.find("_MWAnalyzer") == pCrashReport.end() || - pCrashReport.find("_MWUID") == pCrashReport.end() || - pCrashReport.find("_MWUUID") == pCrashReport.end()) + if (pCrashReport.find(item_crash_into_t_str[CI_MWANALYZER]) == pCrashReport.end() || + pCrashReport.find(item_crash_into_t_str[CI_MWUID]) == pCrashReport.end() || + pCrashReport.find(item_crash_into_t_str[CI_MWUUID]) == pCrashReport.end()) { throw std::string("CMiddleWare::Report(): Important data are missing."); } - std::string analyzer = pCrashReport.find("_MWAnalyzer")->second.m_sContent; - std::string UID = pCrashReport.find("_MWUID")->second.m_sContent; - std::string UUID = pCrashReport.find("_MWUUID")->second.m_sContent;; + std::string analyzer = pCrashReport.find(item_crash_into_t_str[CI_MWANALYZER])->second[CD_CONTENT]; + std::string UID = pCrashReport.find(item_crash_into_t_str[CI_MWUID])->second[CD_CONTENT]; + std::string UUID = pCrashReport.find(item_crash_into_t_str[CI_MWUUID])->second[CD_CONTENT]; if (m_mapAnalyzerReporters.find(analyzer) != m_mapAnalyzerReporters.end()) { @@ -306,7 +300,7 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st } } -int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo) +int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); @@ -348,11 +342,11 @@ int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, crash int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir) { - crash_info_t info; + map_crash_info_t info; return SaveDebugDump(pDebugDumpDir, info); } -int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo) +int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo) { if (IsDebugDumpSaved(pDebugDumpDir)) { @@ -370,10 +364,10 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p return SaveDebugDumpToDatabase(pDebugDumpDir, pCrashInfo); } -crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID, +map_crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID, const std::string& pUID) { - crash_info_t info; + map_crash_info_t crashInfo; CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); database_row_t row; database->Connect(); @@ -388,25 +382,25 @@ crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID, catch (std::string sErr) { DeleteCrashInfo(row.m_sUUID, row.m_sUID, false); - return info; + return crashInfo; } std::string data; dd.LoadText(FILENAME_EXECUTABLE, data); - info.m_sExecutable = data; + add_crash_data_to_crash_info(crashInfo, CI_EXECUTABLE, CD_TXT, data); dd.LoadText(FILENAME_PACKAGE, data); - info.m_sPackage = data; + add_crash_data_to_crash_info(crashInfo, CI_PACKAGE, CD_TXT, data); dd.LoadText(FILENAME_DESCRIPTION, data); - info.m_sDescription = data; + add_crash_data_to_crash_info(crashInfo, CI_DESCRIPTION, CD_TXT, data); dd.Close(); - info.m_sUUID = row.m_sUUID; - info.m_sUID = row.m_sUID; - info.m_sCount = row.m_sCount; - info.m_sTime = row.m_sTime; - info.m_sReported = row.m_sReported; + add_crash_data_to_crash_info(crashInfo, CI_UUID, CD_TXT, row.m_sUUID); + add_crash_data_to_crash_info(crashInfo, CI_UID, CD_TXT, row.m_sUID); + add_crash_data_to_crash_info(crashInfo, CI_COUNT, CD_TXT, row.m_sCount); + add_crash_data_to_crash_info(crashInfo, CI_TIME, CD_TXT, row.m_sTime); + add_crash_data_to_crash_info(crashInfo, CI_REPORTED, CD_TXT, row.m_sReported); - return info; + return crashInfo; } vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID) @@ -422,11 +416,8 @@ vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID) int ii; for (ii = 0; ii < rows.size(); ii++) { - crash_info_t info = GetCrashInfo(rows[ii].m_sUUID, rows[ii].m_sUID); - if (info.m_sUUID == rows[ii].m_sUUID) - { - infos.push_back(info); - } + map_crash_info_t info = GetCrashInfo(rows[ii].m_sUUID, rows[ii].m_sUID); + infos.push_back(info); } return infos; diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h index 5eafce8..e8d5212 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/lib/MiddleWare/MiddleWare.h @@ -56,14 +56,14 @@ class CMiddleWare const std::string& pDebugDumpDir); void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir); void DebugDumpToCrashReport(const std::string& pDebugDumpDir, - crash_report_t& pCrashReport); + map_crash_report_t& pCrashReport); bool IsDebugDumpSaved(const std::string& pDebugDumpDir); int SavePackageDescriptionToDebugDump(const std::string& pDebugDumpDir); int SaveUUIDToDebugDump(const std::string& pDebugDumpDir); - int SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo); - crash_info_t GetCrashInfo(const std::string& pUUID, - const std::string& pUID); + int SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo); + map_crash_info_t GetCrashInfo(const std::string& pUUID, + const std::string& pUID); public: @@ -77,9 +77,9 @@ class CMiddleWare void CreateCrashReport(const std::string& pUUID, const std::string& pUID, - crash_report_t& pCrashReport); + map_crash_report_t& pCrashReport); - void Report(const crash_report_t& pCrashReport); + void Report(const map_crash_report_t& pCrashReport); void DeleteCrashInfo(const std::string& pUUID, const std::string& pUID, @@ -87,7 +87,7 @@ class CMiddleWare int SaveDebugDump(const std::string& pDebugDumpDir); - int SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo); + int SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo); vector_crash_infos_t GetCrashInfos(const std::string& pUID); diff --git a/lib/MiddleWare/Reporter.h b/lib/MiddleWare/Reporter.h index b3d8b8c..02fae12 100644 --- a/lib/MiddleWare/Reporter.h +++ b/lib/MiddleWare/Reporter.h @@ -31,7 +31,7 @@ class CReporter : public CPlugin public: virtual ~CReporter() {} - virtual void Report(const crash_report_t& pCrashReport) = 0; + virtual void Report(const map_crash_report_t& pCrashReport) = 0; }; #endif /* REPORTER_H_ */ |
