/*-1* Copyright (c) 2013 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Justin T. Gibbs (Spectra Logic Corporation)30*/3132/**33* \file event_factory.cc34*/35#include <sys/cdefs.h>36#include <sys/time.h>3738#include <list>39#include <map>40#include <string>4142#include "guid.h"43#include "event.h"44#include "event_factory.h"45/*================================== Macros ==================================*/46#define NUM_ELEMENTS(x) (sizeof(x) / sizeof(*x))4748/*============================ Namespace Control =============================*/49namespace DevdCtl50{5152/*=========================== Class Implementations ==========================*/53/*------------------------------- EventFactory -------------------------------*/54//- Event Public Methods -------------------------------------------------------55EventFactory::EventFactory(Event::BuildMethod *defaultBuildMethod)56: m_defaultBuildMethod(defaultBuildMethod)57{58}5960void61EventFactory::UpdateRegistry(Record regEntries[], size_t numEntries)62{63EventFactory::Record *rec(regEntries);64EventFactory::Record *lastRec(rec + numEntries - 1);6566for (; rec <= lastRec; rec++) {67Key key(rec->m_type, rec->m_subsystem);6869if (rec->m_buildMethod == NULL)70m_registry.erase(key);71else72m_registry[key] = rec->m_buildMethod;73}74}7576Event *77EventFactory::Build(Event::Type type, NVPairMap &nvpairs,78const std::string eventString) const79{80Key key(type, nvpairs["system"]);81Event::BuildMethod *buildMethod(m_defaultBuildMethod);8283Registry::const_iterator foundMethod(m_registry.find(key));84if (foundMethod != m_registry.end())85buildMethod = foundMethod->second;8687if (buildMethod == NULL) {88delete &nvpairs;89return (NULL);90}9192return (buildMethod(type, nvpairs, eventString));93}9495} // namespace DevdCtl969798