Merge pull request #4775 from jmarshallnz/empty_episode_playcount
[vuplus_xbmc] / xbmc / network / WakeOnAccess.h
1 /*
2  *      Copyright (C) 2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "URL.h"
22 #include "XBDateTime.h"
23 #include "utils/Job.h"
24 #include "settings/lib/ISettingsHandler.h"
25
26 class CWakeOnAccess : private IJobCallback, public ISettingsHandler
27 {
28 public:
29   static CWakeOnAccess &Get();
30
31   bool WakeUpHost (const CURL& fileUrl);
32   bool WakeUpHost (const CStdString& hostName, const std::string& customMessage);
33
34   void QueueMACDiscoveryForAllRemotes();
35
36   virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
37   virtual void OnSettingsLoaded();
38   virtual void OnSettingsSaved();
39
40   // struct to keep per host settings
41   struct WakeUpEntry
42   {
43     WakeUpEntry (bool isAwake = false);
44
45     std::string host;
46     std::string mac;
47     CDateTimeSpan timeout;
48     unsigned int wait_online1_sec; // initial wait
49     unsigned int wait_online2_sec; // extended wait
50     unsigned int wait_services_sec;
51
52     unsigned short ping_port; // where to ping
53     unsigned short ping_mode; // how to ping
54
55     CDateTime nextWake;
56   };
57
58 private:
59   CWakeOnAccess();
60   CStdString GetSettingFile();
61   void LoadFromXML();
62   void SaveToXML();
63
64   void SetEnabled(bool enabled);
65   bool IsEnabled() const { return m_enabled; }
66
67   void QueueMACDiscoveryForHost(const CStdString& host);
68   void SaveMACDiscoveryResult(const CStdString& host, const CStdString& mac);
69
70   typedef std::vector<WakeUpEntry> EntriesVector;
71   EntriesVector m_entries;
72   CCriticalSection m_entrylist_protect;
73   bool FindOrTouchHostEntry (const CStdString& hostName, WakeUpEntry& server);
74   void TouchHostEntry (const CStdString& hostName);
75
76   unsigned int m_netinit_sec, m_netsettle_ms; //time to wait for network connection
77
78   bool m_enabled;
79
80   bool WakeUpHost(const WakeUpEntry& server);
81 };