aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Threading/Callback.h
diff options
context:
space:
mode:
authorSpp <spp@jorge.gr>2011-12-27 10:05:49 +0100
committerSpp <spp@jorge.gr>2011-12-27 10:15:27 +0100
commitfa9daaf95b9f09f3a442087cbc59abc782814c63 (patch)
treec24fe99837993c101de77df1416fde629c993817 /src/server/shared/Threading/Callback.h
parent8323027e0c15e97e5da5ec0948c447273321d43f (diff)
parent317628902462c371dc29ec984803fbfb6412402c (diff)
Merge branch 'master' into 4.x and some warning fixes
Diffstat (limited to 'src/server/shared/Threading/Callback.h')
-rwxr-xr-xsrc/server/shared/Threading/Callback.h121
1 files changed, 96 insertions, 25 deletions
diff --git a/src/server/shared/Threading/Callback.h b/src/server/shared/Threading/Callback.h
index b179b215253..6ec2f49c8ff 100755
--- a/src/server/shared/Threading/Callback.h
+++ b/src/server/shared/Threading/Callback.h
@@ -29,107 +29,178 @@ typedef ACE_Future<PreparedQueryResult> PreparedQueryResultFuture;
issued the request. <ParamType> is variable type of parameter that is used as parameter
for the callback function.
*/
-template <typename Result, typename ParamType>
+#define CALLBACK_STAGE_INVALID uint8(-1)
+
+template <typename Result, typename ParamType, bool chain = false>
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<Result> value)
{
- result = value;
+ _result = value;
}
ACE_Future<Result> 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> result;
- ParamType param;
+ ACE_Future<Result> _result;
+ ParamType _param;
+ uint8 _stage;
};
-template <typename Result, typename ParamType1, typename ParamType2>
+template <typename Result, typename ParamType1, typename ParamType2, bool chain = false>
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<Result> value)
{
- result = value;
+ _result = value;
}
ACE_Future<Result> 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()
+ {
+ SetFirstParam(NULL);
+ SetSecondParam(NULL);
+ FreeResult();
+ ResetStage();
}
private:
- ACE_Future<Result> result;
- ParamType1 param_1;
- ParamType2 param_2;
+ ACE_Future<Result> _result;
+ ParamType1 _param_1;
+ ParamType2 _param_2;
+ uint8 _stage;
};
#endif \ No newline at end of file