xref: /aosp_15_r20/external/parameter-framework/upstream/parameter/FormattedSubsystemObject.h (revision c33452fb792a5495ec310a9626f2638b053af5dd)
1*c33452fbSAndroid Build Coastguard Worker /*
2*c33452fbSAndroid Build Coastguard Worker  * Copyright (c) 2011-2015, Intel Corporation
3*c33452fbSAndroid Build Coastguard Worker  * All rights reserved.
4*c33452fbSAndroid Build Coastguard Worker  *
5*c33452fbSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without modification,
6*c33452fbSAndroid Build Coastguard Worker  * are permitted provided that the following conditions are met:
7*c33452fbSAndroid Build Coastguard Worker  *
8*c33452fbSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright notice, this
9*c33452fbSAndroid Build Coastguard Worker  * list of conditions and the following disclaimer.
10*c33452fbSAndroid Build Coastguard Worker  *
11*c33452fbSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*c33452fbSAndroid Build Coastguard Worker  * this list of conditions and the following disclaimer in the documentation and/or
13*c33452fbSAndroid Build Coastguard Worker  * other materials provided with the distribution.
14*c33452fbSAndroid Build Coastguard Worker  *
15*c33452fbSAndroid Build Coastguard Worker  * 3. Neither the name of the copyright holder nor the names of its contributors
16*c33452fbSAndroid Build Coastguard Worker  * may be used to endorse or promote products derived from this software without
17*c33452fbSAndroid Build Coastguard Worker  * specific prior written permission.
18*c33452fbSAndroid Build Coastguard Worker  *
19*c33452fbSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20*c33452fbSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*c33452fbSAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22*c33452fbSAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23*c33452fbSAndroid Build Coastguard Worker  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*c33452fbSAndroid Build Coastguard Worker  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26*c33452fbSAndroid Build Coastguard Worker  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28*c33452fbSAndroid Build Coastguard Worker  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*c33452fbSAndroid Build Coastguard Worker  */
30*c33452fbSAndroid Build Coastguard Worker #pragma once
31*c33452fbSAndroid Build Coastguard Worker 
32*c33452fbSAndroid Build Coastguard Worker #include "parameter_export.h"
33*c33452fbSAndroid Build Coastguard Worker 
34*c33452fbSAndroid Build Coastguard Worker #include "SubsystemObject.h"
35*c33452fbSAndroid Build Coastguard Worker 
36*c33452fbSAndroid Build Coastguard Worker class PARAMETER_EXPORT CFormattedSubsystemObject : public CSubsystemObject
37*c33452fbSAndroid Build Coastguard Worker {
38*c33452fbSAndroid Build Coastguard Worker public:
39*c33452fbSAndroid Build Coastguard Worker     /**
40*c33452fbSAndroid Build Coastguard Worker      * Builds a new CFormattedSubsystemObject instance, without any mapping information.
41*c33452fbSAndroid Build Coastguard Worker      *
42*c33452fbSAndroid Build Coastguard Worker      * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
43*c33452fbSAndroid Build Coastguard Worker      * @param[in] logger the logger provided by the client
44*c33452fbSAndroid Build Coastguard Worker      */
45*c33452fbSAndroid Build Coastguard Worker     CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement,
46*c33452fbSAndroid Build Coastguard Worker                               core::log::Logger &logger);
47*c33452fbSAndroid Build Coastguard Worker 
48*c33452fbSAndroid Build Coastguard Worker     /**
49*c33452fbSAndroid Build Coastguard Worker      * Builds a new CFormattedSubsystemObject instance, using a simple mapping value without Amends.
50*c33452fbSAndroid Build Coastguard Worker      *
51*c33452fbSAndroid Build Coastguard Worker      * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
52*c33452fbSAndroid Build Coastguard Worker      * @param[in] logger the logger provided by the client
53*c33452fbSAndroid Build Coastguard Worker      * @param[in] strFormattedMapping A std::string corresponding to the mapping of the element. The
54*c33452fbSAndroid Build Coastguard Worker      * std::string does not contain any Amend (%) and does not need to be formatted.
55*c33452fbSAndroid Build Coastguard Worker      */
56*c33452fbSAndroid Build Coastguard Worker     CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement,
57*c33452fbSAndroid Build Coastguard Worker                               core::log::Logger &logger, const std::string &strFormattedMapping);
58*c33452fbSAndroid Build Coastguard Worker 
59*c33452fbSAndroid Build Coastguard Worker     /**
60*c33452fbSAndroid Build Coastguard Worker      * Builds a new CFormattedSubsystemObject instance, using a mapping value containing Amends.
61*c33452fbSAndroid Build Coastguard Worker      *
62*c33452fbSAndroid Build Coastguard Worker      * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
63*c33452fbSAndroid Build Coastguard Worker      * @param[in] logger the logger provided by the client
64*c33452fbSAndroid Build Coastguard Worker      * @param[in] strMappingValue A std::string corresponding to the mapping of the element. The
65*c33452fbSAndroid Build Coastguard Worker      * std::string contains Amend (%) and needs to be formatted with information from the context.
66*c33452fbSAndroid Build Coastguard Worker      * @param[in] firstAmendKey Index of the first Amend key
67*c33452fbSAndroid Build Coastguard Worker      * @param[in] nbAmendKeys Number of Amends
68*c33452fbSAndroid Build Coastguard Worker      * @param[in] context Contains values associated to Amend keys
69*c33452fbSAndroid Build Coastguard Worker      */
70*c33452fbSAndroid Build Coastguard Worker     CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement,
71*c33452fbSAndroid Build Coastguard Worker                               core::log::Logger &logger, const std::string &strMappingValue,
72*c33452fbSAndroid Build Coastguard Worker                               size_t firstAmendKey, size_t nbAmendKeys,
73*c33452fbSAndroid Build Coastguard Worker                               const CMappingContext &context);
74*c33452fbSAndroid Build Coastguard Worker     ~CFormattedSubsystemObject() override = default;
75*c33452fbSAndroid Build Coastguard Worker 
76*c33452fbSAndroid Build Coastguard Worker     /**
77*c33452fbSAndroid Build Coastguard Worker      * Returns the formatted mapping value associated to the element.
78*c33452fbSAndroid Build Coastguard Worker      *
79*c33452fbSAndroid Build Coastguard Worker      * @return A std::string containing the mapping
80*c33452fbSAndroid Build Coastguard Worker      */
81*c33452fbSAndroid Build Coastguard Worker     std::string getFormattedMappingValue() const override;
82*c33452fbSAndroid Build Coastguard Worker 
83*c33452fbSAndroid Build Coastguard Worker private:
84*c33452fbSAndroid Build Coastguard Worker     /**
85*c33452fbSAndroid Build Coastguard Worker      * Check if the index of Amend key is valid.
86*c33452fbSAndroid Build Coastguard Worker      *
87*c33452fbSAndroid Build Coastguard Worker      * @param uiAmendKey Index of the Amend key
88*c33452fbSAndroid Build Coastguard Worker      *
89*c33452fbSAndroid Build Coastguard Worker      * @return true if the index of the Amend key is > 0 and <= 9.
90*c33452fbSAndroid Build Coastguard Worker      */
91*c33452fbSAndroid Build Coastguard Worker     static bool isAmendKeyValid(size_t uiAmendKey);
92*c33452fbSAndroid Build Coastguard Worker 
93*c33452fbSAndroid Build Coastguard Worker     /**
94*c33452fbSAndroid Build Coastguard Worker      * Generic mapping formatting
95*c33452fbSAndroid Build Coastguard Worker      *
96*c33452fbSAndroid Build Coastguard Worker      * Format a std::string from mapping data and its context, replacing amendments by their value
97*c33452fbSAndroid Build Coastguard Worker      *
98*c33452fbSAndroid Build Coastguard Worker      * @param[in] strMappingValue The input mapping std::string containing amendments
99*c33452fbSAndroid Build Coastguard Worker      * @param[in] context firstAmendKey The index of the first Amend key in the key list of the
100*c33452fbSAndroid Build Coastguard Worker      * context
101*c33452fbSAndroid Build Coastguard Worker      * @param[in] nbAmendKeys Number of Amend keys in the context
102*c33452fbSAndroid Build Coastguard Worker      * @param[in] context The context containing Amend values
103*c33452fbSAndroid Build Coastguard Worker      *
104*c33452fbSAndroid Build Coastguard Worker      * @return The formatted std::string, corresponding to the input strMappingValue where %n have
105*c33452fbSAndroid Build Coastguard Worker      * been
106*c33452fbSAndroid Build Coastguard Worker      * replaced by their value
107*c33452fbSAndroid Build Coastguard Worker      */
108*c33452fbSAndroid Build Coastguard Worker     static std::string formatMappingValue(const std::string &strMappingValue, size_t firstAmendKey,
109*c33452fbSAndroid Build Coastguard Worker                                           size_t nbAmendKeys, const CMappingContext &context);
110*c33452fbSAndroid Build Coastguard Worker 
111*c33452fbSAndroid Build Coastguard Worker     /**
112*c33452fbSAndroid Build Coastguard Worker      * std::string containing the formatted mapping value
113*c33452fbSAndroid Build Coastguard Worker      */
114*c33452fbSAndroid Build Coastguard Worker     std::string _strFormattedMappingValue;
115*c33452fbSAndroid Build Coastguard Worker };
116