Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Unified Diff: build_tools/debug_server/debug_server/common/rsp_session_log.cc

Issue 6312039: RSP proxy that can record session (for playback testing).... (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build_tools/debug_server/debug_server/common/rsp_session_log.cc
===================================================================
--- build_tools/debug_server/debug_server/common/rsp_session_log.cc (revision 0)
+++ build_tools/debug_server/debug_server/common/rsp_session_log.cc (revision 0)
@@ -0,0 +1,87 @@
+#include "rsp_session_log.h"
+
+#pragma warning(disable : 4996)
+
+namespace {
+void* BlobToCBuff(const debug::Blob& blob);
+} // namespace
+
+namespace rsp {
+SessionLog::SessionLog()
+ : file_(NULL) {
+}
+
+SessionLog::~SessionLog() {
+ Close();
+}
+
+bool SessionLog::OpenToWrite(const std::string& file_name) {
+ Close();
+ file_ = fopen(file_name.c_str(), "wb");
+ return (NULL != file_);
+}
+
+bool SessionLog::OpenToRead(const std::string& file_name) {
+ Close();
+ file_ = fopen(file_name.c_str(), "rb");
+ return (NULL != file_);
+ return false;
+}
+
+void SessionLog::Close() {
+ if (NULL != file_) {
+ fclose(file_);
+ file_ = NULL;
+ }
+}
+
+void SessionLog::Add(char record_type, const debug::Blob& record) {
+ if (NULL == file_)
+ return;
+
+ void* buff = BlobToCBuff(record);
+ if (NULL != buff) {
+ size_t length = record.Size() + sizeof(record_type);
+ fwrite(&length, 1, sizeof(length), file_);
+ fwrite(&record_type, 1, sizeof(record_type), file_);
+ fwrite(buff, 1, length - sizeof(record_type), file_);
+ free(buff);
+ }
+ fflush(file_);
+}
+
+bool SessionLog::GetNextRecord(char* record_type, debug::Blob* record) {
+ if (NULL == file_)
+ return false;
+
+ size_t length = 0;
+ size_t rd1 = fread(&length, 1, sizeof(length), file_);
+ size_t rd2 = fread(record_type, 1, sizeof(*record_type), file_);
+ if ((sizeof(length) != rd1) || (sizeof(*record_type) != rd2))
+ return false;
+
+ length -= sizeof(*record_type);
+ void* buff = malloc(length);
+ if (NULL == buff) {
+ fseek(file_, length, SEEK_CUR);
+ return false;
+ }
+
+ fread(buff, 1, length, file_);
+ *record = debug::Blob(buff, length);
+ free(buff);
+ return true;
+}
+} // namespace rsp
+
+namespace {
+void* BlobToCBuff(const debug::Blob& blob) {
+ size_t num = blob.Size();
+ char* buff = static_cast<char*>(malloc(num));
+ if (NULL != buff) {
+ for (size_t i = 0; i < num; i++)
+ buff[i] = blob[i];
+ }
+ return buff;
+}
+} // namespace
« no previous file with comments | « build_tools/debug_server/debug_server/common/rsp_session_log.h ('k') | build_tools/debug_server/debug_server/debug_server.sln » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698