#pragma once
#include <queue>
#include "MICmdData.h"
#include "MICmnBase.h"
#include "MICmnConfig.h"
#include "MICmnStreamStdin.h"
#include "MIDriverBase.h"
#include "MIDriverMgr.h"
#include "MIUtilSingletonBase.h"
class CMICmnLLDBDebugger;
class CMICmnStreamStdout;
class CMIDriver : public CMICmnBase,
public CMIDriverMgr::IDriver,
public CMIDriverBase,
public MI::ISingleton<CMIDriver> {
friend class MI::ISingleton<CMIDriver>;
public:
enum DriverState_e {
eDriverState_NotRunning = 0,
eDriverState_Initialising,
eDriverState_RunningNotDebugging,
eDriverState_RunningDebugging,
eDriverState_ShuttingDown,
eDriverState_count
};
public:
bool Initialize() override;
bool Shutdown() override;
bool GetExitApplicationFlag() const;
DriverState_e GetCurrentDriverState() const;
bool SetDriverStateRunningNotDebugging();
bool SetDriverStateRunningDebugging();
void SetDriverDebuggingArgExecutable();
bool IsDriverDebuggingArgExecutable() const;
const CMIUtilString &GetAppNameShort() const;
const CMIUtilString &GetAppNameLong() const;
const CMIUtilString &GetVersionDescription() const;
bool WriteMessageToLog(const CMIUtilString &vMessage);
bool SetEnableFallThru(const bool vbYes);
bool GetEnableFallThru() const;
bool HaveExecutableFileNamePathOnCmdLine() const;
const CMIUtilString &GetExecutableFileNamePathOnCmdLine() const;
public:
bool DoInitialize() override;
bool DoShutdown() override;
bool DoMainLoop() override;
lldb::SBError DoParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
bool &vwbExiting) override;
CMIUtilString GetError() const override;
const CMIUtilString &GetName() const override;
lldb::SBDebugger &GetTheDebugger() override;
bool GetDriverIsGDBMICompatibleDriver() const override;
bool SetId(const CMIUtilString &vId) override;
const CMIUtilString &GetId() const override;
void SetExitApplicationFlag(const bool vbForceExit) override;
bool DoFallThruToAnotherDriver(const CMIUtilString &vCmd,
CMIUtilString &vwErrMsg) override;
bool SetDriverToFallThruTo(const CMIDriverBase &vrOtherDriver) override;
FILE *GetStdin() const override;
FILE *GetStdout() const override;
FILE *GetStderr() const override;
const CMIUtilString &GetDriverName() const override;
const CMIUtilString &GetDriverId() const override;
void DeliverSignal(int signal) override;
private:
typedef std::queue<CMIUtilString> QueueStdinLine_t;
private:
CMIDriver();
CMIDriver(const CMIDriver &);
void operator=(const CMIDriver &);
lldb::SBError ParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
bool &vwbExiting);
bool DoAppQuit();
bool InterpretCommand(const CMIUtilString &vTextLine);
bool InterpretCommandThisDriver(const CMIUtilString &vTextLine,
bool &vwbCmdYesValid);
CMIUtilString
WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const;
bool InterpretCommandFallThruDriver(const CMIUtilString &vTextLine,
bool &vwbCmdYesValid);
bool ExecuteCommand(const SMICmdData &vCmdData);
bool StartWorkerThreads();
bool StopWorkerThreads();
bool InitClientIDEToMIDriver() const;
bool InitClientIDEEclipse() const;
bool LocalDebugSessionStartupExecuteCommands();
bool ExecuteCommandString(const bool vbAsyncMode);
bool ExecuteCommandFile(const bool vbAsyncMode);
private:
~CMIDriver() override;
private:
static const CMIUtilString ms_constAppNameShort;
static const CMIUtilString ms_constAppNameLong;
static const CMIUtilString ms_constMIVersion;
bool m_bFallThruToOtherDriverEnabled;
CMIUtilThreadMutex m_threadMutex;
bool m_bDriverIsExiting;
void *m_handleMainThread;
CMICmnStreamStdin &m_rStdin;
CMICmnLLDBDebugger &m_rLldbDebugger;
CMICmnStreamStdout &m_rStdOut;
DriverState_e m_eCurrentDriverState;
bool m_bHaveExecutableFileNamePathOnCmdLine;
CMIUtilString m_strCmdLineArgExecuteableFileNamePath;
bool m_bDriverDebuggingArgExecutable;
bool m_bHaveCommandStringOnCmdLine;
CMIUtilString m_strCmdLineArgCommandString;
bool m_bHaveCommandFileNamePathOnCmdLine;
CMIUtilString m_strCmdLineArgCommandFileNamePath;
};