From 82d408374c8ece8f13b50b93ff24ab9633de14f0 Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 周二, 05 8月 2014 04:58:22 +0800
Subject: [PATCH] windows bootstrap 1

---
 src/library/base/EventRegistry.cpp |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/src/library/base/EventRegistry.cpp b/src/library/base/EventRegistry.cpp
index 26bc337..beefa29 100644
--- a/src/library/base/EventRegistry.cpp
+++ b/src/library/base/EventRegistry.cpp
@@ -8,6 +8,9 @@
 #include "EventRegistry.h"
 #include <cstddef>
 #include <string.h>
+#include <algorithm>
+
+using namespace std;
 
 namespace license {
 EventRegistry::EventRegistry() {
@@ -32,7 +35,7 @@
 
 void EventRegistry::turnLastEventIntoError() {
 	if (logs.size() > 0) {
-		logs.back().severity = SEVERITY_ERROR;
+		logs.back().severity = SVRT_ERROR;
 	}
 }
 
@@ -40,7 +43,7 @@
 	bool eventFound = false;
 	for (auto it = logs.begin(); it != logs.end(); ++it) {
 		if (it->event_type == event) {
-			it->severity = SEVERITY_ERROR;
+			it->severity = SVRT_ERROR;
 			eventFound = true;
 		}
 	}
@@ -49,13 +52,13 @@
 
 AuditEvent const * EventRegistry::getLastFailure() const {
 	const AuditEvent* result = NULL;
-	if(logs.size() == 0){
+	if (logs.size() == 0) {
 		return result;
 	}
 	auto it = logs.end();
-	do  {
+	do {
 		--it;
-		if (it->severity == SEVERITY_ERROR) {
+		if (it->severity == SVRT_ERROR) {
 			result = &(*it);
 			break;
 		}
@@ -67,7 +70,7 @@
 bool EventRegistry::isGood() const {
 	bool isGood = true;
 	for (auto it = logs.begin(); it != logs.end(); ++it) {
-		if (it->severity == SEVERITY_ERROR) {
+		if (it->severity == SVRT_ERROR) {
 			isGood = false;
 			break;
 		}
@@ -75,9 +78,10 @@
 	return isGood;
 }
 
-void EventRegistry::addError(EVENT_TYPE event){
-	addEvent(event,SEVERITY_ERROR);
+void EventRegistry::addError(EVENT_TYPE event) {
+	addEvent(event, SVRT_ERROR);
 }
+
 void EventRegistry::addEvent(EVENT_TYPE event, SEVERITY severity) {
 	AuditEvent audit;
 	audit.severity = severity;
@@ -92,9 +96,25 @@
 	AuditEvent audit;
 	audit.severity = severity;
 	audit.event_type = event;
-	strncpy(audit.param1,eventParameter.c_str(),255);
+	strncpy(audit.param1, eventParameter.c_str(), 255);
 	audit.param2[0] = '\0';
 	logs.push_back(audit);
 }
 
+bool EventRegistry::turnErrosIntoWarnings() {
+	bool eventFound = false;
+	for (auto it = logs.begin(); it != logs.end(); ++it) {
+		if (it->severity == SVRT_ERROR) {
+			it->severity = SVRT_WARN;
+			eventFound = true;
+		}
+	}
+	return eventFound;
 }
+
+void EventRegistry::exportLastEvents(AuditEvent* auditEvents, int nlogs) {
+	int sizeToCopy = min(nlogs, (int) logs.size());
+	std::copy(logs.begin(), logs.begin() + sizeToCopy, auditEvents);
+}
+}
+

--
Gitblit v1.9.1