From 280d7f2a614b20f1188e0228a8b9de1b5f57f368 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 24 Feb 2014 10:01:01 +0100 Subject: [PATCH] CDB extension: Introduce StateNotificationBlocker. Use RAI instead of manual bookkeeping when temporarily blocking the state notifications of the extension context. Change-Id: I991a3f0ddc578058f6bce173b4fc68ce567627ab Reviewed-by: David Schulz --- src/libs/qtcreatorcdbext/extensioncontext.cpp | 28 ++++++++++++++++--- src/libs/qtcreatorcdbext/extensioncontext.h | 3 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/libs/qtcreatorcdbext/extensioncontext.cpp b/src/libs/qtcreatorcdbext/extensioncontext.cpp index 7791b1e6353..abd17e9ff21 100644 --- a/src/libs/qtcreatorcdbext/extensioncontext.cpp +++ b/src/libs/qtcreatorcdbext/extensioncontext.cpp @@ -53,6 +53,29 @@ Parameters::Parameters() : maxStringLength(10000), maxStackDepth(1000) { } +/*! \class StateNotificationBlocker + + Blocks state (stopped) notification of ExtensionContext while instantiated + + \ingroup qtcreatorcdbext +*/ + +class StateNotificationBlocker { + StateNotificationBlocker(const StateNotificationBlocker &); + StateNotificationBlocker &operator=(const StateNotificationBlocker &); + +public: + StateNotificationBlocker(ExtensionContext *ec) + : m_oldValue(ec->stateNotification()) + , m_extensionContext(ec) + { m_extensionContext->setStateNotification(false); } + ~StateNotificationBlocker() { m_extensionContext->setStateNotification(m_oldValue); } + +private: + const bool m_oldValue; + ExtensionContext *m_extensionContext; +}; + /*! \class ExtensionContext Global singleton with context. @@ -350,18 +373,15 @@ bool ExtensionContext::call(const std::string &functionCall, } // Wait until finished startRecordingOutput(); - m_stateNotification = false; + StateNotificationBlocker blocker(this); m_control->WaitForEvent(0, INFINITE); *output = stopRecordingOutput(); - m_stateNotification = true; // Crude attempt at recovering from a crash: Issue 'gN' (go with exception not handled). const bool crashed = output->find(L"This exception may be expected and handled.") != std::string::npos; if (crashed) { m_stopReason.clear(); - m_stateNotification = false; hr = m_control->Execute(DEBUG_OUTCTL_ALL_CLIENTS, "~. gN", DEBUG_EXECUTE_ECHO); m_control->WaitForEvent(0, INFINITE); - m_stateNotification = true; *errorMessage = "A crash occurred while calling: " + functionCall; return false; } diff --git a/src/libs/qtcreatorcdbext/extensioncontext.h b/src/libs/qtcreatorcdbext/extensioncontext.h index 60c9506b38c..2943b863703 100644 --- a/src/libs/qtcreatorcdbext/extensioncontext.h +++ b/src/libs/qtcreatorcdbext/extensioncontext.h @@ -116,6 +116,9 @@ public: const Parameters ¶meters() const { return m_parameters; } Parameters ¶meters() { return m_parameters; } + bool stateNotification() const { return m_stateNotification; } + void setStateNotification(bool s) { m_stateNotification = s; } + private: bool isInitialized() const;