From 2d93bd07baabce1ebd9445c94e44b255a01bf490 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Wed, 21 Dec 2011 10:22:03 +0100 Subject: Core/DBLayer: More generic implementation of callback chains, instead of using this functionality local to CharacterCreatInfo class. Will be used in other places as well. --- src/server/shared/Threading/Callback.h | 118 ++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 25 deletions(-) (limited to 'src/server/shared/Threading/Callback.h') diff --git a/src/server/shared/Threading/Callback.h b/src/server/shared/Threading/Callback.h index f8c3118ec8e..809dba729d3 100755 --- a/src/server/shared/Threading/Callback.h +++ b/src/server/shared/Threading/Callback.h @@ -29,109 +29,177 @@ typedef ACE_Future PreparedQueryResultFuture; issued the request. is variable type of parameter that is used as parameter for the callback function. */ -template +#define CALLBACK_STAGE_INVALID uint8(-1) + +template class QueryCallback { public: - QueryCallback() {} + QueryCallback() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {} //! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery void SetFutureResult(ACE_Future value) { - result = value; + _result = value; } ACE_Future GetFutureResult() { - return result; + return _result; } int IsReady() { - return result.ready(); + return _result.ready(); } void GetResult(Result& res) { - result.get(res); + _result.get(res); } void FreeResult() { - result.cancel(); + _result.cancel(); } void SetParam(ParamType value) { - param = value; + _param = value; } ParamType GetParam() { - return param; + return _param; + } + + //! Resets the stage of the callback chain + void ResetStage() + { + if (!chain) + return; + + _stage = 0; + } + + //! Advances the callback chain to the next stage, so upper level code can act on its results accordingly + void NextStage() + { + if (!chain) + return; + + ++_stage; + } + + //! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid) + uint8 GetStage() + { + return _stage; + } + + //! Resets all underlying variables (param, result and stage) + void Reset() + { + SetParam(NULL); + FreeResult(); + ResetStage(); } private: - ACE_Future result; - ParamType param; + ACE_Future _result; + ParamType _param; + uint8 _stage; }; -template +template class QueryCallback_2 { public: - QueryCallback_2() {} + QueryCallback_2() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {} //! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery void SetFutureResult(ACE_Future value) { - result = value; + _result = value; } ACE_Future GetFutureResult() { - return result; + return _result; } int IsReady() { - return result.ready(); + return _result.ready(); } void GetResult(Result& res) { - result.get(res); + _result.get(res); } void FreeResult() { - result.cancel(); + _result.cancel(); } void SetFirstParam(ParamType1 value) { - param_1 = value; + _param_1 = value; } void SetSecondParam(ParamType2 value) { - param_2 = value; + _param_2 = value; } ParamType1 GetFirstParam() { - return param_1; + return _param_1; } ParamType2 GetSecondParam() { - return param_2; + return _param_2; + } + + //! Resets the stage of the callback chain + void ResetStage() + { + if (!chain) + return; + + _stage = 0; + } + + //! Advances the callback chain to the next stage, so upper level code can act on its results accordingly + void NextStage() + { + if (!chain) + return; + + ++_stage; + } + + //! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid) + uint8 GetStage() + { + return _stage; + } + + //! Resets all underlying variables (param, result and stage) + void Reset() + { + SetParam(NULL); + FreeResult(); + ResetStage(); } private: - ACE_Future result; - ParamType1 param_1; - ParamType2 param_2; + ACE_Future _result; + ParamType1 _param_1; + ParamType2 _param_2; + uint8 _stage; }; #endif \ No newline at end of file -- cgit v1.2.3