• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015, Intel Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #pragma once
31 
32 #include <parameter_export.h>
33 
34 #include "ElementBuilder.h"
35 #include <log/Logger.h>
36 
37 namespace details
38 {
39 /** Part of the implementation of `TLoggingElementBuilderTemplate`
40  * that does not need to be template.
41  *
42  * If this was implemented in this header, the xmlElement implementation
43  * would leak to sources including this header.
44  *
45  * Plugins are including this header. As a result they would include
46  * the xmlElement implementation if it was not hidden in a cpp.
47  *
48  * FIXME: The xml concept (forward declared) is still leaked to the plugin.
49  *        A solution would be have two level of builders:
50  *         - a PluginBuilder that wraps the plugin
51  *         - and an ElementBuilder that wraps the PluginBuilder
52  *        This way the plugin can only see the PluginBuilder and is not
53  *        contaminated by any core specific concept.
54  *
55  * @param[in] xmlElement the XML element
56  * @return the "Name" attribute value of an xml element or
57  * empty string if attribute is not present
58  *
59  */
60 std::string PARAMETER_EXPORT getName(const CXmlElement &xmlElement);
61 }
62 
63 /**
64  * Builder for elements which need logger at construction
65  *
66  * @tparam ElementType the type of the element to build
67  */
68 template <class ElementType>
69 class TLoggingElementBuilderTemplate : public CElementBuilder
70 {
71 public:
72     /**
73      * Class Constructor
74      *
75      * @param[in] logger the logger provided by the client
76      */
TLoggingElementBuilderTemplate(core::log::Logger & logger)77     TLoggingElementBuilderTemplate(core::log::Logger &logger) : CElementBuilder(), mLogger(logger)
78     {
79     }
80 
81     /**
82      * Create a new element
83      *
84      * @param[in] xmlElement the description of the object to create
85      *
86      * @return pointer to the generated element
87      */
createElement(const CXmlElement & xmlElement)88     virtual CElement *createElement(const CXmlElement &xmlElement) const
89     {
90         return new ElementType(details::getName(xmlElement), mLogger);
91     }
92 
93 private:
94     /** Application Logger */
95     core::log::Logger &mLogger;
96 };
97