/*-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 devdctl_event_factory.h34*/3536#ifndef _DEVDCTL_EVENT_FACTORY_H_37#define _DEVDCTL_EVENT_FACTORY_H_3839/*============================ Namespace Control =============================*/40namespace DevdCtl41{4243/*============================= Class Definitions ============================*/44/*------------------------------- EventFactory -------------------------------*/45/**46* \brief Container for "event type" => "event object" creation methods.47*/48class EventFactory49{50public:51/**52* Event creation handlers are matched by event type and a53* string representing the system emitting the event.54*/55typedef std::pair<Event::Type, std::string> Key;5657/** Map type for Factory method lookups. */58typedef std::map<Key, Event::BuildMethod *> Registry;5960/** Table record of factory methods to add to our registry. */61struct Record62{63Event::Type m_type;64const char *m_subsystem;65Event::BuildMethod *m_buildMethod;66};6768const Registry &GetRegistry() const;69Event *Build(Event::Type type, NVPairMap &nvpairs,70const std::string eventString) const;7172EventFactory(Event::BuildMethod *defaultBuildMethod = NULL);7374void UpdateRegistry(Record regEntries[], size_t numEntries);757677protected:78/** Registry of event factory methods providing O(log(n)) lookup. */79Registry m_registry;8081Event::BuildMethod *m_defaultBuildMethod;82};8384inline const EventFactory::Registry &85EventFactory::GetRegistry() const86{87return (m_registry);88}8990} // namespace DevdCtl91#endif /*_DEVDCTL_EVENT_FACTORY_H_ */929394