|
@@ -25,7 +25,7 @@ namespace Plugin {
|
|
|
25
25
|
|
|
26
26
|
namespace {
|
|
27
27
|
|
|
28
|
-
static Metadata<InProcessConfig>metadata(
|
|
28
|
+
static Metadata<InProcessConfig> metadata(
|
|
29
29
|
// Version
|
|
30
30
|
1, 0, 0,
|
|
31
31
|
// Preconditions
|
|
@@ -56,10 +56,33 @@ namespace Plugin {
|
|
|
56
56
|
return (string());
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
Core::hresult InProcessConfig::Register(INotification*
|
|
59
|
+
Core::hresult InProcessConfig::Register(Exchange::IPower::INotification* notification) {
|
|
60
|
+
ASSERT(notification != nullptr);
|
|
61
|
+
|
|
62
|
+
_adminLock.Lock();
|
|
63
|
+
auto item = std::find(_powerNotification.begin(), _powerNotification.end(), notification);
|
|
64
|
+
ASSERT(item == _powerNotification.end());
|
|
65
|
+
|
|
66
|
+
if (item == _powerNotification.end()) {
|
|
67
|
+
notification->AddRef();
|
|
68
|
+
_powerNotification.push_back(notification);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_adminLock.Unlock();
|
|
60
72
|
return Core::ERROR_NONE;
|
|
61
73
|
}
|
|
62
|
-
Core::hresult InProcessConfig::Unregister(const INotification*
|
|
74
|
+
Core::hresult InProcessConfig::Unregister(const Exchange::IPower::INotification* notification) {
|
|
75
|
+
ASSERT(notification != nullptr);
|
|
76
|
+
|
|
77
|
+
_adminLock.Lock();
|
|
78
|
+
auto item = std::find(_powerNotification.begin(), _powerNotification.end(), notification);
|
|
79
|
+
ASSERT(item != _powerNotification.end());
|
|
80
|
+
|
|
81
|
+
if (item != _powerNotification.end()) {
|
|
82
|
+
_powerNotification.erase(item);
|
|
83
|
+
notification->Release();
|
|
84
|
+
}
|
|
85
|
+
_adminLock.Unlock();
|
|
63
86
|
return Core::ERROR_NONE;
|
|
64
87
|
}
|
|
65
88
|
Core::hresult InProcessConfig::GetState(PCState& /* state */ /* @out */) const {
|
|
@@ -69,7 +92,14 @@ namespace Plugin {
|
|
|
69
92
|
return Core::ERROR_NONE;
|
|
70
93
|
}
|
|
71
94
|
void InProcessConfig::PowerKey() {
|
|
72
|
-
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void InProcessConfig::NotifyStateChange(const PCState origin, const PCState destination, const PCPhase phase) const {
|
|
98
|
+
_adminLock.Lock();
|
|
99
|
+
for (auto* notification : _powerNotification) {
|
|
100
|
+
notification->StateChange(origin, destination, phase);
|
|
101
|
+
}
|
|
102
|
+
_adminLock.Unlock();
|
|
73
103
|
}
|
|
74
104
|
} // Plugin
|
|
75
105
|
} // Thunder
|
|
@@ -42,20 +42,21 @@ namespace Plugin {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
~InProcessConfig() override = default;
|
|
45
|
-
|
|
45
|
+
private:
|
|
46
|
+
class PluginConfig : public Core::JSON::Container {
|
|
46
47
|
public:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
PluginConfig(const PluginConfig&) = delete;
|
|
49
|
+
PluginConfig& operator=(const PluginConfig&) = delete;
|
|
50
|
+
PluginConfig(PluginConfig&&) = delete;
|
|
51
|
+
PluginConfig& operator=(PluginConfig&&) = delete;
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
PluginConfig()
|
|
53
54
|
: Core::JSON::Container()
|
|
54
55
|
, Example()
|
|
55
56
|
{
|
|
56
57
|
Add(_T("example"), &Example);
|
|
57
58
|
}
|
|
58
|
-
~
|
|
59
|
+
~PluginConfig() override = default;
|
|
59
60
|
public:
|
|
60
61
|
Core::JSON::String Example;
|
|
61
62
|
};
|
|
@@ -67,9 +68,9 @@ namespace Plugin {
|
|
|
67
68
|
|
|
68
69
|
// IPower methods
|
|
69
70
|
|
|
70
|
-
Core::hresult Register(INotification* const /* sink */) override;
|
|
71
|
+
Core::hresult Register(Exchange::IPower::INotification* const /* sink */) override;
|
|
71
72
|
|
|
72
|
-
Core::hresult Unregister(const INotification* const /* sink */) override;
|
|
73
|
+
Core::hresult Unregister(const Exchange::IPower::INotification* const /* sink */) override;
|
|
73
74
|
|
|
74
75
|
Core::hresult GetState(PCState& /* state */ /* @out */) const override;
|
|
75
76
|
|
|
@@ -86,6 +87,8 @@ namespace Plugin {
|
|
|
86
87
|
private:
|
|
87
88
|
using PowerNotificationContainer = std::vector<Exchange::IPower::INotification*>;
|
|
88
89
|
|
|
90
|
+
void NotifyStateChange(const PCState /* origin */, const PCState /* destination */, const PCPhase /* phase */) const;
|
|
91
|
+
|
|
89
92
|
mutable Core::CriticalSection _adminLock;
|
|
90
93
|
PowerNotificationContainer _powerNotification;
|
|
91
94
|
};
|