mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 22:48:19 +00:00
Remove use of global 'reds' var from spice_server_remove_interface()
Since this is public API, we can't easily change the signature of the function to take a RedsState argument, so instead we apply a hack and store the reds argument inside the device state struct when the interface is added, and retrieve it for use later when it is removed. Acked-by: Pavel Grunt <pgrunt@redhat.com>
This commit is contained in:
parent
41adaa15ba
commit
b85c8295d6
@ -71,6 +71,7 @@ struct SpiceCharDeviceState {
|
||||
|
||||
SpiceCharDeviceCallbacks cbs;
|
||||
void *opaque;
|
||||
SpiceServer *reds;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -1034,3 +1035,13 @@ int spice_char_device_state_restore(SpiceCharDeviceState *dev,
|
||||
spice_char_device_read_from_device(dev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void spice_char_device_set_server(SpiceCharDeviceState *dev, SpiceServer *server)
|
||||
{
|
||||
dev->reds = server;
|
||||
}
|
||||
|
||||
SpiceServer* spice_char_device_get_server(SpiceCharDeviceState *dev)
|
||||
{
|
||||
return dev->reds;
|
||||
}
|
||||
|
||||
@ -181,6 +181,8 @@ int spice_char_device_client_exists(SpiceCharDeviceState *dev,
|
||||
|
||||
void spice_char_device_start(SpiceCharDeviceState *dev);
|
||||
void spice_char_device_stop(SpiceCharDeviceState *dev);
|
||||
void spice_char_device_set_server(SpiceCharDeviceState *dev, SpiceServer *server);
|
||||
SpiceServer* spice_char_device_get_server(SpiceCharDeviceState *dev);
|
||||
|
||||
/** Read from device **/
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ struct SpiceKbdState {
|
||||
bool key_ext[0x7f];
|
||||
};
|
||||
|
||||
SpiceKbdState* spice_kbd_state_new(void)
|
||||
static SpiceKbdState* spice_kbd_state_new(void)
|
||||
{
|
||||
return spice_new0(SpiceKbdState, 1);
|
||||
}
|
||||
@ -72,20 +72,25 @@ struct SpiceMouseState {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
SpiceMouseState* spice_mouse_state_new(void)
|
||||
static SpiceMouseState* spice_mouse_state_new(void)
|
||||
{
|
||||
return spice_new0(SpiceMouseState, 1);
|
||||
}
|
||||
|
||||
struct SpiceTabletState {
|
||||
int dummy;
|
||||
RedsState *reds;
|
||||
};
|
||||
|
||||
SpiceTabletState* spice_tablet_state_new(void)
|
||||
static SpiceTabletState* spice_tablet_state_new(void)
|
||||
{
|
||||
return spice_new0(SpiceTabletState, 1);
|
||||
}
|
||||
|
||||
RedsState* spice_tablet_state_get_server(SpiceTabletState *st)
|
||||
{
|
||||
return st->reds;
|
||||
}
|
||||
|
||||
typedef struct InputsChannelClient {
|
||||
RedChannelClient base;
|
||||
uint16_t motion_count;
|
||||
@ -685,7 +690,7 @@ SpiceTabletInstance* inputs_channel_get_tablet(InputsChannel *inputs)
|
||||
return inputs->tablet;
|
||||
}
|
||||
|
||||
int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet)
|
||||
int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet, RedsState *reds)
|
||||
{
|
||||
if (inputs->tablet) {
|
||||
spice_printerr("already have tablet");
|
||||
@ -693,6 +698,7 @@ int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet
|
||||
}
|
||||
inputs->tablet = tablet;
|
||||
inputs->tablet->st = spice_tablet_state_new();
|
||||
inputs->tablet->st->reds = reds;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -31,16 +31,14 @@ const VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel *inputs);
|
||||
void inputs_channel_on_keyboard_leds_change(InputsChannel *inputs, uint8_t leds);
|
||||
void inputs_channel_set_tablet_logical_size(InputsChannel *inputs, int x_res, int y_res);
|
||||
|
||||
SpiceKbdState* spice_kbd_state_new(void);
|
||||
SpiceMouseState* spice_mouse_state_new(void);
|
||||
SpiceTabletState* spice_tablet_state_new(void);
|
||||
|
||||
SpiceKbdInstance* inputs_channel_get_keyboard(InputsChannel *inputs);
|
||||
int inputs_channel_set_keyboard(InputsChannel *inputs, SpiceKbdInstance *keyboard);
|
||||
SpiceMouseInstance* inputs_channel_get_mouse(InputsChannel *inputs);
|
||||
int inputs_channel_set_mouse(InputsChannel *inputs, SpiceMouseInstance *mouse);
|
||||
SpiceTabletInstance* inputs_channel_get_tablet(InputsChannel *inputs);
|
||||
int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet);
|
||||
int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet, RedsState *reds);
|
||||
int inputs_channel_has_tablet(InputsChannel *inputs);
|
||||
void inputs_channel_detach_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet);
|
||||
RedsState* spice_tablet_state_get_server(SpiceTabletState *dev);
|
||||
|
||||
#endif
|
||||
|
||||
@ -3125,6 +3125,7 @@ static int spice_server_char_device_add_interface(SpiceServer *s,
|
||||
if (reds->vm_running) {
|
||||
spice_char_device_start(char_device->st);
|
||||
}
|
||||
spice_char_device_set_server(char_device->st, reds);
|
||||
reds_char_device_add_state(reds, char_device->st);
|
||||
} else {
|
||||
spice_warning("failed to create device state for %s", char_device->subtype);
|
||||
@ -3202,13 +3203,14 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
|
||||
red_dispatcher_init(qxl);
|
||||
|
||||
} else if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
|
||||
SpiceTabletInstance *tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
|
||||
spice_info("SPICE_INTERFACE_TABLET");
|
||||
if (interface->major_version != SPICE_INTERFACE_TABLET_MAJOR ||
|
||||
interface->minor_version > SPICE_INTERFACE_TABLET_MINOR) {
|
||||
spice_warning("unsupported tablet interface");
|
||||
return -1;
|
||||
}
|
||||
if (inputs_channel_set_tablet(reds->inputs_channel, SPICE_CONTAINEROF(sin, SpiceTabletInstance, base)) != 0) {
|
||||
if (inputs_channel_set_tablet(reds->inputs_channel, tablet, reds) != 0) {
|
||||
return -1;
|
||||
}
|
||||
reds_update_mouse_mode(reds);
|
||||
@ -3263,11 +3265,14 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
|
||||
|
||||
SPICE_GNUC_VISIBLE int spice_server_remove_interface(SpiceBaseInstance *sin)
|
||||
{
|
||||
RedsState *reds;
|
||||
const SpiceBaseInterface *interface = sin->sif;
|
||||
|
||||
if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
|
||||
SpiceTabletInstance *tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
|
||||
reds = spice_tablet_state_get_server(tablet->st);
|
||||
spice_info("remove SPICE_INTERFACE_TABLET");
|
||||
inputs_channel_detach_tablet(reds->inputs_channel, SPICE_CONTAINEROF(sin, SpiceTabletInstance, base));
|
||||
inputs_channel_detach_tablet(reds->inputs_channel, tablet);
|
||||
reds_update_mouse_mode(reds);
|
||||
} else if (strcmp(interface->type, SPICE_INTERFACE_PLAYBACK) == 0) {
|
||||
spice_info("remove SPICE_INTERFACE_PLAYBACK");
|
||||
@ -3276,6 +3281,8 @@ SPICE_GNUC_VISIBLE int spice_server_remove_interface(SpiceBaseInstance *sin)
|
||||
spice_info("remove SPICE_INTERFACE_RECORD");
|
||||
snd_detach_record(SPICE_CONTAINEROF(sin, SpiceRecordInstance, base));
|
||||
} else if (strcmp(interface->type, SPICE_INTERFACE_CHAR_DEVICE) == 0) {
|
||||
SpiceCharDeviceInstance *char_device = SPICE_CONTAINEROF(sin, SpiceCharDeviceInstance, base);
|
||||
reds = spice_char_device_get_server(char_device->st);
|
||||
spice_server_char_device_remove_interface(reds, sin);
|
||||
} else {
|
||||
spice_warning("VD_INTERFACE_REMOVING unsupported");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user