Advertisement
bueddl

Untitled

Nov 6th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. namespace core {
  2.  
  3. enum class message_type {
  4.     UNDEFINED,
  5.     EVENT,
  6.     REQUEST,
  7.     RESPONSE,
  8. };
  9.  
  10. class message
  11. {
  12. public:
  13.     const message_type type() const
  14.     {
  15.         return m_type;
  16.     }
  17.  
  18. private:
  19.     message_type m_type;
  20. };
  21.  
  22. class event : public message
  23. {
  24. public:
  25.     event(/* TODO */);
  26.  
  27. private:
  28.  
  29. };
  30.  
  31. }
  32.  
  33. // Modue API implementation
  34. class gameserver_impl : public module
  35. {
  36. protected:
  37.     void get_map_list_request(int offset, int count)
  38.     {
  39.         // THE implementation
  40.     }
  41. };
  42.  
  43. // Facade (internal API)
  44. class gameserver : protected proxy<gameserver>
  45. {
  46. public:
  47.     gameserver(gameserver_impl &impl)
  48.         : proxy<gameserver>::proxy(*this),
  49.             m_impl_handle(impl)
  50.     {
  51.     }
  52.  
  53.     void get_map_list_async(int offset, int count, void(cb*)(const game::map_list &map_list))
  54.     {
  55.         core::request ev(&gameserver_impl::get_map_list_request, offset, count);
  56.         ev.sender = ??;// TODO
  57.         ev.cb = cb;
  58.         m_impl_handle.deliver_messag(ev);
  59.     }
  60.    
  61.     game::map_list get_map_list(int offset, int count)
  62.     {
  63.         return gs_proxy.do_sync<gameserver::get_map_list_async>(offset, count);
  64.     }
  65.  
  66. private:
  67.     gameserver_impl &m_impl_handle;
  68. };
  69.  
  70. // Instanciate facade based on module instance, e.g. inside the player object
  71. gameserver m_gs(gs_module_instance);
  72. // Also possible via other, already bound, reference (facade), this is like in
  73. // case of connect handled by core
  74. ? on_connect(gameserver &gs, ? playerdata)
  75. {
  76.     player pl(playerdata); // Create player object from playerdata struct
  77.     pl.gameserver(gs); // Bind gameserver reference
  78. }
  79.  
  80. // Do an API call sync...
  81. auto map_list = m_gs.get_map_list(0, 300);
  82. // ...or async...
  83. m_gs.get_map_list_async(0, 300, []
  84.     (auto &map_list)
  85.     {
  86.  
  87.     }
  88. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement