1 /*
2  * Copyright (c) 2011-2014, 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 "ParameterMgrPlatformConnector.h"
33 #include "RemoteCommandHandlerTemplate.h"
34 #include "RemoteProcessorServer.h"
35 #include <string>
36 #include <iostream>
37 #include <list>
38 
39 class CParameterMgrPlatformConnectorLogger;
40 class ISelectionCriterionInterface;
41 
42 class CTestPlatform
43 {
44     typedef TRemoteCommandHandlerTemplate<CTestPlatform> CCommandHandler;
45     typedef CCommandHandler::CommandStatus CommandReturn;
46 
47 public:
48     CTestPlatform(const std::string &strclass, uint16_t iPortNumber);
49     virtual ~CTestPlatform();
50 
51     // Init
52     bool run(std::string &strError);
53 
54 private:
55     //////////////// Remote command parsers
56     /// Selection Criterion
57     CommandReturn createExclusiveSelectionCriterionFromStateList(
58         const IRemoteCommand &remoteCommand, std::string &strResult);
59     CommandReturn createInclusiveSelectionCriterionFromStateList(
60         const IRemoteCommand &remoteCommand, std::string &strResult);
61 
62     CommandReturn createExclusiveSelectionCriterion(const IRemoteCommand &remoteCommand,
63                                                     std::string &strResult);
64     CommandReturn createInclusiveSelectionCriterion(const IRemoteCommand &remoteCommand,
65                                                     std::string &strResult);
66 
67     CommandReturn getSchemaUri(const IRemoteCommand &remotecommand, std::string &result);
68     CommandReturn setSchemaUri(const IRemoteCommand &remotecommand, std::string &result);
69 
70     /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState.
71      * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return
72      *
73      * @param[in] remoteCommand the first argument should be the name of the criterion to set.
74      *                          if the criterion is provided in lexical space,
75      *                              the following arguments should be criterion new values
76      *                          if the criterion is provided in numerical space,
77      *                              the second argument should be the criterion new value
78      */
79     CommandReturn setCriterionState(const IRemoteCommand &remoteCommand, std::string &strResult);
80 
81     /** Callback to start the PFW, see CParameterMgrPlatformConnector::start.
82      * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return
83      *
84      * @param[in] remoteCommand is ignored
85      */
86     CommandReturn startParameterMgr(const IRemoteCommand &remoteCommand, std::string &strResult);
87 
88     /** Callback to apply PFW configuration, see CParameterMgrPlatformConnector::applyConfiguration.
89      * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return
90      *
91      * @param[in] remoteCommand is ignored
92      *
93      * @return EDone (never fails)
94      */
95     CommandReturn applyConfigurations(const IRemoteCommand &remoteCommand, std::string &strResult);
96 
97     /** Callback to exit the test-platform.
98      *
99      * @param[in] remoteCommand is ignored
100      *
101      * @return EDone (never fails)
102      */
103     CommandReturn exit(const IRemoteCommand &remoteCommand, std::string &strResult);
104 
105     /** The type of a CParameterMgrPlatformConnector boolean setter. */
106     typedef bool (CParameterMgrPlatformConnector::*setter_t)(bool, std::string &);
107     /** Template callback to create a _pParameterMgrPlatformConnector boolean setter callback.
108      * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return
109      *
110      * Convert the remoteCommand first argument to a boolean and call the
111      * template parameter function with this value.
112      *
113      * @tparam the boolean setter method.
114      * @param[in] remoteCommand the first argument should be ether "on" or "off".
115      */
116     template <setter_t setFunction>
117     CommandReturn setter(const IRemoteCommand &remoteCommand, std::string &strResult);
118 
119     /** The type of a CParameterMgrPlatformConnector boolean getter. */
120     typedef bool (CParameterMgrPlatformConnector::*getter_t)() const;
121     /** Template callback to create a ParameterMgrPlatformConnector boolean getter callback.
122      * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return
123      *
124      * Convert to boolean returned by the template parameter function converted to a
125      * std::string ("True", "False") and return it.
126      *
127      * @param the boolean getter method.
128      * @param[in] remoteCommand is ignored
129      *
130      * @return EDone (never fails)
131      */
132     template <getter_t getFunction>
133     CommandReturn getter(const IRemoteCommand &remoteCommand, std::string &strResult);
134 
135     // Commands
136     bool createExclusiveSelectionCriterionFromStateList(const std::string &strName,
137                                                         const IRemoteCommand &remoteCommand,
138                                                         std::string &strResult);
139     bool createInclusiveSelectionCriterionFromStateList(const std::string &strName,
140                                                         const IRemoteCommand &remoteCommand,
141                                                         std::string &strResult);
142 
143     bool createExclusiveSelectionCriterion(const std::string &strName, size_t nbValues,
144                                            std::string &strResult);
145     bool createInclusiveSelectionCriterion(const std::string &strName, size_t nbValues,
146                                            std::string &strResult);
147     bool setCriterionState(const std::string &strName, uint32_t uiState, std::string &strResult);
148     bool setCriterionStateByLexicalSpace(const IRemoteCommand &remoteCommand,
149                                          std::string &strResult);
150 
151     // Connector
152     CParameterMgrPlatformConnector mParameterMgrPlatformConnector;
153 
154     class : public CParameterMgrPlatformConnector::ILogger
155     {
156     public:
info(const std::string & log)157         virtual void info(const std::string &log) { std::cout << log << std::endl; }
158 
warning(const std::string & log)159         virtual void warning(const std::string &log) { std::cerr << log << std::endl; }
160     } mLogger;
161 
162     // Remote Processor Server
163     CRemoteProcessorServer mRemoteProcessorServer;
164 };
165