Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Oct 2013 23:21:02 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r256474 - projects/zfsd/head/lib/libdevctl
Message-ID:  <201310142321.r9ENL2lJ028787@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Mon Oct 14 23:21:02 2013
New Revision: 256474
URL: http://svnweb.freebsd.org/changeset/base/256474

Log:
  Fix registration of a default event builder for the Consumer class.
  
  	lib/libdevctl/consumer.cc:
  		In Consumer::ConnectToDevd(), improve syslog output.
  
  	lib/libdevctl/event.cc:
  	lib/libdevctl/event.h:
  		Implement pure virtual method in the Event class so that it
  		can be instantiated.
  
  		Provide a generic EventBuilder method that builds generic
  		Events.  This is expected to be used by consumers of this
  		library that just need key=>value data for all events
  		received.
  
  	lib/libdevctl/event_factory.cc:
  		In EventFactory::Build, fix segmentation violation
                  when a default event builder is registered and no
                  more specific event builder is found in the factory's
                  registry.
  
  Submitted by:	gibbs
  Approved by:	ken (mentor)
  Sponsored by:	Spectra Logic Corporation

Modified:
  projects/zfsd/head/lib/libdevctl/consumer.cc
  projects/zfsd/head/lib/libdevctl/event.cc
  projects/zfsd/head/lib/libdevctl/event.h
  projects/zfsd/head/lib/libdevctl/event_factory.cc

Modified: projects/zfsd/head/lib/libdevctl/consumer.cc
==============================================================================
--- projects/zfsd/head/lib/libdevctl/consumer.cc	Mon Oct 14 23:15:58 2013	(r256473)
+++ projects/zfsd/head/lib/libdevctl/consumer.cc	Mon Oct 14 23:21:02 2013	(r256474)
@@ -98,11 +98,12 @@ Consumer::ConnectToDevd()
 	int		   sLen;
 	int		   result;
 
-	syslog(LOG_INFO, "Connecting to devd");
 	if (m_devdSockFD != -1) {
 		/* Already connected. */
+		syslog(LOG_INFO, "%s: Already connected.", __func__);
 		return (true);
 	}
+	syslog(LOG_INFO, "%s: Connecting to devd.", __func__);
 
 	memset(&devdAddr, 0, sizeof(devdAddr));
 	devdAddr.sun_family= AF_UNIX;

Modified: projects/zfsd/head/lib/libdevctl/event.cc
==============================================================================
--- projects/zfsd/head/lib/libdevctl/event.cc	Mon Oct 14 23:15:58 2013	(r256473)
+++ projects/zfsd/head/lib/libdevctl/event.cc	Mon Oct 14 23:21:02 2013	(r256474)
@@ -85,6 +85,13 @@ Event::EventTypeRecord Event::s_typeTabl
 
 //- Event Static Public Methods ------------------------------------------------
 Event *
+Event::EventBuilder(Event::Type type, NVPairMap &nvPairs,
+		    const string &eventString)
+{
+	return (new Event(type, nvPairs, eventString));
+}
+
+Event *
 Event::CreateEvent(const EventFactory &factory, const string &eventString)
 {
 	NVPairMap &nvpairs(*new NVPairMap);
@@ -186,6 +193,12 @@ Event::~Event()
 	delete &m_nvPairs;
 }
 
+Event *
+Event::DeepCopy() const
+{
+	return (new Event(*this));
+}
+
 bool
 Event::Process() const
 {

Modified: projects/zfsd/head/lib/libdevctl/event.h
==============================================================================
--- projects/zfsd/head/lib/libdevctl/event.h	Mon Oct 14 23:15:58 2013	(r256473)
+++ projects/zfsd/head/lib/libdevctl/event.h	Mon Oct 14 23:21:02 2013	(r256474)
@@ -94,6 +94,9 @@ public:
 	 */
 	typedef Event* (BuildMethod)(Type, NVPairMap &, const std::string &);
 
+	/** Generic Event object factory. */
+	static BuildMethod EventBuilder;
+
 	static Event *CreateEvent(const EventFactory &factory,
 				  const std::string &eventString);
 
@@ -168,7 +171,7 @@ public:
 	 * Create and return a fully independent clone
 	 * of this event.
 	 */
-	virtual Event *DeepCopy()			 const = 0;
+	virtual Event *DeepCopy()			 const;
 
 	/** Destructor */
 	virtual ~Event();

Modified: projects/zfsd/head/lib/libdevctl/event_factory.cc
==============================================================================
--- projects/zfsd/head/lib/libdevctl/event_factory.cc	Mon Oct 14 23:15:58 2013	(r256473)
+++ projects/zfsd/head/lib/libdevctl/event_factory.cc	Mon Oct 14 23:21:02 2013	(r256474)
@@ -90,7 +90,7 @@ EventFactory::Build(Event::Type type, NV
 	if (buildMethod == NULL)
 		return (NULL);
 
-	return ((foundMethod->second)(type, nvpairs, eventString));
+	return (buildMethod(type, nvpairs, eventString));
 }
 
 } // namespace DevCtl



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310142321.r9ENL2lJ028787>