diff options
Diffstat (limited to 'src/server/bnetserver/Services/Service.h')
| -rw-r--r-- | src/server/bnetserver/Services/Service.h | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/src/server/bnetserver/Services/Service.h b/src/server/bnetserver/Services/Service.h index 9dcbb685a66..b4907c22bb2 100644 --- a/src/server/bnetserver/Services/Service.h +++ b/src/server/bnetserver/Services/Service.h @@ -15,31 +15,71 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef Service_h__ -#define Service_h__ +#ifndef TRINITYCORE_BNET_SERVICE_H +#define TRINITYCORE_BNET_SERVICE_H -#include "Session.h" +#include "MessageBuffer.h" +#include <functional> +#include <string> -namespace bgs { namespace protocol { } } +namespace google::protobuf +{ +class Message; +} + +namespace bgs::protocol { } using namespace bgs::protocol; namespace Battlenet { + class Session; + + class ServiceBaseCaller + { + protected: + explicit ServiceBaseCaller(Session* session) : _session(session) { } + + void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)>&& callback); + void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request); + void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status); + void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const* response); + std::string GetCallerInfo() const; + + Session* _session; + }; + template<class T> - class Service : public T + class Service : public T, public ServiceBaseCaller { public: - Service(Session* session) : T(true), _session(session) { } + explicit Service(Session* session) : T(true), ServiceBaseCaller(session) { } protected: - void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)> callback) override { _session->SendRequest(serviceHash, methodId, request, std::move(callback)); } - void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request) override { _session->SendRequest(serviceHash, methodId, request); } - void SendResponse(uint32 /*serviceHash*/, uint32 /*methodId*/, uint32 token, uint32 status) override { _session->SendResponse(token, status); } - void SendResponse(uint32 /*serviceHash*/, uint32 /*methodId*/, uint32 token, google::protobuf::Message const* response) override { _session->SendResponse(token, response); } - std::string GetCallerInfo() const override { return _session->GetClientInfo(); } + void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)> callback) override + { + ServiceBaseCaller::SendRequest(serviceHash, methodId, request, std::move(callback)); + } - Session* _session; + void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request) override + { + ServiceBaseCaller::SendRequest(serviceHash, methodId, request); + } + + void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status) override + { + ServiceBaseCaller::SendResponse(serviceHash, methodId, token, status); + } + + void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const* response) override + { + ServiceBaseCaller::SendResponse(serviceHash, methodId, token, response); + } + + std::string GetCallerInfo() const override + { + return ServiceBaseCaller::GetCallerInfo(); + } }; } -#endif // Service_h__ +#endif // TRINITYCORE_BNET_SERVICE_H |
