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