TrinityCore
ServiceBase.cpp
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#include "ServiceBase.h"
19#include "Errors.h"
20#include "Log.h"
21#include <google/protobuf/message.h>
22
24{
25 TC_LOG_ERROR("service.protobuf", "{} Server tried to call server method {}",
26 GetCallerInfo(), methodId);
27}
28
29void ServiceBase::LogCallClientMethod(char const* methodName, char const* inputTypeName, google::protobuf::Message const* request)
30{
31 TC_LOG_DEBUG("service.protobuf", "{} Server called client method {}({}{{ {} }})",
32 GetCallerInfo(), methodName, inputTypeName, request->ShortDebugString());
33}
34
35void ServiceBase::LogCallServerMethod(char const* methodName, char const* inputTypeName, google::protobuf::Message const* request)
36{
37 TC_LOG_DEBUG("service.protobuf", "{} Client called server method {}({}{{ {} }}).",
38 GetCallerInfo(), methodName, inputTypeName, request->ShortDebugString());
39}
40
41void ServiceBase::LogUnimplementedServerMethod(char const* methodName, google::protobuf::Message const* request)
42{
43 TC_LOG_ERROR("service.protobuf", "{} Client tried to call not implemented method {}({{ {} }})",
44 GetCallerInfo(), methodName, request->ShortDebugString());
45}
46
48{
49 TC_LOG_ERROR("service.protobuf", "Bad method id {}.", methodId);
50}
51
52void ServiceBase::LogFailedParsingRequest(char const* methodName)
53{
54 TC_LOG_DEBUG("service.protobuf", "{} Failed to parse request for {} server method call.", GetCallerInfo(), methodName);
55}
56
57std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)> ServiceBase::CreateServerContinuation(uint32 token, uint32 methodId, char const* methodName, google::protobuf::Descriptor const* outputDescriptor)
58{
59 return [token, methodId, methodName, outputDescriptor](ServiceBase* service, uint32 status, ::google::protobuf::Message const* response)
60 {
61 ASSERT(response->GetDescriptor() == outputDescriptor);
62 TC_LOG_DEBUG("service.protobuf", "{} Client called server method {}() {}{{ {} }} status {}.",
63 service->GetCallerInfo(), methodName, outputDescriptor->full_name(), response->ShortDebugString(), status);
64 if (!status)
65 service->SendResponse(service->GetServiceHash(), methodId, token, response);
66 else
67 service->SendResponse(service->GetServiceHash(), methodId, token, status);
68 };
69}
uint32_t uint32
Definition: Define.h:142
#define ASSERT
Definition: Errors.h:68
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
void LogInvalidMethod(uint32 methodId)
Definition: ServiceBase.cpp:47
void LogDisallowedMethod(uint32 methodId)
Definition: ServiceBase.cpp:23
void LogFailedParsingRequest(char const *methodName)
Definition: ServiceBase.cpp:52
virtual std::string GetCallerInfo() const =0
void LogCallClientMethod(char const *methodName, char const *inputTypeName, google::protobuf::Message const *request)
Definition: ServiceBase.cpp:29
std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> CreateServerContinuation(uint32 token, uint32 methodId, char const *methodName, google::protobuf::Descriptor const *outputDescriptor)
Definition: ServiceBase.cpp:57
void LogUnimplementedServerMethod(char const *methodName, google::protobuf::Message const *request)
Definition: ServiceBase.cpp:41
void LogCallServerMethod(char const *methodName, char const *inputTypeName, google::protobuf::Message const *request)
Definition: ServiceBase.cpp:35