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