TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ServiceDispatcher.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 "MessageBuffer.h"
22 #include "Log.h"
23 #include "Common.h"
24 #include "AccountService.h"
25 #include "AuthenticationService.h"
26 #include "challenge_service.pb.h"
27 #include "channel_service.pb.h"
28 #include "ConnectionService.h"
29 #include "friends_service.pb.h"
30 #include "GameUtilitiesService.h"
31 #include "presence_service.pb.h"
32 #include "report_service.pb.h"
33 #include "resource_service.pb.h"
35 
36 namespace Battlenet
37 {
38  class Session;
39 
41  {
42  public:
43  void Dispatch(Session* session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer);
44 
45  static ServiceDispatcher& Instance();
46 
47  private:
49 
50  template<class Service>
51  void AddService()
52  {
53  _dispatchers[Service::OriginalHash::value] = &ServiceDispatcher::Dispatch<Service>;
54  }
55 
56  template<class Service>
57  static void Dispatch(Session* session, uint32 token, uint32 methodId, MessageBuffer buffer)
58  {
59  Service(session).CallServerMethod(token, methodId, std::forward<MessageBuffer>(buffer));
60  }
61 
62  std::unordered_map<uint32, std::function<void(Session*, uint32, uint32, MessageBuffer)>> _dispatchers;
63  };
64 }
65 
66 #define sServiceDispatcher ServiceDispatcher::Instance()
67 
68 #endif // ServiceRegistry_h__
static void Dispatch(Session *session, uint32 token, uint32 methodId, MessageBuffer buffer)
Definition: ServiceDispatcher.h:57
void Dispatch(Session *session, uint32 serviceHash, uint32 token, uint32 methodId, MessageBuffer buffer)
Definition: ServiceDispatcher.cpp:35
Definition: method_options.pb.h:28
Definition: Service.h:29
std::unordered_map< uint32, std::function< void(Session *, uint32, uint32, MessageBuffer)> > _dispatchers
Definition: ServiceDispatcher.h:62
static ServiceDispatcher & Instance()
Definition: ServiceDispatcher.cpp:44
Definition: ServiceDispatcher.h:40
ServiceDispatcher()
Definition: ServiceDispatcher.cpp:20
uint32_t uint32
Definition: Define.h:150
void AddService()
Definition: ServiceDispatcher.h:51
Definition: Session.h:79
const FieldDescriptor value
Definition: descriptor.h:1522
Definition: MessageBuffer.h:24