Re: [Spice-devel] [PATCH] server/video: do not allow non-streamable drawables be stream candidates

2012-05-20 Thread Alon Levy
On Thu, May 17, 2012 at 08:46:47PM +0300, Yonit Halperin wrote:
 Fix a crash caused by a call to __red_is_next_stream_frame made by
 red_stream_maintenance, with a drawable that is not a DRAW_COPY one.
 Only DRAW_COPY drawables can be streamed, and __red_is_next_stream_frame
 refers to red_drawable-u.copy.src_bitmap.

ACK. Please spell out that the crash is a segfault on the field you
mention in the last sentence, thanks.

 ---
  server/red_worker.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)
 
 diff --git a/server/red_worker.c b/server/red_worker.c
 index dd00bff..3a0bdf4 100644
 --- a/server/red_worker.c
 +++ b/server/red_worker.c
 @@ -2916,6 +2916,10 @@ static inline int __red_is_next_stream_frame(RedWorker 
 *worker,
  RedDrawable *red_drawable;
  int is_frame_container = FALSE;
  
 +if (!candidate-streamable) {
 +return STREAM_FRAME_NONE;
 +}
 +
  if (candidate-creation_time - other_time 
  (stream ? RED_STREAM_CONTINUS_MAX_DELTA : 
 RED_STREAM_DETACTION_MAX_DELTA)) {
  return STREAM_FRAME_NONE;
 -- 
 1.7.7.6
 
 ___
 Spice-devel mailing list
 Spice-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/spice-devel
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 1/2] server/red_channel: prevent creating more than one channel client with the same type+id

2012-05-20 Thread Yonit Halperin
---
 server/red_channel.c |   51 ++---
 1 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/server/red_channel.c b/server/red_channel.c
index 4858bb5..0359466 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -40,6 +40,7 @@
 static void red_channel_client_event(int fd, int event, void *data);
 static void red_client_add_channel(RedClient *client, RedChannelClient *rcc);
 static void red_client_remove_channel(RedChannelClient *rcc);
+static RedChannelClient *red_client_get_channel(RedClient *client, int type, 
int id);
 static void red_channel_client_restore_main_sender(RedChannelClient *rcc);
 
 static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header)
@@ -514,13 +515,27 @@ int red_channel_client_test_remote_cap(RedChannelClient 
*rcc, uint32_t cap)
   cap);
 }
 
+static int red_channle_client_pre_create_validate(RedChannel *channel, 
RedClient  *client)
+{
+if (red_client_get_channel(client, channel-type, channel-id)) {
+spice_printerr(Error client %p: duplicated channel type %d id %d,
+   client, channel-type, channel-id);
+return FALSE;
+}
+return TRUE;
+}
+
 RedChannelClient *red_channel_client_create(int size, RedChannel *channel, 
RedClient  *client,
 RedsStream *stream,
 int num_common_caps, uint32_t 
*common_caps,
 int num_caps, uint32_t *caps)
 {
-RedChannelClient *rcc;
+RedChannelClient *rcc = NULL;
 
+pthread_mutex_lock(client-lock);
+if (!red_channle_client_pre_create_validate(channel, client)) {
+goto error;
+}
 spice_assert(stream  channel  size = sizeof(RedChannelClient));
 rcc = spice_malloc0(size);
 rcc-stream = stream;
@@ -570,10 +585,12 @@ RedChannelClient *red_channel_client_create(int size, 
RedChannel *channel, RedCl
 rcc-id = channel-clients_num;
 red_channel_add_client(channel, rcc);
 red_client_add_channel(client, rcc);
+pthread_mutex_unlock(client-lock);
 return rcc;
 error:
 free(rcc);
 reds_stream_free(stream);
+pthread_mutex_unlock(client-lock);
 return NULL;
 }
 
@@ -1220,9 +1237,14 @@ RedChannelClient *red_channel_client_create_dummy(int 
size,
   int num_common_caps, 
uint32_t *common_caps,
   int num_caps, uint32_t *caps)
 {
-RedChannelClient *rcc;
+RedChannelClient *rcc = NULL;
 
 spice_assert(size = sizeof(RedChannelClient));
+
+pthread_mutex_lock(client-lock);
+if (!red_channle_client_pre_create_validate(channel, client)) {
+goto error;
+}
 rcc = spice_malloc0(size);
 rcc-client = client;
 rcc-channel = channel;
@@ -1241,7 +1263,11 @@ RedChannelClient *red_channel_client_create_dummy(int 
size,
 rcc-incoming.serial = 1;
 
 red_channel_add_client(channel, rcc);
+pthread_mutex_unlock(client-lock);
 return rcc;
+error:
+pthread_mutex_unlock(client-lock);
+return NULL;
 }
 
 void red_channel_client_destroy_dummy(RedChannelClient *rcc)
@@ -1454,19 +1480,36 @@ void red_client_destroy(RedClient *client)
 free(client);
 }
 
+/* client-lock should be locked */
+static RedChannelClient *red_client_get_channel(RedClient *client, int type, 
int id)
+{
+RingItem *link;
+RedChannelClient *rcc;
+RedChannelClient *ret = NULL;
+
+RING_FOREACH(link, client-channels) {
+rcc = SPICE_CONTAINEROF(link, RedChannelClient, client_link);
+if (rcc-channel-type == type  rcc-channel-id == id) {
+ret = rcc;
+break;
+}
+}
+return ret;
+}
+
+/* client-lock should be locked */
 static void red_client_add_channel(RedClient *client, RedChannelClient *rcc)
 {
 spice_assert(rcc  client);
-pthread_mutex_lock(client-lock);
 ring_add(client-channels, rcc-client_link);
 client-channels_num++;
-pthread_mutex_unlock(client-lock);
 }
 
 MainChannelClient *red_client_get_main(RedClient *client) {
 return client-mcc;
 }
 
+
 void red_client_set_main(RedClient *client, MainChannelClient *mcc) {
 client-mcc = mcc;
 }
-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-server 2/2] server: handle red_channel_client_create returning NULL

