svn commit: r256453 - projects/zfsd/head/cddl/sbin/zfsd
Alan Somers
asomers at FreeBSD.org
Mon Oct 14 20:56:52 UTC 2013
Author: asomers
Date: Mon Oct 14 20:56:51 2013
New Revision: 256453
URL: http://svnweb.freebsd.org/changeset/base/256453
Log:
In the static method CaseFile::DeSerializeFile(), break out the acutal parsing
of the serialization stream into the instance method
CaseFile::DeSerialize(ifstream &caseStream).
cddl/sbin/zfsd/case_file.h:
Declaration of CaseFile::DeSerialize().
cddl/sbin/zfsd/case_file.cc:
o Factor out CaseFile::DeSerialize() from
CaseFile::DeSerializeFile().
o In CaseFile::DeSerialize() remove a superfluous
return statement after a throw.
Submitted by: gibbs
Approved by: ken (mentor)
Sponsored by: Spectra Logic Corporation
Modified:
projects/zfsd/head/cddl/sbin/zfsd/case_file.cc
projects/zfsd/head/cddl/sbin/zfsd/case_file.h
Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/case_file.cc Mon Oct 14 20:53:51 2013 (r256452)
+++ projects/zfsd/head/cddl/sbin/zfsd/case_file.cc Mon Oct 14 20:56:51 2013 (r256453)
@@ -552,7 +552,6 @@ void
CaseFile::DeSerializeFile(const char *fileName)
{
string fullName(s_caseFilePath + '/' + fileName);
- string evString;
CaseFile *existingCaseFile(NULL);
CaseFile *caseFile(NULL);
@@ -603,50 +602,11 @@ CaseFile::DeSerializeFile(const char *fi
}
ifstream caseStream(fullName.c_str());
- if (!caseStream) {
+ if (!caseStream)
throw ZfsdException("CaseFile::DeSerialize: Unable to "
"read %s.\n", fileName);
- return;
- }
- stringstream fakeDevdSocket(stringstream::in|stringstream::out);
- IstreamReader caseReader(&fakeDevdSocket);
- /* Re-load EventData */
- EventBuffer eventBuffer(caseReader);
- caseStream >> std::noskipws >> std::ws;
- while (!caseStream.eof()) {
- /*
- * Outline:
- * read the beginning of a line and check it for
- * "tentative". If found, discard "tentative".
- * Shove into fakeDevdSocket.
- * call ExtractEvent
- * continue
- */
- DevCtlEventList* destEvents;
- string tentFlag("tentative ");
- string line;
- std::stringbuf lineBuf;
- caseStream.get(lineBuf);
- caseStream.ignore(); /*discard the newline character*/
- line = lineBuf.str();
- if (line.compare(0, tentFlag.size(), tentFlag) == 0) {
- line.erase(0, tentFlag.size());
- destEvents = &caseFile->m_tentativeEvents;
- } else {
- destEvents = &caseFile->m_events;
- }
- fakeDevdSocket << line;
- fakeDevdSocket << '\n';
- while (eventBuffer.ExtractEvent(evString)) {
- DevCtlEvent *event(DevCtlEvent::CreateEvent(
- evString));
- if (event != NULL) {
- destEvents->push_back(event);
- caseFile->RegisterCallout(*event);
- }
- }
- }
+ caseFile->DeSerialize(caseStream);
} catch (const ParseException &exp) {
exp.Log();
@@ -759,6 +719,50 @@ CaseFile::Serialize()
}
void
+CaseFile::DeSerialize(ifstream &caseStream)
+{
+ stringstream fakeDevdSocket(stringstream::in|stringstream::out);
+ IstreamReader caseReader(&fakeDevdSocket);
+ EventBuffer eventBuffer(caseReader);
+ string evString;
+
+ caseStream >> std::noskipws >> std::ws;
+ while (!caseStream.eof()) {
+ /*
+ * Outline:
+ * read the beginning of a line and check it for
+ * "tentative". If found, discard "tentative".
+ * Shove into fakeDevdSocket.
+ * call ExtractEvent
+ * continue
+ */
+ DevCtlEventList* destEvents;
+ string tentFlag("tentative ");
+ string line;
+ std::stringbuf lineBuf;
+
+ caseStream.get(lineBuf);
+ caseStream.ignore(); /*discard the newline character*/
+ line = lineBuf.str();
+ if (line.compare(0, tentFlag.size(), tentFlag) == 0) {
+ line.erase(0, tentFlag.size());
+ destEvents = &m_tentativeEvents;
+ } else {
+ destEvents = &m_events;
+ }
+ fakeDevdSocket << line;
+ fakeDevdSocket << '\n';
+ while (eventBuffer.ExtractEvent(evString)) {
+ DevCtlEvent *event(DevCtlEvent::CreateEvent(evString));
+ if (event != NULL) {
+ destEvents->push_back(event);
+ RegisterCallout(*event);
+ }
+ }
+ }
+}
+
+void
CaseFile::Close()
{
/*
Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.h
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/case_file.h Mon Oct 14 20:53:51 2013 (r256452)
+++ projects/zfsd/head/cddl/sbin/zfsd/case_file.h Mon Oct 14 20:56:51 2013 (r256453)
@@ -255,6 +255,13 @@ protected:
void Serialize();
/**
+ * \brief Retrieve event data from a serialization stream.
+ *
+ * \param caseStream The serializtion stream to parse.
+ */
+ void DeSerialize(std::ifstream &caseStream);
+
+ /**
* \brief Serializes the supplied event list and writes it to fd
*
* \param prefix If not NULL, this prefix will be prepended to
More information about the svn-src-projects
mailing list