4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
45 string
get_next_param(const string
&cmd
, size_t &pos
, char sperate
= ' ');
46 string
remove_square_brackets(const string
&cmd
);
47 int get_string_in_square_brackets(const string
&cmd
, string
&context
);
53 ConfigItem
*m_config_item
= nullptr;
54 void *m_dev
= nullptr;
57 class CmdUsbCtx
: public CmdCtx
60 ~CmdUsbCtx() override
;
61 int look_for_match_device(const char * procotol
);
75 const char * const key
;
76 const char * const Error
;
79 const bool ignore_case
;
80 Param(const char *ky
, void *pD
, Type tp
, bool ignore
= true, const char *error
= nullptr) :
81 key
{ky
}, Error
{error
}, pData
{pD
}, type
{tp
}, ignore_case
{ignore
}
89 vector
<Param
> m_param
;
90 uint64_t m_timeout
= 2000;
91 bool m_lastcmd
= false;
93 bool m_NoKeyParam
= false;
94 bool m_bCheckTotalParam
= false;
97 CmdBase(char *p
) { if (p
) m_cmd
= p
; }
100 void insert_param_info(const char *key
, void *pD
, Param::Type tp
, bool ignore_case
= true, const char* err
= nullptr)
102 m_param
.emplace_back(Param
{key
, pD
, tp
, ignore_case
, err
});
105 virtual int parser_protocal(char *p
, size_t &pos
);
106 virtual int parser(char *p
= nullptr);
107 virtual int run(CmdCtx
*p
) = 0;
111 using CreateCmdObj
= shared_ptr
<CmdBase
> (*) (char *);
113 class CmdObjCreateMap
:public map
<string
, CreateCmdObj
>
119 class CmdDone
:public CmdBase
122 CmdDone(char *p
) :CmdBase(p
) { m_lastcmd
= true; }
123 int run(CmdCtx
*p
) override
;
126 class CmdDelay
:public CmdBase
130 CmdDelay(char *p
) :CmdBase(p
) {}
131 int parser(char *p
= nullptr) override
;
132 int run(CmdCtx
*p
) override
;
135 class CmdShell
: public CmdBase
142 CmdShell(char *p
) : CmdBase(p
) {}
143 int parser(char *p
= nullptr) override
;
144 int run(CmdCtx
*p
) override
;
147 class CmdList
: public std::vector
<shared_ptr
<CmdBase
>>
150 int run_all(CmdCtx
*p
, bool dry_run
= false);
153 class CmdMap
: public std::map
<std::string
, shared_ptr
<CmdList
>>
156 int run_all(const std::string
&protocal
, CmdCtx
*p
, bool dry_run
= false);
159 class CfgCmd
:public CmdBase
162 CfgCmd(char *cmd
) :CmdBase(cmd
) {}
163 int parser(char * /*p*/) override
{ return 0; }
164 int run(CmdCtx
*p
) override
;
167 int run_cmds(const char *procotal
, CmdCtx
*p
);