1 //===-- MICmdInvoker.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 "MICmdData.h"
16 #include "MICmdMgrSetCmdDeleteCallback.h"
17 #include "MICmnBase.h"
18 #include "MIUtilSingletonBase.h"
22 class CMICmnStreamStdout;
25 //============================================================================
26 // Details: MI Command Invoker. The Invoker works on the command pattern design.
27 // There two main jobs; action command Execute() function, followed by
28 // the command's Acknowledge() function. When a command has finished
30 // execute function it returns to the invoker. The invoker then calls
32 // command's Acknowledge() function to do more work, form and give
33 // back a MI result. In the meantime the Command Monitor is monitoring
34 // the each command doing their Execute() function work so they do not
35 // exceed a time limit which if it exceeds informs the command(s) to
37 // The work by the Invoker is carried out in the main thread.
38 // The Invoker takes ownership of any commands created which means it
39 // is the only object to delete them when a command is finished
43 class CMICmdInvoker : public CMICmnBase,
44 public CMICmdMgrSetCmdDeleteCallback::ICallback,
45 public MI::ISingleton<CMICmdInvoker> {
46 friend class MI::ISingleton<CMICmdInvoker>;
51 // Description: Invoker's interface for commands to implement.
55 virtual bool Acknowledge() = 0;
56 virtual bool Execute() = 0;
57 virtual bool ParseArgs() = 0;
58 virtual void SetCmdData(const SMICmdData &vCmdData) = 0;
59 virtual const SMICmdData &GetCmdData() const = 0;
60 virtual const CMIUtilString &GetErrorDescription() const = 0;
61 virtual void CmdFinishedTellInvoker() const = 0;
62 virtual const CMIUtilString &GetMIResultRecord() const = 0;
63 virtual const CMIUtilString &GetMIResultRecordExtra() const = 0;
64 virtual bool HasMIResultRecordExtra() const = 0;
66 /* dtor */ virtual ~ICmd() {}
71 bool Initialize() override;
72 bool Shutdown() override;
73 bool CmdExecute(CMICmdBase &vCmd);
74 bool CmdExecuteFinished(CMICmdBase &vCmd);
78 typedef std::map<MIuint, CMICmdBase *> MapCmdIdToCmd_t;
79 typedef std::pair<MIuint, CMICmdBase *> MapPairCmdIdToCmd_t;
83 /* ctor */ CMICmdInvoker();
84 /* ctor */ CMICmdInvoker(const CMICmdInvoker &);
85 void operator=(const CMICmdInvoker &);
87 bool CmdDelete(const MIuint vCmdId, const bool vbYesDeleteCmd = false);
88 bool CmdAdd(const CMICmdBase &vCmd);
89 bool CmdStdout(const SMICmdData &vCmdData) const;
90 void CmdCauseAppExit(const CMICmdBase &vCmd) const;
95 /* dtor */ ~CMICmdInvoker() override;
96 // From CMICmdMgrSetCmdDeleteCallback::ICallback
97 void Delete(SMICmdData &vCmd) override;
101 MapCmdIdToCmd_t m_mapCmdIdToCmd;
102 CMICmnStreamStdout &m_rStreamOut;