]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdInvoker.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdInvoker.h
1 //===-- MICmdInvoker.h ------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #pragma once
10
11 // Third party headers
12 #include <map>
13
14 // In-house headers:
15 #include "MICmdData.h"
16 #include "MICmdMgrSetCmdDeleteCallback.h"
17 #include "MICmnBase.h"
18 #include "MIUtilSingletonBase.h"
19
20 // Declarations:
21 class CMICmdBase;
22 class CMICmnStreamStdout;
23
24 //++
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
29 //          its
30 //          execute function it returns to the invoker. The invoker then calls
31 //          the
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
36 //          stop work.
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
40 //          working.
41 //          A singleton class.
42 //--
43 class CMICmdInvoker : public CMICmnBase,
44                       public CMICmdMgrSetCmdDeleteCallback::ICallback,
45                       public MI::ISingleton<CMICmdInvoker> {
46   friend class MI::ISingleton<CMICmdInvoker>;
47
48   // Class:
49 public:
50   //++
51   // Description: Invoker's interface for commands to implement.
52   //--
53   class ICmd {
54   public:
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;
65
66     /* dtor */ virtual ~ICmd() {}
67   };
68
69   // Methods:
70 public:
71   bool Initialize() override;
72   bool Shutdown() override;
73   bool CmdExecute(CMICmdBase &vCmd);
74   bool CmdExecuteFinished(CMICmdBase &vCmd);
75
76   // Typedefs:
77 private:
78   typedef std::map<MIuint, CMICmdBase *> MapCmdIdToCmd_t;
79   typedef std::pair<MIuint, CMICmdBase *> MapPairCmdIdToCmd_t;
80
81   // Methods:
82 private:
83   /* ctor */ CMICmdInvoker();
84   /* ctor */ CMICmdInvoker(const CMICmdInvoker &);
85   void operator=(const CMICmdInvoker &);
86   void CmdDeleteAll();
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;
91
92   // Overridden:
93 private:
94   // From CMICmnBase
95   /* dtor */ ~CMICmdInvoker() override;
96   // From CMICmdMgrSetCmdDeleteCallback::ICallback
97   void Delete(SMICmdData &vCmd) override;
98
99   // Attributes:
100 private:
101   MapCmdIdToCmd_t m_mapCmdIdToCmd;
102   CMICmnStreamStdout &m_rStreamOut;
103 };