• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     //!
RegisterDevice(KeyType key,Type value)61     static bool RegisterDevice(KeyType key, Type value)
62     {
63         std::pair<iterator, bool> result =
64             GetCreators().insert(std::make_pair(key, value));
65 
66         return result.second;
67     }
68 
69     //!
70     //! \brief    Get the pointer of DeviceInfo registered with key.
71     //!
72     //! \param    [in] key
73     //!           KeyType, the type alias of std::string.
74     //!
75     //! \return   the pointer of DeviceInfo is returned if @param key is found.
76     //!           nullptr is returned if @param key is not found
77     //!
LookupDevice(KeyType key)78     static Type LookupDevice(KeyType key)
79     {
80         Creators &creators = GetCreators();
81         iterator  creator  = creators.find(key);
82         if (creator != creators.end())
83             return creator->second;
84 
85         return nullptr;
86     }
87 
88 private:
89 
90     //!
91     //! \brief    obtain the static pair table of param@ key and callback function
92     //! \details  obtain the static pair table that is registerted with key and callback function
93     //!
94 
95     //! \return   return the static pair table about the param @key and callback function
GetCreators()96     static Creators &GetCreators()
97     {
98         static Creators creators;
99 
100         return creators;
101     }
102 MEDIA_CLASS_DEFINE_END(DeviceInfoFactory)
103 };
104 
105 #endif /*  _SKUWA_FACTORY_H_ */
106