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

135 lines
3.1 KiB
C++
Raw Normal View History

/*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2010-08-18 19:48:51 +02:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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, write to the Free Software
2010-08-18 19:48:51 +02:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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-08-18 19:48:51 +02:00
typedef ACE_Future<QueryResult_AutoPtr> 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() {}
void SetFutureResult(QueryResultFuture value)
{
result = value;
}
QueryResultFuture GetFutureResult()
{
return result;
}
int IsReady()
{
return result.ready();
}
void GetResult(QueryResult_AutoPtr& res)
2010-08-18 19:48:51 +02:00
{
result.get(res);
}
void FreeResult()
{
result.cancel();
}
void SetParam(ParamType value)
{
param = value;
}
ParamType GetParam()
{
return param;
}
private:
QueryResultFuture result;
ParamType param;
};
2010-08-24 19:04:25 +02:00
template <typename ParamType1, typename ParamType2>
class QueryCallback_2
{
public:
QueryCallback_2() {}
void SetFutureResult(QueryResultFuture value)
{
result = value;
}
QueryResultFuture GetFutureResult()
{
return result;
}
int IsReady()
{
return result.ready();
}
void GetResult(QueryResult_AutoPtr& res)
{
result.get(res);
}
void FreeResult()
{
result.cancel();
}
void SetFirstParam(ParamType1 value)
{
param_1 = value;
}
void SetSecondParam(ParamType2 value)
{
param_2 = value;
}
ParamType1 GetFirstParam()
{
return param_1;
}
ParamType2 GetSecondParam()
{
return param_2;
}
private:
QueryResultFuture result;
ParamType1 param_1;
ParamType2 param_2;
};
2010-08-18 19:48:51 +02:00
#endif