[Spice-devel] [spice-gtk 2/4] smartcard: Add methods to act on software readers

Christophe Fergeau cfergeau at redhat.com
Wed Jun 19 08:33:25 PDT 2013


Currently, the methods to insert/remove smartcards from a software
smartcard reader are global to the SpiceSmartcardManager singleton
rather than acting on a SpiceSmartcardreader object.
This commit adds insert/remove methods acting on such objects.
---
 gtk/map-file            |  2 ++
 gtk/smartcard-manager.c | 73 ++++++++++++++++++++++++++++++++++++++++++-------
 gtk/smartcard-manager.h |  2 ++
 gtk/spice-glib-sym-file |  2 ++
 4 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/gtk/map-file b/gtk/map-file
index 558a4d7..0419ecb 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -95,7 +95,9 @@ spice_smartcard_manager_get_type;
 spice_smartcard_manager_insert_card;
 spice_smartcard_manager_remove_card;
 spice_smartcard_reader_get_type;
+spice_smartcard_reader_insert_card;
 spice_smartcard_reader_is_software;
+spice_smartcard_reader_remove_card;
 spice_usb_device_get_description;
 spice_usb_device_get_type;
 spice_usb_device_manager_can_redirect_device;
diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
index 3b86dfb..366e2dd 100644
--- a/gtk/smartcard-manager.c
+++ b/gtk/smartcard-manager.c
@@ -536,6 +536,50 @@ gboolean spice_smartcard_manager_init_finish(SpiceSession *session,
 }
 
 /**
+ * spice_smartcard_reader_insert_card:
+ * @reader: a #SpiceSmartcardReader
+ *
+ * Simulates insertion of a smartcard in the software smartcard reader
+ * @reader. If @reader is not a software smartcard reader, FALSE will be
+ * returned.
+ *
+ * Returns: TRUE if insertion of a card was successfully simulated, FALSE
+ * otherwise
+ */
+gboolean spice_smartcard_reader_insert_card(SpiceSmartcardReader *reader)
+{
+    VCardEmulError status;
+
+    g_return_val_if_fail(spice_smartcard_reader_is_software(reader), FALSE);
+
+    status = vcard_emul_force_card_insert((VReader *)reader);
+
+    return (status == VCARD_EMUL_OK);
+}
+
+/**
+ * spice_smartcard_reader_remove_card:
+ * @reader: a #SpiceSmartcardReader
+ *
+ * Simulates removal of a smartcard from the software smartcard reader
+ * @reader. If @reader is not a software smartcard reader, FALSE will be
+ * returned.
+ *
+ * Returns: TRUE if removal of a card was successfully simulated, FALSE
+ * otherwise
+ */
+gboolean spice_smartcard_reader_remove_card(SpiceSmartcardReader *reader)
+{
+    VCardEmulError status;
+
+    g_return_val_if_fail(spice_smartcard_reader_is_software(reader), FALSE);
+
+    status = vcard_emul_force_card_remove((VReader *)reader);
+
+    return (status == VCARD_EMUL_OK);
+}
+
+/**
  * spice_smartcard_manager_insert_card:
  * @manager: a #SpiceSmartcardManager
  *
@@ -550,14 +594,13 @@ gboolean spice_smartcard_manager_init_finish(SpiceSession *session,
  */
 gboolean spice_smartcard_manager_insert_card(SpiceSmartcardManager *manager)
 {
-    VCardEmulError status;
+    SpiceSmartcardReader *reader;
 
-    if (manager->priv->software_reader != NULL)
-        return FALSE;
+    g_return_val_if_fail (manager->priv->software_reader != NULL, FALSE);
 
-    status = vcard_emul_force_card_insert(manager->priv->software_reader);
+    reader = (SpiceSmartcardReader *)manager->priv->software_reader;
 
-    return (status == VCARD_EMUL_OK);
+    return spice_smartcard_reader_insert_card(reader);
 }
 
 /**
@@ -573,14 +616,13 @@ gboolean spice_smartcard_manager_insert_card(SpiceSmartcardManager *manager)
  */
 gboolean spice_smartcard_manager_remove_card(SpiceSmartcardManager *manager)
 {
-    VCardEmulError status;
+    SpiceSmartcardReader *reader;
 
-    if (manager->priv->software_reader != NULL)
-        return FALSE;
+    g_return_val_if_fail (manager->priv->software_reader != NULL, FALSE);
 
-    status = vcard_emul_force_card_remove(manager->priv->software_reader);
+    reader = (SpiceSmartcardReader *)manager->priv->software_reader;
 
-    return (status == VCARD_EMUL_OK);
+    return spice_smartcard_reader_remove_card(reader);
 }
 #else
 gboolean spice_smartcard_reader_is_software(SpiceSmartcardReader *reader)
@@ -616,4 +658,15 @@ gboolean spice_smartcard_manager_remove_card(SpiceSmartcardManager *manager)
 {
     return FALSE;
 }
+
+gboolean spice_smartcard_reader_insert_card(SpiceSmartcardReader *reader)
+{
+    return FALSE;
+}
+
+gboolean spice_smartcard_reader_remove_card(SpiceSmartcardReader *reader)
+{
+    return FALSE;
+}
+
 #endif /* USE_SMARTCARD */
diff --git a/gtk/smartcard-manager.h b/gtk/smartcard-manager.h
index 65c6934..ac00be8 100644
--- a/gtk/smartcard-manager.h
+++ b/gtk/smartcard-manager.h
@@ -71,6 +71,8 @@ SpiceSmartcardManager *spice_smartcard_manager_get(void);
 gboolean spice_smartcard_manager_insert_card(SpiceSmartcardManager *manager);
 gboolean spice_smartcard_manager_remove_card(SpiceSmartcardManager *manager);
 gboolean spice_smartcard_reader_is_software(SpiceSmartcardReader *reader);
+gboolean spice_smartcard_reader_insert_card(SpiceSmartcardReader *reader);
+gboolean spice_smartcard_reader_remove_card(SpiceSmartcardReader *reader);
 
 G_END_DECLS
 
diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file
index 5a580d6..3db6a0c 100644
--- a/gtk/spice-glib-sym-file
+++ b/gtk/spice-glib-sym-file
@@ -71,7 +71,9 @@ spice_smartcard_manager_get_type
 spice_smartcard_manager_insert_card
 spice_smartcard_manager_remove_card
 spice_smartcard_reader_get_type
+spice_smartcard_reader_insert_card
 spice_smartcard_reader_is_software
+spice_smartcard_reader_remove_card
 spice_usb_device_get_description
 spice_usb_device_get_type
 spice_usb_device_manager_can_redirect_device
-- 
1.8.2.1



More information about the Spice-devel mailing list