1 //===-- MICmdFactory.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Third party headers
16 #include "MICmnBase.h"
17 #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 // Authors: Illya Rudkin 19/02/2014.
32 class CMICmdFactory : public CMICmnBase, public MI::ISingleton<CMICmdFactory>
34 friend class MI::ISingleton<CMICmdFactory>;
38 typedef CMICmdBase *(*CmdCreatorFnPtr)(void);
43 // Description: Command's factory's interface for commands to implement.
48 virtual const CMIUtilString &GetMiCmd(void) const = 0;
49 virtual CmdCreatorFnPtr GetCmdCreatorFn(void) const = 0;
50 // virtual CMICmdBase * CreateSelf( void ) = 0; // Not possible as require a static creator
51 // function in the command class, here for awareness
53 /* dtor */ virtual ~ICmd(void){};
58 bool Initialize(void) override;
59 bool Shutdown(void) override;
60 bool CmdRegister(const CMIUtilString &vMiCmd, CmdCreatorFnPtr vCmdCreateFn);
61 bool CmdCreate(const CMIUtilString &vMiCmd, const SMICmdData &vCmdData, CMICmdBase *&vpNewCmd);
62 bool CmdExist(const CMIUtilString &vMiCmd) const;
66 /* ctor */ CMICmdFactory(void);
67 /* ctor */ CMICmdFactory(const CMICmdFactory &);
68 void operator=(const CMICmdFactory &);
70 bool HaveAlready(const CMIUtilString &vMiCmd) const;
71 bool IsValid(const CMIUtilString &vMiCmd) const;
76 /* dtor */ ~CMICmdFactory(void) override;
80 typedef std::map<CMIUtilString, CmdCreatorFnPtr> MapMiCmdToCmdCreatorFn_t;
81 typedef std::pair<CMIUtilString, CmdCreatorFnPtr> MapPairMiCmdToCmdCreatorFn_t;
85 MapMiCmdToCmdCreatorFn_t m_mapMiCmdToCmdCreatorFn;