1 //===-- MICmdFactory.h ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // Third party headers
15 #include "MICmnBase.h"
16 #include "MIUtilSingletonBase.h"
23 //============================================================================
24 // Details: MI Command Factory. Holds a list of registered MI commands that
25 // MI application understands to interpret. Creates commands objects.
26 // The Command Factory is carried out in the main thread.
29 class CMICmdFactory : public CMICmnBase, public MI::ISingleton<CMICmdFactory> {
30 friend class MI::ISingleton<CMICmdFactory>;
34 typedef CMICmdBase *(*CmdCreatorFnPtr)();
39 // Description: Command's factory's interface for commands to implement.
43 virtual const CMIUtilString &GetMiCmd() const = 0;
44 virtual CmdCreatorFnPtr GetCmdCreatorFn() const = 0;
45 // virtual CMICmdBase * CreateSelf( void ) = 0; // Not
46 // possible as require a static creator
47 // function in the command class, here for awareness
49 /* dtor */ virtual ~ICmd() {}
54 bool Initialize() override;
55 bool Shutdown() override;
56 bool CmdRegister(const CMIUtilString &vMiCmd, CmdCreatorFnPtr vCmdCreateFn);
57 bool CmdCreate(const CMIUtilString &vMiCmd, const SMICmdData &vCmdData,
58 CMICmdBase *&vpNewCmd);
59 bool CmdExist(const CMIUtilString &vMiCmd) const;
63 /* ctor */ CMICmdFactory();
64 /* ctor */ CMICmdFactory(const CMICmdFactory &);
65 void operator=(const CMICmdFactory &);
67 bool HaveAlready(const CMIUtilString &vMiCmd) const;
68 bool IsValid(const CMIUtilString &vMiCmd) const;
73 /* dtor */ ~CMICmdFactory() override;
77 typedef std::map<CMIUtilString, CmdCreatorFnPtr> MapMiCmdToCmdCreatorFn_t;
78 typedef std::pair<CMIUtilString, CmdCreatorFnPtr>
79 MapPairMiCmdToCmdCreatorFn_t;
83 MapMiCmdToCmdCreatorFn_t m_mapMiCmdToCmdCreatorFn;