1300906Sasomers/*- 2300906Sasomers * Copyright (c) 2013 Spectra Logic Corporation 3300906Sasomers * All rights reserved. 4300906Sasomers * 5300906Sasomers * Redistribution and use in source and binary forms, with or without 6300906Sasomers * modification, are permitted provided that the following conditions 7300906Sasomers * are met: 8300906Sasomers * 1. Redistributions of source code must retain the above copyright 9300906Sasomers * notice, this list of conditions, and the following disclaimer, 10300906Sasomers * without modification. 11300906Sasomers * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12300906Sasomers * substantially similar to the "NO WARRANTY" disclaimer below 13300906Sasomers * ("Disclaimer") and any redistribution must be conditioned upon 14300906Sasomers * including a substantially similar Disclaimer requirement for further 15300906Sasomers * binary redistribution. 16300906Sasomers * 17300906Sasomers * NO WARRANTY 18300906Sasomers * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19300906Sasomers * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20300906Sasomers * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21300906Sasomers * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22300906Sasomers * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23300906Sasomers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24300906Sasomers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25300906Sasomers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26300906Sasomers * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27300906Sasomers * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28300906Sasomers * POSSIBILITY OF SUCH DAMAGES. 29300906Sasomers * 30300906Sasomers * Authors: Justin T. Gibbs (Spectra Logic Corporation) 31300906Sasomers * 32300906Sasomers * $FreeBSD: releng/11.0/lib/libdevdctl/event_factory.h 300906 2016-05-28 17:43:40Z asomers $ 33300906Sasomers */ 34300906Sasomers 35300906Sasomers/** 36300906Sasomers * \file devdctl_event_factory.h 37300906Sasomers */ 38300906Sasomers 39300906Sasomers#ifndef _DEVDCTL_EVENT_FACTORY_H_ 40300906Sasomers#define _DEVDCTL_EVENT_FACTORY_H_ 41300906Sasomers 42300906Sasomers/*============================ Namespace Control =============================*/ 43300906Sasomersnamespace DevdCtl 44300906Sasomers{ 45300906Sasomers 46300906Sasomers/*============================= Class Definitions ============================*/ 47300906Sasomers/*------------------------------- EventFactory -------------------------------*/ 48300906Sasomers/** 49300906Sasomers * \brief Container for "event type" => "event object" creation methods. 50300906Sasomers */ 51300906Sasomersclass EventFactory 52300906Sasomers{ 53300906Sasomerspublic: 54300906Sasomers /** 55300906Sasomers * Event creation handlers are matched by event type and a 56300906Sasomers * string representing the system emitting the event. 57300906Sasomers */ 58300906Sasomers typedef std::pair<Event::Type, std::string> Key; 59300906Sasomers 60300906Sasomers /** Map type for Factory method lookups. */ 61300906Sasomers typedef std::map<Key, Event::BuildMethod *> Registry; 62300906Sasomers 63300906Sasomers /** Table record of factory methods to add to our registry. */ 64300906Sasomers struct Record 65300906Sasomers { 66300906Sasomers Event::Type m_type; 67300906Sasomers const char *m_subsystem; 68300906Sasomers Event::BuildMethod *m_buildMethod; 69300906Sasomers }; 70300906Sasomers 71300906Sasomers const Registry &GetRegistry() const; 72300906Sasomers Event *Build(Event::Type type, NVPairMap &nvpairs, 73300906Sasomers const std::string eventString) const; 74300906Sasomers 75300906Sasomers EventFactory(Event::BuildMethod *defaultBuildMethod = NULL); 76300906Sasomers 77300906Sasomers void UpdateRegistry(Record regEntries[], size_t numEntries); 78300906Sasomers 79300906Sasomers 80300906Sasomersprotected: 81300906Sasomers /** Registry of event factory methods providing O(log(n)) lookup. */ 82300906Sasomers Registry m_registry; 83300906Sasomers 84300906Sasomers Event::BuildMethod *m_defaultBuildMethod; 85300906Sasomers}; 86300906Sasomers 87300906Sasomersinline const EventFactory::Registry & 88300906SasomersEventFactory::GetRegistry() const 89300906Sasomers{ 90300906Sasomers return (m_registry); 91300906Sasomers} 92300906Sasomers 93300906Sasomers} // namespace DevdCtl 94300906Sasomers#endif /*_DEVDCTL_EVENT_FACTORY_H_ */ 95