| 1 | /* |
| 2 | * Copyright (c) 2017, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | //! |
| 23 | //! \file skuwa_factory.h |
| 24 | //! \brief Defines one template class for the management of SKU/WA/SystemInfo |
| 25 | //! |
| 26 | |
| 27 | #ifndef _SKUWA_FACTORY_H_ |
| 28 | #define _SKUWA_FACTORY_H_ |
| 29 | |
| 30 | #include <map> |
| 31 | #include <vector> |
| 32 | #include <utility> |
| 33 | #include <cstdarg> |
| 34 | #include <cstdint> |
| 35 | #include "media_class_trace.h" |
| 36 | //! |
| 37 | //! \class DeviceInfoFactory |
| 38 | //! \brief Device info factory |
| 39 | //! |
| 40 | template <class T> |
| 41 | class DeviceInfoFactory |
| 42 | { |
| 43 | public: |
| 44 | typedef T* Type; |
| 45 | typedef uint32_t KeyType; |
| 46 | typedef std::map<KeyType, Type> Creators; |
| 47 | typedef typename Creators::iterator iterator; |
| 48 | |
| 49 | //! |
| 50 | //! \brief register one value with key. |
| 51 | //! |
| 52 | //! \param [in] key |
| 53 | //! KeyType, the type alias of uint32_t |
| 54 | //! \param [in] value |
| 55 | //! T *, the type of info related with key |
| 56 | //! |
| 57 | //! |
| 58 | //! \return true is returned if it is successfully registerted with @param key |
| 59 | //! false is returned if @param key is already registered and doesn't register |
| 60 | //! |
| 61 | static bool RegisterDevice(KeyType key, Type value) |
| 62 | { |
| 63 | std::pair<iterator, bool> result = GetCreators().emplace(key, value); |
| 64 | |
| 65 | return result.second; |
| 66 | } |
| 67 | |
| 68 | //! |
| 69 | //! \brief Get the pointer of DeviceInfo registered with key. |
| 70 | //! |
| 71 | //! \param [in] key |
| 72 | //! KeyType, the type alias of std::string. |
| 73 | //! |
| 74 | //! \return the pointer of DeviceInfo is returned if @param key is found. |
| 75 | //! nullptr is returned if @param key is not found |
| 76 | //! |
| 77 | static Type LookupDevice(KeyType key) |
| 78 | { |
| 79 | Creators &creators = GetCreators(); |
| 80 | iterator creator = creators.find(key); |
| 81 | if (creator != creators.end()) |
| 82 | return creator->second; |
| 83 | |
| 84 | return nullptr; |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | |
| 89 | //! |
| 90 | //! \brief obtain the static pair table of param@ key and callback function |
| 91 | //! \details obtain the static pair table that is registerted with key and callback function |
| 92 | //! |
| 93 | |
| 94 | //! \return return the static pair table about the param @key and callback function |
| 95 | static Creators &GetCreators() |
| 96 | { |
| 97 | static Creators creators; |
| 98 | |
| 99 | return creators; |
| 100 | } |
| 101 | MEDIA_CLASS_DEFINE_END(DeviceInfoFactory) |
| 102 | }; |
| 103 | |
| 104 | #endif /* _SKUWA_FACTORY_H_ */ |