Files
TCPlayerbotCore/src/server/shared/Threading/Callback.h
T

134 lines
2.9 KiB
C++
Raw Normal View History

2010-10-07 13:38:35 +02:00
/*
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2010-08-18 19:48:51 +02:00
#ifndef _CALLBACK_H
#define _CALLBACK_H
2009-10-17 15:51:44 -07:00
2010-08-18 19:48:51 +02:00
#include <ace/Future.h>
#include <ace/Future_Set.h>
2010-09-03 00:04:14 +02:00
#include "QueryResult.h"
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
typedef ACE_Future<QueryResult> QueryResultFuture;
2009-10-17 15:51:44 -07:00
2010-08-18 19:48:51 +02:00
/*! A simple template using ACE_Future to manage callbacks from the thread and object that
issued the request. <ParamType> is variable type of parameter that is used as parameter
for the callback function.
*/
template <typename ParamType>
class QueryCallback
2008-10-02 16:23:55 -05:00
{
2010-08-18 19:48:51 +02:00
public:
QueryCallback() {}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
void SetFutureResult(QueryResultFuture value)
{
result = value;
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
QueryResultFuture GetFutureResult()
{
2010-09-12 01:40:27 +02:00
return result;
2010-08-18 19:48:51 +02:00
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
int IsReady()
{
return result.ready();
}
2010-09-12 01:40:27 +02:00
2010-09-11 21:10:54 +02:00
void GetResult(QueryResult& res)
2010-08-18 19:48:51 +02:00
{
result.get(res);
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
void FreeResult()
{
result.cancel();
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
void SetParam(ParamType value)
{
param = value;
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
ParamType GetParam()
{
return param;
}
2010-09-12 01:40:27 +02:00
2010-08-18 19:48:51 +02:00
private:
QueryResultFuture result;
ParamType param;
};
2010-08-24 19:04:25 +02:00
template <typename ParamType1, typename ParamType2>
class QueryCallback_2
{
public:
QueryCallback_2() {}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
void SetFutureResult(QueryResultFuture value)
{
result = value;
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
QueryResultFuture GetFutureResult()
{
2010-09-12 01:40:27 +02:00
return result;
2010-08-24 19:04:25 +02:00
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
int IsReady()
{
return result.ready();
}
2010-09-12 01:40:27 +02:00
2010-09-11 21:10:54 +02:00
void GetResult(QueryResult& res)
2010-08-24 19:04:25 +02:00
{
result.get(res);
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
void FreeResult()
{
result.cancel();
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
void SetFirstParam(ParamType1 value)
{
param_1 = value;
}
void SetSecondParam(ParamType2 value)
{
param_2 = value;
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
ParamType1 GetFirstParam()
{
return param_1;
}
ParamType2 GetSecondParam()
{
return param_2;
}
2010-09-12 01:40:27 +02:00
2010-08-24 19:04:25 +02:00
private:
QueryResultFuture result;
ParamType1 param_1;
ParamType2 param_2;
};
2010-08-18 19:48:51 +02:00
#endif