1 // Copyright (C) 2011, 2014, 2015 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #pragma once
19 #ifndef GAMELIST_CLIENT_H
20 #define GAMELIST_CLIENT_H
21 
22 #include <config.h>
23 
24 #include <list>
25 #include <memory>
26 #include <sigc++/trackable.h>
27 #include <sigc++/signal.h>
28 #include <glibmm.h>
29 class XML_Helper;
30 class NetworkConnection;
31 class RecentlyPlayedGame;
32 class RecentlyPlayedGameList;
33 class Profile;
34 
35 //! Sends queries to and receives responses from the GamelistServer.
36 class GamelistClient
37 {
38 public:
39 
40   //! Returns the singleton instance.  Creates a new one if neccessary.
41   static GamelistClient* getInstance();
42 
43   //! Deletes the singleton instance.
44   static void deleteInstance();
45 
46   void start(Glib::ustring host, guint32 port, Profile *p);
47   void disconnect();
48 
49   void request_game_list();
50   sigc::signal<void, RecentlyPlayedGameList*, Glib::ustring> received_game_list;
51 
52   void request_advertising(RecentlyPlayedGame *game);
53   sigc::signal<void, Glib::ustring, Glib::ustring> received_advertising_response;
54 
55   void request_advertising_removal(Glib::ustring scenario_id);
56   sigc::signal<void, Glib::ustring, Glib::ustring> received_advertising_removal_response;
57 
58   void request_reload();
59   sigc::signal<void, Glib::ustring> received_reload_response;
60 
61   void request_server_terminate();
62 
63   sigc::signal<void> client_connected;
64   sigc::signal<void> client_disconnected;
65   sigc::signal<void> client_forcibly_disconnected; //server went away
66   sigc::signal<void> client_could_not_connect;
67 
getHost()68   Glib::ustring getHost() const{return d_host;};
getPort()69   guint32 getPort() const{return d_port;};
70 
71 protected:
72   GamelistClient();
~GamelistClient()73   ~GamelistClient() {};
74 
75 private:
76   NetworkConnection* network_connection;
77 
78   void onConnected();
79   void onConnectionFailed();
80   void onConnectionLost();
81   bool onGotMessage(int type, Glib::ustring message);
82   void on_torn_down();
83   bool loadRecentlyPlayedGameList(Glib::ustring tag, XML_Helper *helper);
84 
85   static GamelistClient * s_instance;
86   Glib::ustring d_host;
87   guint32 d_port;
88   bool d_connected;
89   Glib::ustring d_profile_id;
90   RecentlyPlayedGameList *d_recently_played_game_list;
91 
92 };
93 
94 #endif
95