TrinityCore
ServiceBase.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 ServiceBase_h__
19#define ServiceBase_h__
20
21#include "MessageBuffer.h"
22#include "Define.h"
23#include <functional>
24#include <string>
25
26namespace google
27{
28 namespace protobuf
29 {
30 class Descriptor;
31 class Message;
32 }
33}
34
36{
37public:
38 explicit ServiceBase(uint32 serviceHash) : service_hash_(serviceHash) { }
39
40 virtual ~ServiceBase() { }
41
42 virtual void CallServerMethod(uint32 token, uint32 methodId, MessageBuffer buffer) = 0;
43
44 virtual std::string GetCallerInfo() const = 0;
45
46 void LogDisallowedMethod(uint32 methodId);
47 void LogCallClientMethod(char const* methodName, char const* inputTypeName, google::protobuf::Message const* request);
48 void LogCallServerMethod(char const* methodName, char const* inputTypeName, google::protobuf::Message const* request);
49 void LogUnimplementedServerMethod(char const* methodName, google::protobuf::Message const* request);
50 void LogInvalidMethod(uint32 methodId);
51 void LogFailedParsingRequest(char const* methodName);
52
53 uint32 GetServiceHash() const { return service_hash_; }
54
55protected:
56 std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)> CreateServerContinuation(uint32 token, uint32 methodId, char const* methodName, google::protobuf::Descriptor const* outputDescriptor);
57
58 virtual void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request, std::function<void(MessageBuffer)> callback) = 0;
59 virtual void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const* request) = 0;
60 virtual void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status) = 0;
61 virtual void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const* response) = 0;
62
64};
65
66#endif // ServiceBase_h__
#define TC_PROTO_API
Definition: Define.h:105
uint32_t uint32
Definition: Define.h:142
uint32 GetServiceHash() const
Definition: ServiceBase.h:53
virtual void CallServerMethod(uint32 token, uint32 methodId, MessageBuffer buffer)=0
virtual std::string GetCallerInfo() const =0
ServiceBase(uint32 serviceHash)
Definition: ServiceBase.h:38
virtual void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const *request)=0
virtual void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status)=0
virtual ~ServiceBase()
Definition: ServiceBase.h:40
virtual void SendRequest(uint32 serviceHash, uint32 methodId, google::protobuf::Message const *request, std::function< void(MessageBuffer)> callback)=0
virtual void SendResponse(uint32 serviceHash, uint32 methodId, uint32 token, google::protobuf::Message const *response)=0
uint32 service_hash_
Definition: ServiceBase.h:63