2012-05-20 Thread Yonit Halperin
---
 server/inputs_channel.c|3 +++
 server/main_channel.c  |2 +-
 server/red_tunnel_worker.c |4 +++-
 server/red_worker.c|3 +++
 server/smartcard.c |3 +++
 server/snd_worker.c|3 +++
 6 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/server/inputs_channel.c b/server/inputs_channel.c
index ad247f4..e14e995 100644
--- a/server/inputs_channel.c
+++ b/server/inputs_channel.c
@@ -502,6 +502,9 @@ static void inputs_connect(RedChannel *channel, RedClient 
*client,
   stream,
   num_common_caps, 
common_caps,
   num_caps, caps);
+if (!icc) {
+return;
+}
 icc-motion_count = 0;
 inputs_pipe_add_init(icc-base);
 }
diff --git a/server/main_channel.c b/server/main_channel.c
index 713f121..ace24ff 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -998,7 +998,7 @@ static MainChannelClient 
*main_channel_client_create(MainChannel *main_chan, Red
  
red_channel_client_create(sizeof(MainChannelClient), main_chan-base,
client, stream, 
num_common_caps,
common_caps, num_caps, 
caps);
-
+spice_assert(mcc != NULL);
 mcc-connection_id = connection_id;
 mcc-bitrate_per_sec = ~0;
 #ifdef RED_STATISTICS
diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
index 384c36d..12f3106 100644
--- a/server/red_tunnel_worker.c
+++ b/server/red_tunnel_worker.c
@@ -3452,7 +3452,9 @@ static void handle_tunnel_channel_link(RedChannel 
*channel, RedClient *client,
 tcc = 
(TunnelChannelClient*)red_channel_client_create(sizeof(TunnelChannelClient),
   channel, client, 
stream,
   0, NULL, 0, NULL);
-
+if (!tcc) {
+return;
+}
 tcc-worker = worker;
 tcc-worker-channel_client = tcc;
 net_slirp_set_net_interface(worker-tunnel_interface.base);
diff --git a/server/red_worker.c b/server/red_worker.c
index dd00bff..3616d0f 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -9769,6 +9769,9 @@ static CommonChannelClient 
*common_channel_client_create(int size,
 RedChannelClient *rcc =
 red_channel_client_create(size, common-base, client, stream,
   num_common_caps, common_caps, num_caps, 
caps);
+if (!rcc) {
+return NULL;
+}
 CommonChannelClient *common_cc = (CommonChannelClient*)rcc;
 common_cc-worker = common-worker;
 common_cc-id = common-worker-id;
diff --git a/server/smartcard.c b/server/smartcard.c
index eb2823a..8ded142 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -500,6 +500,9 @@ static void smartcard_connect(RedChannel *channel, 
RedClient *client,
 rcc = red_channel_client_create(sizeof(RedChannelClient), channel, client, 
stream,
 num_common_caps, common_caps,
 num_caps, caps);
+if (!rcc) {
+return;
+}
 red_channel_client_ack_zero_messages_window(rcc);
 }
 
diff --git a/server/snd_worker.c b/server/snd_worker.c
index caffe67..3599c6f 100644
--- a/server/snd_worker.c
+++ b/server/snd_worker.c
@@ -975,6 +975,9 @@ static SndChannel *__new_channel(SndWorker *worker, int 
size, uint32_t channel_i
   client,
   num_common_caps, 
common_caps,
   num_caps, caps);
+if (!channel-channel_client) {
+goto error2;
+}
 return channel;
 
 error2:
-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-server 1/2] server/red_channel: prevent creating more than one channel client with the same type+id

2012-05-20 Thread Alon Levy
On Sun, May 20, 2012 at 01:31:37PM +0300, Yonit Halperin wrote:
 ---
  server/red_channel.c |   51 ++---
  1 files changed, 47 insertions(+), 4 deletions(-)

ACK, one spelling idea and a blank line that crept in.

 
 diff --git a/server/red_channel.c b/server/red_channel.c
 index 4858bb5..0359466 100644
 --- a/server/red_channel.c
 +++ b/server/red_channel.c
 @@ -40,6 +40,7 @@
  static void red_channel_client_event(int fd, int event, void *data);
  static void red_client_add_channel(RedClient *client, RedChannelClient *rcc);
  static void red_client_remove_channel(RedChannelClient *rcc);
 +static RedChannelClient *red_client_get_channel(RedClient *client, int type, 
 int id);
  static void red_channel_client_restore_main_sender(RedChannelClient *rcc);
  
  static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header)
 @@ -514,13 +515,27 @@ int red_channel_client_test_remote_cap(RedChannelClient 
 *rcc, uint32_t cap)
cap);
  }
  
 +static int red_channle_client_pre_create_validate(RedChannel *channel, 
 RedClient  *client)
 +{
 +if (red_client_get_channel(client, channel-type, channel-id)) {
 +spice_printerr(Error client %p: duplicated channel type %d id %d,
s/duplicated/duplicate/ ?

 +   client, channel-type, channel-id);
 +return FALSE;
 +}
 +return TRUE;
 +}
 +
  RedChannelClient *red_channel_client_create(int size, RedChannel *channel, 
 RedClient  *client,
  RedsStream *stream,
  int num_common_caps, uint32_t 
 *common_caps,
  int num_caps, uint32_t *caps)
  {
 -RedChannelClient *rcc;
 +RedChannelClient *rcc = NULL;
  
 +pthread_mutex_lock(client-lock);
 +if (!red_channle_client_pre_create_validate(channel, client)) {
 +goto error;
 +}
  spice_assert(stream  channel  size = sizeof(RedChannelClient));
  rcc = spice_malloc0(size);
  rcc-stream = stream;
 @@ -570,10 +585,12 @@ RedChannelClient *red_channel_client_create(int size, 
 RedChannel *channel, RedCl
  rcc-id = channel-clients_num;
  red_channel_add_client(channel, rcc);
  red_client_add_channel(client, rcc);
 +pthread_mutex_unlock(client-lock);
  return rcc;
  error:
  free(rcc);
  reds_stream_free(stream);
 +pthread_mutex_unlock(client-lock);
  return NULL;
  }
  
 @@ -1220,9 +1237,14 @@ RedChannelClient *red_channel_client_create_dummy(int 
 size,
int num_common_caps, 
 uint32_t *common_caps,
int num_caps, uint32_t 
 *caps)
  {
 -RedChannelClient *rcc;
 +RedChannelClient *rcc = NULL;
  
  spice_assert(size = sizeof(RedChannelClient));
 +
 +pthread_mutex_lock(client-lock);
 +if (!red_channle_client_pre_create_validate(channel, client)) {
 +goto error;
 +}
  rcc = spice_malloc0(size);
  rcc-client = client;
  rcc-channel = channel;
 @@ -1241,7 +1263,11 @@ RedChannelClient *red_channel_client_create_dummy(int 
 size,
  rcc-incoming.serial = 1;
  
  red_channel_add_client(channel, rcc);
 +pthread_mutex_unlock(client-lock);
  return rcc;
 +error:
 +pthread_mutex_unlock(client-lock);
 +return NULL;
  }
  
  void red_channel_client_destroy_dummy(RedChannelClient *rcc)
 @@ -1454,19 +1480,36 @@ void red_client_destroy(RedClient *client)
  free(client);
  }
  
 +/* client-lock should be locked */
 +static RedChannelClient *red_client_get_channel(RedClient *client, int type, 
 int id)
 +{
 +RingItem *link;
 +RedChannelClient *rcc;
 +RedChannelClient *ret = NULL;
 +
 +RING_FOREACH(link, client-channels) {
 +rcc = SPICE_CONTAINEROF(link, RedChannelClient, client_link);
 +if (rcc-channel-type == type  rcc-channel-id == id) {
 +ret = rcc;
 +break;
 +}
 +}
 +return ret;
 +}
 +
 +/* client-lock should be locked */
  static void red_client_add_channel(RedClient *client, RedChannelClient *rcc)
  {
  spice_assert(rcc  client);
 -pthread_mutex_lock(client-lock);
  ring_add(client-channels, rcc-client_link);
  client-channels_num++;
 -pthread_mutex_unlock(client-lock);
  }
  
  MainChannelClient *red_client_get_main(RedClient *client) {
  return client-mcc;
  }
  
 +

Blank line accidentally got in.

  void red_client_set_main(RedClient *client, MainChannelClient *mcc) {
  client-mcc = mcc;
  }
 -- 
 1.7.7.6
 
 ___
 Spice-devel mailing list
 Spice-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/spice-devel
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-server 2/2] server: handle red_channel_client_create returning NULL

