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