TrinityCore
Loading...
Searching...
No Matches
Service.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_BNET_SERVICE_H
19#define TRINITYCORE_BNET_SERVICE_H
20
21#include "MessageBuffer.h"
22#include <functional>
23#include <string>
24
26{
27class Message;
28}
29
30namespace bgs::protocol { }
31using namespace bgs::protocol;
32
33namespace Battlenet
34{
35 class Session;
36
38 {
39 protected:
40 explicit ServiceBaseCaller(Session* session) : _session(session) { }
41
42 void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)>&& callback);
43 void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request);
44 void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status);
45 void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const* response);
46 std::string GetCallerInfo() const;
47
49 };
50
51 template<class T>
52 class Service : public T, public ServiceBaseCaller
53 {
54 public:
55 explicit Service(Session* session) : T(true), ServiceBaseCaller(session) { }
56
57 protected:
58 void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)> callback) override
59 {
60 ServiceBaseCaller::SendRequest(serviceHash, methodId, request, std::move(callback));
61 }
62
63 void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request) override
64 {
65 ServiceBaseCaller::SendRequest(serviceHash, methodId, request);
66 }
67
68 void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status) override
69 {
70 ServiceBaseCaller::SendResponse(serviceHash, methodId, token, status);
71 }
72
73 void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const* response) override
74 {
75 ServiceBaseCaller::SendResponse(serviceHash, methodId, token, response);
76 }
77
78 std::string GetCallerInfo() const override
79 {
81 }
82 };
83}
84
85#endif // TRINITYCORE_BNET_SERVICE_H
uint32_t uint32
Definition Define.h:154
void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status)
Definition Service.cpp:31
std::string GetCallerInfo() const
Definition Service.cpp:41
ServiceBaseCaller(Session *session)
Definition Service.h:40
void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const *request, std::function< void(MessageBuffer)> &&callback)
Definition Service.cpp:21
Service(Session *session)
Definition Service.h:55
void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const *response) override
Definition Service.h:73
void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const *request) override
Definition Service.h:63
std::string GetCallerInfo() const override
Definition Service.h:78
void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const *request, std::function< void(MessageBuffer)> callback) override
Definition Service.h:58
void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status) override
Definition Service.h:68