2012-05-20 Thread Alon Levy
On Sun, May 20, 2012 at 01:31:38PM +0300, Yonit Halperin wrote:

Looks good, ACK.

 ---
  server/inputs_channel.c|3 +++
  server/main_channel.c  |2 +-
  server/red_tunnel_worker.c |4 +++-
  server/red_worker.c|3 +++
  server/smartcard.c |3 +++
  server/snd_worker.c|3 +++
  6 files changed, 16 insertions(+), 2 deletions(-)
 
 diff --git a/server/inputs_channel.c b/server/inputs_channel.c
 index ad247f4..e14e995 100644
 --- a/server/inputs_channel.c
 +++ b/server/inputs_channel.c
 @@ -502,6 +502,9 @@ static void inputs_connect(RedChannel *channel, RedClient 
 *client,
stream,
num_common_caps, 
 common_caps,
num_caps, caps);
 +if (!icc) {
 +return;
 +}
  icc-motion_count = 0;
  inputs_pipe_add_init(icc-base);
  }
 diff --git a/server/main_channel.c b/server/main_channel.c
 index 713f121..ace24ff 100644
 --- a/server/main_channel.c
 +++ b/server/main_channel.c
 @@ -998,7 +998,7 @@ static MainChannelClient 
 *main_channel_client_create(MainChannel *main_chan, Red
   
 red_channel_client_create(sizeof(MainChannelClient), main_chan-base,
 client, stream, 
 num_common_caps,
 common_caps, 
 num_caps, caps);
 -
 +spice_assert(mcc != NULL);
  mcc-connection_id = connection_id;
  mcc-bitrate_per_sec = ~0;
  #ifdef RED_STATISTICS
 diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
 index 384c36d..12f3106 100644
 --- a/server/red_tunnel_worker.c
 +++ b/server/red_tunnel_worker.c
 @@ -3452,7 +3452,9 @@ static void handle_tunnel_channel_link(RedChannel 
 *channel, RedClient *client,
  tcc = 
 (TunnelChannelClient*)red_channel_client_create(sizeof(TunnelChannelClient),
channel, client, 
 stream,
0, NULL, 0, NULL);
 -
 +if (!tcc) {
 +return;
 +}
  tcc-worker = worker;
  tcc-worker-channel_client = tcc;
  net_slirp_set_net_interface(worker-tunnel_interface.base);
 diff --git a/server/red_worker.c b/server/red_worker.c
 index dd00bff..3616d0f 100644
 --- a/server/red_worker.c
 +++ b/server/red_worker.c
 @@ -9769,6 +9769,9 @@ static CommonChannelClient 
 *common_channel_client_create(int size,
  RedChannelClient *rcc =
  red_channel_client_create(size, common-base, client, stream,
num_common_caps, common_caps, num_caps, 
 caps);
 +if (!rcc) {
 +return NULL;
 +}
  CommonChannelClient *common_cc = (CommonChannelClient*)rcc;
  common_cc-worker = common-worker;
  common_cc-id = common-worker-id;
 diff --git a/server/smartcard.c b/server/smartcard.c
 index eb2823a..8ded142 100644
 --- a/server/smartcard.c
 +++ b/server/smartcard.c
 @@ -500,6 +500,9 @@ static void smartcard_connect(RedChannel *channel, 
 RedClient *client,
  rcc = red_channel_client_create(sizeof(RedChannelClient), channel, 
 client, stream,
  num_common_caps, common_caps,
  num_caps, caps);
 +if (!rcc) {
 +return;
 +}
  red_channel_client_ack_zero_messages_window(rcc);
  }
  
 diff --git a/server/snd_worker.c b/server/snd_worker.c
 index caffe67..3599c6f 100644
 --- a/server/snd_worker.c
 +++ b/server/snd_worker.c
 @@ -975,6 +975,9 @@ static SndChannel *__new_channel(SndWorker *worker, int 
 size, uint32_t channel_i
client,

 num_common_caps, common_caps,
num_caps, 
 caps);
 +if (!channel-channel_client) {
 +goto error2;
 +}
  return channel;
  
  error2:
 -- 
 1.7.7.6
 
 ___
 Spice-devel mailing list
 Spice-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/spice-devel
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [spice-gtk Win32 v2 PATCH 0/5] usb-redir support for Windows (mingw32)

2012-05-20 Thread Uri Lublin
Hello,

This patchset enables usb-redir support in spice-gtk running on Windows.

Patches 1, 2 fixes compilation on mingw with usbredir enabled.
Patch 1  - No need to review, was was already reviewed and acked.
Patch 2  - On windows GUDEV is not required.

Patch 3 adds GUdev like implementation for windows:
  - listening for USB device plug/unplug evevnts.
  - notifying registerees of such events.
  - provide similar api for minimal changes in usb-device-manager.

Patch 4 adds the capability to install a libusb driver dynamically
  - Assuming usbclerk is installed on the client machine.
  - Note that current implementation requires a rescan of USB devices
(and an additional patch to libusbx).

Patch 5  Leak memory and prevent crashes.
A ToDo list.


Changes in v2:
   - many review comments fixed
   - no --enable-gudev added to configure.ac. Instead GUDEV is checked
 on non-windows as a part of USBREDIR
   - a separate window is used for event listening (no gtk dependency)
   - snprintf patch of v1 is squashed in v2 patchset.
   - Windows USB source files appear in the tarballs of make dist.
   - spicy code is not changed (a result of using a separate window for events)

Arnon Gilboa (1):
  Windows mingw: usb: add win-usb-dev.[ch]: implement GUdevDevice  GUdevClient

Uri Lublin (4):
  Move err variable definition to beginning of the function
  Windows mingw: usb: configure.ac: do not require GUDEV for USBREDIR
  Windows mingw: usb: Dynamically install a libusb driver for USB devices
  Windows mingw: usb: Comment out some memory cleanups not working on Windows

 configure.ac |   20 +++-
 gtk/Makefile.am  |   19 +++
 gtk/channel-usbredir.c   |4 +-
 gtk/usb-device-manager.c |   55 +++-
 gtk/usbclerk.h   |   35 
 gtk/usbutil.c|1 +
 gtk/win-usb-dev.c|  359 ++
 gtk/win-usb-dev.h|   92 +++
 gtk/win-usb-driver-install.c |  213 +
 gtk/win-usb-driver-install.h |   39 +
 10 files changed, 834 insertions(+), 3 deletions(-)
 create mode 100644 gtk/usbclerk.h
 create mode 100644 gtk/win-usb-dev.c
 create mode 100644 gtk/win-usb-dev.h
 create mode 100644 gtk/win-usb-driver-install.c
 create mode 100644 gtk/win-usb-driver-install.h

-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [spice-gtk Win32 v2 PATCH 1/5] Move err variable definition to beginning of the function

2012-05-20 Thread Uri Lublin
This fixes the following compilation error:
channel-usbredir.c: In function 'spice_usbredir_channel_connect_device_async':
channel-usbredir.c:313:9: error: jump skips variable initialization 
[-Werror=jump-misses-init]
---
 gtk/channel-usbredir.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index 8b2d2f4..3d57152 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -297,6 +297,9 @@ void spice_usbredir_channel_connect_device_async(
 {
 SpiceUsbredirChannelPrivate *priv = channel-priv;
 GSimpleAsyncResult *result;
+#if ! USE_POLKIT
+GError *err = NULL;
+#endif

 g_return_if_fail(SPICE_IS_USBREDIR_CHANNEL(channel));
 g_return_if_fail(device != NULL);
@@ -335,7 +338,6 @@ void spice_usbredir_channel_connect_device_async(
   channel);
 return;
 #else
-GError *err = NULL;
 if (!spice_usbredir_channel_open_device(channel, err)) {
 g_simple_async_result_take_error(result, err);
 libusb_unref_device(priv-device);
-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [spice-gtk Win32 v2 PATCH 2/5] Windows mingw: usb: configure.ac: do not require GUDEV for USBREDIR

2012-05-20 Thread Uri Lublin
For windows GUDEV is not required

- GUDEV is alwasy checked as part of USBREDIR, and fails
  if USBREDIR but no GUDEV on non-windows.
- Added GUDEV env-variables in gtk/Makefile.am
---
 configure.ac|   20 +++-
 gtk/Makefile.am |2 ++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 09129b7..f39fbe8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -343,7 +343,7 @@ if test x$enable_usbredir = xno; then
   have_usbredir=no
 else
   PKG_CHECK_MODULES([USBREDIR],
-[gudev-1.0 libusb-1.0 = 1.0.9 libusbredirhost = 0.4.2 
libusbredirparser = 0.4],
+[libusb-1.0 = 1.0.9 libusbredirhost = 0.4.2 
libusbredirparser = 0.4],
 [have_usbredir=yes],
 [have_usbredir=no])
   if test x$have_usbredir = xno  test x$enable_usbredir = xyes; then
@@ -352,8 +352,26 @@ else
   if test x$have_usbredir = xyes; then
 AC_DEFINE(USE_USBREDIR, [1], [Define if supporting usbredir proxying])
   fi
+
+  # require GUDEV unless os_win32 is true
+  PKG_CHECK_MODULES([GUDEV],
+[gudev-1.0],
+[have_gudev=yes],
+[have_gudev=no])
+  if test x$have_gudev = xyes; then
+AC_DEFINE(USE_GUDEV, [1], [Define if supporting gudev])
+  fi
+
 fi
 AM_CONDITIONAL([WITH_USBREDIR], [test x$have_usbredir = xyes])
+AM_CONDITIONAL([WITH_GUDEV], [test x$have_gudev = xyes])
+
+# for non-win32 usbredir requires gudev
+if test x$have_usbredir = xyes  test x$have_gudev = xno  \
+  test x$os_win32 = xno; then
+  AC_MSG_ERROR([usbredir requested but required gudev is not available])
+fi
+

 AC_ARG_ENABLE([polkit],
   AS_HELP_STRING([--enable-polkit=@:@auto/yes/no@:@],
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 7b29e61..69cf0ef 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -82,6 +82,7 @@ SPICE_COMMON_CPPFLAGS =   
\
$(GST_CFLAGS)   \
$(SMARTCARD_CFLAGS) \
$(USBREDIR_CFLAGS)  \
+   $(GUDEV_CFLAGS) \
$(NULL)

 AM_CPPFLAGS =  \
@@ -179,6 +180,7 @@ libspice_client_glib_2_0_la_LIBADD =
\
$(SASL_LIBS)\
$(SMARTCARD_LIBS)   \
$(USBREDIR_LIBS)\
+   $(GUDEV_LIBS)   \
$(NULL)

 if WITH_POLKIT
-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [spice-gtk Win32 v2 PATCH 3/5] Windows mingw: usb: add win-usb-dev.[ch]: implement GUdevDevice GUdevClient

2012-05-20 Thread Uri Lublin
From: Arnon Gilboa agil...@redhat.com

With this patch usb-device-manager can work with little changes
on windows too.

-added GUdevDevice and GUdevClient like classes
-added uevent signal based on WM_DEVICECHANGE

Modified-by: Uri Lublin u...@redhat.com
---
 gtk/Makefile.am  |   15 ++
 gtk/usb-device-manager.c |7 +
 gtk/win-usb-dev.c|  359 ++
 gtk/win-usb-dev.h|   92 
 4 files changed, 473 insertions(+), 0 deletions(-)
 create mode 100644 gtk/win-usb-dev.c
 create mode 100644 gtk/win-usb-dev.h

diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 69cf0ef..81150ab 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -308,6 +308,21 @@ libspice_client_glib_2_0_la_SOURCES += coroutine_gthread.c
 libspice_client_glib_2_0_la_LIBADD += $(GTHREAD_LIBS)
 endif

+
+WIN_USB_FILES= \
+   win-usb-dev.h   \
+   win-usb-dev.c   \
+   usbclerk.h  \
+   $(NULL)
+
+if OS_WIN32
+libspice_client_glib_2_0_la_SOURCES += \
+   $(WIN_USB_FILES)
+else
+EXTRA_DIST += $(WIN_USB_FILES)
+endif
+
+
 displaysrc =   \
glib-compat.h   \
display/edid.h  \
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 14b60c9..2b6ce28 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -28,7 +28,14 @@
 #ifdef USE_USBREDIR
 #include errno.h
 #include libusb.h
+#if defined(USE_GUDEV)
 #include gudev/gudev.h
+#elif defined(G_OS_WIN32)
+#include win-usb-dev.h
+#else
+#warning Expecting one of G_OS_WIN32 and USE_GUDEV to be defined
+#endif
+
 #include channel-usbredir-priv.h
 #include usbredirhost.h
 #include usbutil.h
diff --git a/gtk/win-usb-dev.c b/gtk/win-usb-dev.c
new file mode 100644
index 000..7503c41
--- /dev/null
+++ b/gtk/win-usb-dev.c
@@ -0,0 +1,359 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2012 Red Hat, Inc.
+
+   Red Hat Authors:
+   Arnon Gilboa agil...@redhat.com
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see http://www.gnu.org/licenses/.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include windows.h
+#include libusb.h
+#include win-usb-dev.h
+#include spice-marshal.h
+#include spice-util.h
+
+#define G_UDEV_CLIENT_GET_PRIVATE(obj) \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), G_UDEV_TYPE_CLIENT, 
GUdevClientPrivate))
+
+struct _GUdevClientPrivate {
+libusb_device **dev_list;
+ssize_t dev_list_size;
+GList *udevice_list;
+HWND hwnd;
+};
+
+#define G_UDEV_CLIENT_WINCLASS_NAME  TEXT(G_UDEV_CLIENT)
+
+static void g_udev_client_initable_iface_init(GInitableIface  *iface);
+
+G_DEFINE_TYPE_WITH_CODE(GUdevClient, g_udev_client, G_TYPE_OBJECT,
+G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, 
g_udev_client_initable_iface_init));
+
+
+typedef struct _GUdevDeviceInfo GUdevDeviceInfo;
+
+struct _GUdevDeviceInfo {
+struct libusb_device_descriptor desc;
+libusb_device *dev;
+gchar sclass[4];
+gchar sbus[4];
+gchar saddr[4];
+};
+
+struct _GUdevDevicePrivate
+{
+GUdevDeviceInfo *usbdev;
+};
+
+G_DEFINE_TYPE(GUdevDevice, g_udev_device, G_TYPE_OBJECT)
+
+enum
+{
+UEVENT_SIGNAL,
+LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+static GUdevClient *singletone = NULL;
+
+static GUdevDevice *g_udev_device_new(GUdevDeviceInfo *usbdev);
+static LRESULT CALLBACK wnd_proc(HWND hwnd, UINT message, WPARAM wparam, 
LPARAM lparam);
+static gboolean get_usb_dev_info(libusb_device *dev, GUdevDeviceInfo *usbdev);
+
+GUdevClient *g_udev_client_new(const gchar* const *subsystems)
+{
+if (!singletone) {
+singletone = g_initable_new(G_UDEV_TYPE_CLIENT, NULL, NULL, NULL);
+return singletone;
+} else {
+return g_object_ref(singletone);
+}
+}
+
+static gboolean g_udev_client_initable_init(GInitable *initable, GCancellable 
*cancellable,
+GError **err)
+{
+GUdevClient *self;
+GUdevClientPrivate *priv;
+GUdevDeviceInfo *usbdev;
+GUdevDevice *udevice;
+libusb_device **dev;
+WNDCLASS wcls;
+int rc;
+
+g_return_val_if_fail(G_UDEV_IS_CLIENT(initable), FALSE);
+g_return_val_if_fail(cancellable == NULL, FALSE);
+
+self = G_UDEV_CLIENT(initable);
+

[Spice-devel] [spice-gtk Win32 v2 PATCH 4/5] Windows mingw: usb: Dynamically install a libusb driver for USB devices

2012-05-20 Thread Uri Lublin
- Added win-usb-driver-install.[ch]
- Added usbclerk.h

Operation (on Windows, spice-gtk point of view):
- After some sanity checks, just before redir'ing a USB device
  a libusb driver needs to be installed (before libusb can open/access it).
- A connection (NamedPipe) is established with usb-clerk, a libusb
  driver installation service, and a request for driver installation
  is sent.
- Installation status is asynchronously read from the pipe, and
  spice_usb_drv_install_finished() is called.
- Upon a successful intallation USB devices are being rescanned
  by libusb (to pick up the new driver - required a libusbx patch),
  and the device usbredir continues.

Linux operation is not changed.
---
 gtk/Makefile.am  |2 +
 gtk/usb-device-manager.c |   33 ++-
 gtk/usbclerk.h   |   35 +++
 gtk/win-usb-driver-install.c |  213 ++
 gtk/win-usb-driver-install.h |   39 
 5 files changed, 321 insertions(+), 1 deletions(-)
 create mode 100644 gtk/usbclerk.h
 create mode 100644 gtk/win-usb-driver-install.c
 create mode 100644 gtk/win-usb-driver-install.h

diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 81150ab..67ab9d7 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -313,6 +313,8 @@ WIN_USB_FILES= \
win-usb-dev.h   \
win-usb-dev.c   \
usbclerk.h  \
+   win-usb-driver-install.h\
+   win-usb-driver-install.c\
$(NULL)

 if OS_WIN32
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 2b6ce28..c373447 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -32,6 +32,7 @@
 #include gudev/gudev.h
 #elif defined(G_OS_WIN32)
 #include win-usb-dev.h
+#include win-usb-driver-install.h
 #else
 #warning Expecting one of G_OS_WIN32 and USE_GUDEV to be defined
 #endif
@@ -593,11 +594,16 @@ static void 
spice_usb_device_manager_add_dev(SpiceUsbDeviceManager  *self,
 priv-auto_conn_filter_rules_count,
 device, 0) == 0;

-if (can_redirect  auto_ok)
+if (can_redirect  auto_ok) {
+#ifdef G_OS_WIN32
+spice_win_usb_driver_install(self, device);
+#else
 spice_usb_device_manager_connect_device_async(self,
(SpiceUsbDevice *)device, NULL,
spice_usb_device_manager_auto_connect_cb,
libusb_ref_device(device));
+#endif
+}
 }

 SPICE_DEBUG(device added %p, device);
@@ -661,6 +667,31 @@ static void spice_usb_device_manager_channel_connect_cb(
 g_object_unref(result);
 }

+#ifdef G_OS_WIN32
+/**
+ * spice_usb_drv_install_finished:
+ * @self: #SpiceUsbDeviceManager
+ * @device: the libusb device for which a libusb driver got installed
+ * @status: status of driver-installation operation
+ *
+ * Called when an Windows libusb driver installation completed.
+ *
+ * If the driver installation was successful, continue with USB
+ * device redirection
+ */
+void spice_usb_drv_install_finished(SpiceUsbDeviceManager *self,
+ libusb_device *device, int status)
+{
+if (status) {
+spice_win_usb_rescan_devices(self, self-priv-context);
+spice_usb_device_manager_connect_device_async(self,
+(SpiceUsbDevice *)device, NULL,
+spice_usb_device_manager_auto_connect_cb,
+libusb_ref_device(device));
+}
+}
+#endif
+
 /* -- */
 /* private api*/

diff --git a/gtk/usbclerk.h b/gtk/usbclerk.h
new file mode 100644
index 000..5b1e3cf
--- /dev/null
+++ b/gtk/usbclerk.h
@@ -0,0 +1,35 @@
+#ifndef _H_USBCLERK
+#define _H_USBCLERK
+
+#include windows.h
+
+#define USB_CLERK_PIPE_NAME TEXT(.\\pipe\\usbclerkpipe)
+#define USB_CLERK_MAGIC 0xDADA
+#define USB_CLERK_VERSION   0x0002
+
+typedef struct USBClerkHeader {
+UINT16 magic;
+UINT16 version;
+UINT16 type;
+UINT16 size;
+} USBClerkHeader;
+
+enum {
+USB_CLERK_DRIVER_INSTALL = 1,
+USB_CLERK_DRIVER_REMOVE,
+USB_CLERK_REPLY,
+USB_CLERK_END_MESSAGE,
+};
+
+typedef struct USBClerkDriverOp {
+USBClerkHeader hdr;
+UINT16 vid;
+UINT16 pid;
+} USBClerkDriverOp;
+
+typedef struct USBClerkReply {
+USBClerkHeader hdr;
+UINT32 status;
+} USBClerkReply;
+
+#endif
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
new file mode 100644
index 000..07402c7
--- /dev/null
+++ b/gtk/win-usb-driver-install.c
@@ -0,0 +1,213 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   Red Hat Authors:
+   Uri Lublin u...@redhat.com
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General 

[Spice-devel] [spice-gtk Win32 v2 PATCH 5/5] Windows mingw: usb: Comment out some memory cleanups not working on Windows

2012-05-20 Thread Uri Lublin
It's not nice, but better than crashing.
---
 gtk/usb-device-manager.c |   15 +++
 gtk/usbutil.c|1 +
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index c373447..492689f 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -144,9 +144,14 @@ static void 
spice_usb_device_manager_init(SpiceUsbDeviceManager *self)

 priv-channels = g_ptr_array_new();
 #ifdef USE_USBREDIR
+#ifdef WIN32
+/* FIXME WIN32 use g_ptr_array_new_with_free_func */
+priv-devices  = g_ptr_array_new();
+#else
 priv-devices  = g_ptr_array_new_with_free_func((GDestroyNotify)
 libusb_unref_device);
 #endif
+#endif
 }

 static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
@@ -207,6 +212,8 @@ static gboolean 
spice_usb_device_manager_initable_init(GInitable  *initable,
 g_signal_connect(G_OBJECT(priv-udev), uevent,
  G_CALLBACK(spice_usb_device_manager_uevent_cb), self);

+/* FIXME: fix coldplug for WIN32 */
+#ifndef WIN32
 /* Do coldplug (detection of already connected devices) */
 libusb_get_device_list(priv-context, priv-coldplug_list);
 list = g_udev_client_query_by_subsystem(priv-udev, usb);
@@ -217,6 +224,7 @@ static gboolean 
spice_usb_device_manager_initable_init(GInitable  *initable,
 g_list_free(list);
 libusb_free_device_list(priv-coldplug_list, 1);
 priv-coldplug_list = NULL;
+#endif

 return TRUE;
 #else
@@ -236,6 +244,7 @@ static void spice_usb_device_manager_finalize(GObject 
*gobject)
 g_ptr_array_unref(priv-devices);

 #ifdef USE_USBREDIR
+/* FIXME: verify WIN32 cleanup*/
 g_clear_object(priv-udev);
 if (priv-context)
 libusb_exit(priv-context);
@@ -830,8 +839,14 @@ GPtrArray* 
spice_usb_device_manager_get_devices(SpiceUsbDeviceManager *self)
 SpiceUsbDeviceManagerPrivate *priv = self-priv;
 guint i;

+#ifdef G_OS_WIN32
+/* FIXME WIN32 use g_ptr_array_new_with_free_func */
+devices_copy = g_ptr_array_new();
+#else
 devices_copy = g_ptr_array_new_with_free_func((GDestroyNotify)
   libusb_unref_device);
+#endif
+
 for (i = 0; i  priv-devices-len; i++) {
 libusb_device *device = g_ptr_array_index(priv-devices, i);
 g_ptr_array_add(devices_copy, libusb_ref_device(device));
diff --git a/gtk/usbutil.c b/gtk/usbutil.c
index 704f973..fd3d2de 100644
--- a/gtk/usbutil.c
+++ b/gtk/usbutil.c
@@ -233,6 +233,7 @@ void spice_usb_util_get_device_strings(int bus, int address,
 *manufacturer = NULL;
 *product = NULL;

+/* FIXME: add windows support for manufacturer  product */
 #if __linux__
 *manufacturer = spice_usbutil_get_sysfs_attribute(bus, address, 
manufacturer);
 *product = spice_usbutil_get_sysfs_attribute(bus, address, product);
-- 
1.7.7.6

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] Is there any network bandwidth recommendation for spice?

2012-05-20 Thread Andrew Cathrow


- Original Message -
 From: David Jaša dj...@redhat.com
 To: Liang Han liang@gmail.com
 Cc: spice-devel@lists.freedesktop.org
 Sent: Wednesday, May 16, 2012 4:06:23 AM
 Subject: Re: [Spice-devel] Is there any network bandwidth recommendation for 
 spice?
 
 Hi Liang,
 
 5-10 Mbps per client should be sufficient to give nice user

That's very high if the user is just using desktop applications.
Obviously if you're streaming video though the more the merrier.


 experience.
 It works on slower connections too but you then feel you're working
 with
 remote machine.
 
 David
 
 
 Liang Han píše v Ne 06. 05. 2012 v 09:31 +0800:
  Guys,
  
  I would like to know if I have 200 spice clients connecting to
  remote
  servers and people do some web surfing and write documents, what is
  the recommended network bandwidth between the spice clients and the
  remote servers.
  
  Thanks!
  
  --
  Best regards
  Liang Han
  ___
  Spice-devel mailing list
  Spice-devel@lists.freedesktop.org
  http://lists.freedesktop.org/mailman/listinfo/spice-devel
 
 --
 
 David Jaša, RHCE
 
 SPICE QE based in Brno
 GPG Key: 22C33E24
 Fingerprint: 513A 060B D1B4 2A72 7F0D 0278 B125 CD00 22C3 3E24
 
 
 
 ___
 Spice-devel mailing list
 Spice-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/spice-devel
 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] Problem with dual-display full-screen client on X

2012-05-20 Thread Andrew Cathrow


- Original Message -
 From: Noel Van Hook noel.van.h...@intelligraphics.com
 To: Christophe Fergeau cferg...@redhat.com
 Cc: spice-devel@lists.freedesktop.org
 Sent: Monday, May 14, 2012 12:07:08 PM
 Subject: Re: [Spice-devel] Problem with dual-display full-screen client on X
 
 On Mon, May 14, 2012 at 8:54 AM, Christophe Fergeau
 cferg...@redhat.com wrote:
  Hey,
 
  On Fri, May 11, 2012 at 04:33:43PM -0500, Noel Van Hook wrote:
  Background information:
  I am running the guest OS (CentOS) with dual heads.
  I am also running the client on CentOS.
  When I open the client, two client windows appear (spice0 and
  spice1),
  and all is well with the world.
  The machine I am running the client on has two monitors, and is
  XRandR
  compliant.
 
  The bug:
  When I press Ctrl-Shift-F11 to change the guest to full-screen,
  both
  monitors change resolution, and the spice0 window properly appears
  in
  full screen mode on the left monitor.  The spice1 window never
  appears
  anywhere, and the right monitor goes black with an X cursor on
  it.
 
  I did some debugging, and it appears as though my window manager
  may
  be interfering with the clients attempt to use the second monitor.
 
  In the client code,  RedWindow::show() calls  RedWindow::move() to
  move the right client window onto the right monitor.
   RedWindow::move() in turn calls XMoveWindow(), but the
   XMoveWindow
  call appears to be ignored.  I suspect it is being intercepted by
  my
  window manager, because if, right before I call RedWindow::move(),
  I
  set the override_redirect attribute of _win to true, it works
  fine.
   (I then set it back to false when we leave fullscreen mode).
 
  So, this appears to fix it... but is it the right fix?  Or have I
  just
  patched a symptom of a deeper problem?
 
  This code in spice-client is quite hairy, and these days it's
  highly
  recommended to use virt-viewer/remote-viewer, did you test if they
  are
  doing the right thing on your setup ?
 
 
 I am not familiar with virt-viewer or remote-viewer, but it sounds
 like they are alternatives to spicec? If that is the case, it doesn't
 help me.  I don't get to choose which viewer to use, I just get to
 make it work. :-)

All future development is going into remote-viewer, so I'd advise moving 
forward.

 Noel
 
 --
 Noel Van Hook - Intelligraphics, Inc
 522 Cooper Ave N
 Red Lodge, MT 59068
 noel.van.h...@intelligraphics.com  (425) 770-5561
 ___
 Spice-devel mailing list
 Spice-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/spice-devel
 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel