TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WorldserverServiceDispatcher.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 ServiceRegistry_h__
19 #define ServiceRegistry_h__
20 
21 #include "WorldSession.h"
22 #include "MessageBuffer.h"
23 #include "Log.h"
24 #include "Common.h"
25 #include "account_service.pb.h"
27 #include "challenge_service.pb.h"
28 #include "channel_service.pb.h"
29 #include "connection_service.pb.h"
30 #include "friends_service.pb.h"
32 #include "presence_service.pb.h"
33 #include "report_service.pb.h"
34 #include "resource_service.pb.h"
36 
37 namespace Battlenet
38 {
40  {
41  public:
42  void Dispatch(WorldSession* session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer);
43 
45 
46  private:
48 
49  template<class Service>
50  void AddService()
51  {
52  _dispatchers[Service::NameHash::value] = &WorldserverServiceDispatcher::Dispatch<Service>;
53  }
54 
55  template<class Service>
56  static void Dispatch(WorldSession* session, uint32 token, uint32 methodId, MessageBuffer buffer)
57  {
58  Service(session).CallServerMethod(token, methodId, std::forward<MessageBuffer>(buffer));
59  }
60 
61  std::unordered_map<uint32, std::function<void(WorldSession*, uint32, uint32, MessageBuffer)>> _dispatchers;
62  };
63 }
64 
65 #define sServiceDispatcher Battlenet::WorldserverServiceDispatcher::Instance()
66 
67 #endif // ServiceRegistry_h__
Definition: method_options.pb.h:28
Definition: Service.h:29
Definition: WorldserverServiceDispatcher.h:39
void AddService()
Definition: WorldserverServiceDispatcher.h:50
WorldserverServiceDispatcher()
Definition: WorldserverServiceDispatcher.cpp:21
uint32_t uint32
Definition: Define.h:150
static void Dispatch(WorldSession *session, uint32 token, uint32 methodId, MessageBuffer buffer)
Definition: WorldserverServiceDispatcher.h:56
const FieldDescriptor value
Definition: descriptor.h:1522
Player session in the World.
Definition: WorldSession.h:882
void Dispatch(WorldSession *session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer)
Definition: WorldserverServiceDispatcher.cpp:36
std::unordered_map< uint32, std::function< void(WorldSession *, uint32, uint32, MessageBuffer)> > _dispatchers
Definition: WorldserverServiceDispatcher.h:61
static WorldserverServiceDispatcher & Instance()
Definition: WorldserverServiceDispatcher.cpp:45
Definition: MessageBuffer.h:24