Add JSON stubs, remove a bunch of now obsolete code.

Originally committed to SVN as r5113.
This commit is contained in:
Amar Takhar 2011-01-03 13:20:53 +00:00
parent e35badd20a
commit 4118580bb6
6 changed files with 65 additions and 148 deletions

View file

@ -145,33 +145,33 @@ public:
/// CPU ID string
/// @return CPU ID
/// @retval Any, ex: Intel(R) Pentium(R) M processor 1600MHz
virtual wxString CPUId()=0;
virtual std::string CPUId()=0;
/// CPU Speed
/// @return Speed
/// @retval Integer
virtual wxString CPUSpeed()=0;
virtual std::string CPUSpeed()=0;
/// CPU Count
/// @return Count
/// @retval Integer
virtual wxString CPUCount()=0;
virtual int CPUCount()=0;
/// CPU Cores
/// @return Cores
/// @retval Integer
virtual wxString CPUCores()=0;
virtual int CPUCores()=0;
/// CPU Features
/// @return Features set 1
/// @retval FPU,VME,DE,PSE,TSC,MSR...
virtual wxString CPUFeatures()=0;
virtual std::string CPUFeatures()=0;
/// CPU Features2
/// @return Features set 2
/// @retval CPU-specific features
/// @note "EST,TM2" on my P-M, or "SYSCALL,NX,MMX+,LM,3DNow!+,3DNow!" on an Opteron
virtual wxString CPUFeatures2()=0;
virtual std::string CPUFeatures2()=0;
/// System memory
/// @return Memory
@ -257,7 +257,7 @@ public:
/// <file version="[version]">[name]</file>
/// </lib>
/// \endverbatim
virtual wxString UnixLibraries()=0;
virtual std::string UnixLibraries()=0;
/// Desktop environment
/// @return Environment

View file

@ -29,14 +29,14 @@ public:
wxString DesktopEnvironment();
// Hardware
virtual wxString CPUId() { return ""; }
virtual wxString CPUSpeed() { return ""; }
virtual wxString CPUCores() { return ""; }
virtual wxString CPUCount() { return ""; }
virtual wxString CPUFeatures() { return ""; }
virtual wxString CPUFeatures2() { return ""; }
virtual std::string CPUId() { return ""; }
virtual std::string CPUSpeed() { return ""; }
virtual int CPUCores() { return 0; }
virtual int CPUCount() { return 0; }
virtual std::string CPUFeatures() { return ""; }
virtual std::string CPUFeatures2() { return ""; }
virtual uint64_t Memory() { return 0; }
// Unix Specific
virtual wxString UnixLibraries() { return ""; };
virtual std::string UnixLibraries() { return ""; };
};

View file

