Commit db0b61ff authored by Martin Marinov's avatar Martin Marinov
Browse files

Add Progress:Context::set_abort_allowed() which provides a control to turn...

Add Progress:Context::set_abort_allowed() which provides a control to turn on/off the abort functionality. Disable the control by default. Add PROGRESS_ALLOW_ABORT to enable abort in a scope. This allows the operation to turn on abort processing only inside exception-handled scopes.
parent 972cd1f0
......@@ -11,12 +11,14 @@ namespace Progress {
/// Context implementation
Context::Context()
: abrt_stte_(AST_NONE), phny_root_("phony"),
: abrt_stte_(AST_NONE), abrt_alwd_(false), phny_root_("phony"),
root_node_(&phny_root_), actv_node_(&phny_root_)
{}
void Context::abort()
{
if (!abrt_alwd_)
return;
abrt_stte_ = AST_PROCESSING;
BASE_THROW_ERROR(PROGRESS_ABORTED);
}
......
......@@ -103,6 +103,9 @@ public:
void enter_node(Node* _node);
void exit_node();
void set_abort_allowed(bool _abrt_alwd) { abrt_alwd_ = _abrt_alwd; }
bool abort_allowed() const { return abrt_alwd_; }
private:
enum AbortStateType
{
......@@ -113,6 +116,7 @@ private:
private:
AbortStateType abrt_stte_; //!< Abort state
bool abrt_alwd_; //!< Abort allowed flag, ignores AST_REQUEST if false
Node phny_root_; //!< "phony" root
Node* root_node_; //!< Root node
Node* actv_node_; //!< Active node
......@@ -125,6 +129,31 @@ private:
//! the current thread Progress context
extern thread_local Context cntx;
/*!
Enable (or disable) the Context::abort() processing, use to enable abort()
processing which is disabled by default.
Use this to set up a scope in which the progress can be aborted. Such scope
should be exception-handled, unless exiting the application on abort is desired.
*/
class AbortAllowedSession
{
public:
AbortAllowedSession(const bool _abrt_alwd)
: abrt_alwd_bckp_(cntx.abort_allowed())
{
cntx.set_abort_allowed(_abrt_alwd);
}
~AbortAllowedSession()
{
cntx.set_abort_allowed(abrt_alwd_bckp_);
}
private:
bool abrt_alwd_bckp_;
};
} //namespace Progress
#define PROGRESS_NODE_NAME(OPRT) OPRT##_node
......@@ -159,6 +188,7 @@ extern thread_local Context cntx;
#define PROGRESS_TICK { Progress::cntx.tick(__PROGRESS_FUNCTION__); }
#define PROGRESS_RESUME_ABORT { Progress::cntx.resume_abort(); }
#define PROGRESS_END_ABORT { Progress::cntx.end_abort(); }
#define PROGRESS_ALLOW_ABORT Progress::AbortAllowedSession abrt_alwd_sssn(true)
#else
......@@ -168,6 +198,7 @@ extern thread_local Context cntx;
#define PROGRESS_TICK
#define PROGRESS_RESUME_ABORT
#define PROGRESS_END_ABORT
#define PROGRESS_ALLOW_ABORT
#endif// PROGRESS_ON
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment