Set the capabilities based on the whether the hook function is defined
in the interface. Unsupported actions are actively rejected.
---
server/power-channel-client.cpp | 5 +++--
server/power-channel.cpp | 17 +++++++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/server/power-channel-client.cpp b/server/power-channel-client.cpp
index 036f1cba..3f12e550 100644
--- a/server/power-channel-client.cpp
+++ b/server/power-channel-client.cpp
@@ -52,6 +52,7 @@ bool PowerChannelClient::handle_message(uint16_t type,
uint32_t size, void *mess
{
spice_debug("PowerChannelClient handle_message() called");
PowerChannel *power_channel = get_channel();
+ const RedChannelCapabilities *local_caps =
power_channel->get_local_capabilities();
SpicePowerInstance *sin = power_channel->sin;
SpicePowerInterface *sif;
@@ -64,7 +65,7 @@ bool PowerChannelClient::handle_message(uint16_t type,
uint32_t size, void *mess
switch (type) {
case SPICE_MSGC_POWER_RESET: {
spice_debug("Got a SPICE_MSGC_POWER_RESET message");
- if (!sif->do_reset) {
+ if (!test_capability(local_caps->caps, local_caps->num_caps,
SPICE_POWER_CAP_RESET)) {
spice_debug("PowerChannelClient handle_message() no reset
impl");
this->get_client()->get_main()->push_notify("Server does not
support power reset action.");
return TRUE;
@@ -74,7 +75,7 @@ bool PowerChannelClient::handle_message(uint16_t type,
uint32_t size, void *mess
}
case SPICE_MSGC_POWER_POWEROFF: {
spice_debug("Got a SPICE_MSGC_POWER_POWEROFF message");
- if (!sif->do_poweroff) {
+ if (!test_capability(local_caps->caps, local_caps->num_caps,
SPICE_POWER_CAP_POWEROFF)) {
spice_debug("PowerChannelClient handle_message() no poweroff
impl");
this->get_client()->get_main()->push_notify("Server does not
support power off action.");
return TRUE;
diff --git a/server/power-channel.cpp b/server/power-channel.cpp
index 57f8951f..f3de501a 100644
--- a/server/power-channel.cpp
+++ b/server/power-channel.cpp
@@ -57,8 +57,21 @@ int PowerChannel::set_instance(SpicePowerInstance *new_sin)
void power_attach(RedsState *reds, SpicePowerInstance *sin)
{
- sin->st = new PowerChannel(reds);
- sin->st->set_instance(sin);
+ SpicePowerInterface *sif = SPICE_UPCAST(SpicePowerInterface,
sin->base.sif);
+
+ PowerChannel *channel = new PowerChannel(reds);
+ channel->set_instance(sin);
+
+ if (sif->do_reset != NULL) {
+ spice_debug("power_attach() set reset cap");
+ channel->set_cap(SPICE_POWER_CAP_RESET);
+ }
+ if (sif->do_poweroff != NULL) {
+ spice_debug("power_attach() set poweroff cap");
+ channel->set_cap(SPICE_POWER_CAP_POWEROFF);
+ }
+
+ sin->st = channel;
}
void power_detach(SpicePowerInstance *sin)
--
2.52.0