kodi
WakeOnAccess.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "URL.h"
12 #include "XBDateTime.h"
13 #include "settings/lib/ISettingCallback.h"
14 #include "settings/lib/ISettingsHandler.h"
15 #include "threads/CriticalSection.h"
16 #include "utils/Job.h"
17 
18 #include <string>
19 #include <vector>
20 
22 {
23 public:
24  static CWakeOnAccess &GetInstance();
25 
26  bool WakeUpHost (const CURL& fileUrl);
27  bool WakeUpHost (const std::string& hostName, const std::string& customMessage);
28 
29  void QueueMACDiscoveryForAllRemotes();
30 
31  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
32  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
33  void OnSettingsLoaded() override;
34 
35  // struct to keep per host settings
36  struct WakeUpEntry
37  {
38  explicit WakeUpEntry (bool isAwake = false);
39 
40  std::string host;
41  std::string mac;
42  CDateTimeSpan timeout;
43  unsigned int wait_online1_sec; // initial wait
44  unsigned int wait_online2_sec; // extended wait
45  unsigned int wait_services_sec;
46 
47  unsigned short ping_port = 0; // where to ping
48  unsigned short ping_mode = 0; // how to ping
49 
50  CDateTime nextWake;
51  std::string upnpUuid; // empty unless upnpmode
52  std::string friendlyName;
53  };
54 
55 private:
56  CWakeOnAccess();
57  std::string GetSettingFile();
58  void LoadFromXML();
59  void SaveToXML();
60 
61  void SetEnabled(bool enabled);
62  bool IsEnabled() const { return m_enabled; }
63 
64  void QueueMACDiscoveryForHost(const std::string& host);
65  void SaveMACDiscoveryResult(const std::string& host, const std::string& mac);
66 
67  typedef std::vector<WakeUpEntry> EntriesVector;
68  EntriesVector m_entries;
69  CCriticalSection m_entrylist_protect;
70  bool FindOrTouchHostEntry(const std::string& hostName, bool upnpMode, WakeUpEntry& server);
71  void TouchHostEntry(const std::string& hostName, bool upnpMode);
72 
73  unsigned int m_netinit_sec, m_netsettle_ms; //time to wait for network connection
74 
75  bool m_enabled = false;
76 
77  bool WakeUpHost(const std::string& hostName, const std::string& customMessage, bool upnpMode);
78  bool WakeUpHost(const WakeUpEntry& server);
79 
80  std::vector<struct UPnPServer> m_UPnPServers; // list of wakeable upnp servers
81 };
void OnSettingChanged(const std::shared_ptr< const CSetting > &setting) override
The value of the given setting has changed.
Definition: WakeOnAccess.cpp:763
void OnSettingsLoaded() override
Settings have been loaded.
Definition: WakeOnAccess.cpp:785
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
void OnJobComplete(unsigned int jobID, bool success, CJob *job) override
The callback used when a job completes.
Definition: WakeOnAccess.cpp:737
Definition: URL.h:21
Definition: ISettingCallback.h:16
Definition: WakeOnAccess.h:36
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Interface defining methods being called by the settings system if an action is performed on multiple/...
Definition: ISettingsHandler.h:16
Callback interface for asynchronous jobs.
Definition: Job.h:31
Definition: XBDateTime.h:21
Definition: WakeOnAccess.h:21