@ -32,33 +32,33 @@ extern "C" {
#include "platform_unix_bsd.h"
wxString PlatformUnixBSD::CPUId() {
std::string PlatformUnixBSD::CPUId() {
char id[300];
size_t len = sizeof(id);
sysctlbyname("hw.model", &id, &len, NULL, 0);
return wxString::Format("%s", id);
return id;
};
wxString PlatformUnixBSD::CPUSpeed() {
std::string PlatformUnixBSD::CPUSpeed() {
return "";
};
wxString PlatformUnixBSD::CPUCores() {
return "";
int PlatformUnixBSD::CPUCores() {
return 0;
};
wxString PlatformUnixBSD::CPUCount() {
int PlatformUnixBSD::CPUCount() {
int proc;
size_t len = sizeof(proc);
sysctlbyname("hw.ncpu", &proc, &len, NULL, 0);
return wxString::Format("%d", proc);
return proc;
};
wxString PlatformUnixBSD::CPUFeatures() {
std::string PlatformUnixBSD::CPUFeatures() {
return "";
};
wxString PlatformUnixBSD::CPUFeatures2() {
std::string PlatformUnixBSD::CPUFeatures2() {
return "";
};
@ -69,6 +69,6 @@ uint64_t PlatformUnixBSD::Memory() {
return memory;
};
wxString PlatformUnixBSD::UnixLibraries() {
std::string PlatformUnixBSD::UnixLibraries() {
return "";
};

View file

@ -27,14 +27,14 @@ public:
virtual ~PlatformUnixBSD() {};
// Hardware
virtual wxString CPUId();
virtual wxString CPUSpeed();
virtual wxString CPUCores();
virtual wxString CPUCount();
virtual wxString CPUFeatures();
virtual wxString CPUFeatures2();
virtual std::string CPUId();
virtual std::string CPUSpeed();
virtual int CPUCores();
virtual int CPUCount();
virtual std::string CPUFeatures();
virtual std::string CPUFeatures2();
virtual uint64_t Memory();
// Unix Specific
virtual wxString UnixLibraries();
virtual std::string UnixLibraries();
};

View file

@ -86,139 +86,56 @@ Report::XMLReport Report::ReportCreate() {
json::Object cpu;
cpu["Id"] = json::String();
cpu["Speed"] = json::String();
cpu["Count"] = json::String();
cpu["Cores"] = json::String();
cpu["Features"] = json::String();
cpu["Features2"] = json::String();
cpu["Id"] = json::String(p->CPUId());
cpu["Speed"] = json::String(p->CPUSpeed());
cpu["Count"] = json::Number(p->CPUCount());
cpu["Cores"] = json::Number(p->CPUCores());
cpu["Features"] = json::String(p->CPUFeatures());
cpu["Features2"] = json::String(p->CPUFeatures2());
json::Object display;
// display["Depth"] = json::Number(p->DisplayDepth());
// display["Colour"] = json::Number(p->DisplayColour());
// display["Size"] = json::String(p->DisplaySize());
// display["Pixels Per Inch"] = json::Number(p->DisplayPPI());
/*
wxXmlNode *cpu = new wxXmlNode(wxXML_ELEMENT_NODE, CPU);
doc.hardware->AddChild(cpu);
Add(cpu, Id, p->CPUId());
Add(cpu, Speed, p->CPUSpeed());
Add(cpu, Count, p->CPUCount());
Add(cpu, Cores, p->CPUCores());
Add(cpu, Features, p->CPUFeatures());
Add(cpu, Features2, p->CPUFeatures2());
wxXmlNode *display = new wxXmlNode(wxXML_ELEMENT_NODE, Display);
doc.hardware->AddChild(display);
Add(display, Depth, p->DisplayDepth());
Add(display, Colour Screen, p->DisplayColour());
Add(display, Size, p->DisplaySize());
Add(display, Pixels Per Inch, p->DisplayPPI());
// json::Object gl;
// gl["Vendor"] = json::String(p->OpenGLVendor());
// gl["Renderer"] = json::String(p->OpenGLRenderer());
// gl["Version"] = json::String(p->OpenGLVersion());
// gl["Extensions"] = json::String(p->OpenGLExt());
// display["OpenGL"] = gl;
wxXmlNode *display_gl = new wxXmlNode(wxXML_ELEMENT_NODE, OpenGL);
display->AddChild(display_gl);
Add(display_gl, Vendor, p->OpenGLVendor());
Add(display_gl, Renderer, p->OpenGLRenderer());
Add(display_gl, Version, p->OpenGLVersion());
Add(display_gl, Extensions, p->OpenGLExt());
#ifdef __WINDOWS__
doc.windows = new wxXmlNode(wxXML_ELEMENT_NODE, Windows);
doc.report->AddChild(doc.windows);
Add(doc.windows, Service Pack, p->ServicePack());
Add(doc.windows, Graphics Driver Version, p->DriverGraphicsVersion());
Add(doc.windows, DirectShow Filters, p->DirectShowFilters());
Add(doc.windows, AntiVirus Installed, p->AntiVirus());
Add(doc.windows, Firewall Installed, p->Firewall());
Add(doc.windows, DLL, p->DLLVersions());
json::Object windows;
windows["Service Pack"] = json::String();
windows["Graphics Driver Version"] = json::String();
windows["DirectShow Filters"] = json::String();
windows["AntiVirus Installed"] = json::Boolean();
windows["Firewall Installed"] = json::Boolean();
windows["DLL"] = json::String();
#endif
#ifdef __UNIX__
doc.unixx = new wxXmlNode(wxXML_ELEMENT_NODE, Unix);
doc.report->AddChild(doc.unixx);
Add(doc.unixx, Desktop Environment, p->DesktopEnvironment());
Add(doc.unixx, Libraries, p->UnixLibraries());
json::Object u_nix;
// u_nix["Desktop Environment"] = json::String(p->DesktopEnvironment());
// u_nix["Libraries"] = json::String(p->UnixLibraries());
#endif
#ifdef __APPLE__
doc.osx = new wxXmlNode(wxXML_ELEMENT_NODE, OS X);
doc.report->AddChild(doc.osx);
Add(doc.osx, Patch, p->PatchLevel());
Add(doc.osx, QuickTime Extensions, p->QuickTimeExt());
Add(doc.osx, Model, p->HardwareModel());
json::Object osx;
osx["Patch"] = json::String(p->PatchLevel());
osx["QuickTime Extensions"] = json::String(p->QuickTimeExt());
osx["Model"] = json::String(p->HardwareModel());
#endif
*/
return doc;
}
/// @brief Add a new XML node.
/// @param parent Parent nodee
/// @param node Name of the new node
/// @param text Contents
void Report::Add(wxXmlNode *parent, wxString node, wxString text) {
// Using AddChild() keeps the nodes in their natural order. It's slower but our
// document is pretty small. Doing it the faster way results in reverse-ordered nodes.
wxXmlNode *tmp = new wxXmlNode(wxXML_ELEMENT_NODE, node);
tmp->AddChild(new wxXmlNode(wxXML_TEXT_NODE, node, text));
parent->AddChild(tmp);
}
/// @brief Recursive function to populate listView and text-based for Clipboard.
/// @param node Node to parse.
/// @param listView wxListView to populate.
void Report::ProcessNode(wxXmlNode *node, wxString *text, wxListView *listView) {
wxString node_name;
nameMap::iterator names;
nameMap nMap = HumanNames();
wxXmlNode *child = node->GetChildren();
while (child) {
wxString name = child->GetName();
if ((names = nMap.find(name)) != nMap.end()) {
node_name = locale->GetString(names->second);
} else {
wxLogDebug("Report::ProcessNode Unknown node found: \"%s\" (add it to nMap)\n", name);
node_name = name;
}
wxListItem column;
int row = listView->GetItemCount();
int depth = child->GetDepth();
if (child->GetChildren()->GetType() == wxXML_ELEMENT_NODE) {
int font_size = 15 - floor(depth * 2 + 0.5);
int bgcolour = 155 + (depth * 20);
listView->InsertItem(row,node_name);
listView->SetItemFont(row, wxFont(font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
listView->SetItemBackgroundColour(row, wxColour(bgcolour,bgcolour,bgcolour, wxALPHA_OPAQUE));
if (depth == 1) text->Append("\n");
text->Append(wxString::Format("%s\n", node_name.Pad((depth*2)-2, ' ', 0)));
ProcessNode(child, text, listView);
} else {
wxString content = child->GetNodeContent();
listView->InsertItem(row,node_name);
listView->SetItem(row,1, content);
text->Append(wxString::Format("%-22s: %s\n", node_name.Pad((depth*2)-2, ' ', 0), content));
}
child = child->GetNext();
}
}
void Report::Fill(wxString *text, wxListView *listView) {
listView->InsertColumn(0, _("Entry"), wxLIST_FORMAT_RIGHT);
listView->InsertColumn(1, _("Text"), wxLIST_FORMAT_LEFT, 100);
ProcessNode(doc.report, text, listView);
listView->SetColumnWidth(0, wxLIST_AUTOSIZE);
listView->SetColumnWidth(1, wxLIST_AUTOSIZE);
}
/// @brief Return Report as Text for the Clipboard.
void Report::Save(wxString file) {
doc.doc->Save(file);

View file

@ -41,7 +41,7 @@ View::View(wxWindow *frame, Report *r)
// Fill the list with the actual report.
text = new wxString();
r->Fill(text, listView);
// r->Fill(text, listView);
listSizer->Add(listView, 1, wxEXPAND);
topSizer->Add(listSizer, 1, wxEXPAND | wxALL, 0);