TrinityCore
ServiceDispatcher.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 ServiceDispatcher_h__
19#define ServiceDispatcher_h__
20
21#include "MessageBuffer.h"
22#include "AccountService.h"
25#include "club_listener.pb.h"
28#include "club_service.pb.h"
29#include "ConnectionService.h"
30#include "friends_service.pb.h"
33#include "presence_service.pb.h"
34#include "report_service.pb.h"
36#include "resource_service.pb.h"
38
39namespace Battlenet
40{
41 class Session;
42
44 {
45 public:
46 void Dispatch(Session* session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer);
47
49
50 private:
52
53 template<class Service>
55 {
56 _dispatchers[Service::OriginalHash::value] = &ServiceDispatcher::Dispatch<Service>;
57 }
58
59 template<class Service>
60 static void Dispatch(Session* session, uint32 token, uint32 methodId, MessageBuffer buffer)
61 {
62 Service(session).CallServerMethod(token, methodId, std::move(buffer));
63 }
64
66 std::unordered_map<uint32, ServiceMethod> _dispatchers;
67 };
68}
69
70#define sServiceDispatcher ServiceDispatcher::Instance()
71
72#endif // ServiceDispatcher_h__
uint32_t uint32
Definition: Define.h:142
static void Dispatch(Session *session, uint32 token, uint32 methodId, MessageBuffer buffer)
std::unordered_map< uint32, ServiceMethod > _dispatchers
void(* ServiceMethod)(Session *, uint32, uint32, MessageBuffer)
void Dispatch(Session *session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer)
static ServiceDispatcher & Instance()