[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [virt-viewer 11/20] Don't try to parse ticket for all actions



I initially hardcoded ticket parsing while parsing the response to
an action request since this was easier to quickly test the code.
However this is limited and wrong. This commit adds an optional
function pointer parameter to the response parsing code so that
action-specific behaviour can be done while parsing the response.
---
 src/ovirt-proxy.c |   27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/ovirt-proxy.c b/src/ovirt-proxy.c
index f7b06d8..243d75d 100644
--- a/src/ovirt-proxy.c
+++ b/src/ovirt-proxy.c
@@ -517,8 +517,11 @@ static void parse_fault(RestXmlNode *root, GError **error)
     g_set_error(error, OVIRT_PROXY_ERROR, OVIRT_PROXY_FAULT, node->content);
 }
 
+typedef gboolean (*ActionResponseParser)(RestXmlNode *node, OvirtVm *vm, GError **error);
+
 static gboolean
-parse_action_response(RestProxyCall *call, OvirtVm *vm, GError **error)
+parse_action_response(RestProxyCall *call, OvirtVm *vm,
+                      ActionResponseParser response_parser, GError **error)
 {
     RestXmlParser *parser;
     RestXmlNode *root;
@@ -533,7 +536,11 @@ parse_action_response(RestProxyCall *call, OvirtVm *vm, GError **error)
 
     if (g_strcmp0(root->name, "action") == 0) {
         if (parse_action_status(root, error) == OVIRT_RESPONSE_COMPLETE) {
-            result = parse_ticket_status(root, vm, error);
+            if (response_parser) {
+                result = response_parser(root, vm, error);
+            } else {
+                result = TRUE;
+            }
         }
     } else if (g_strcmp0(root->name, "fault") == 0) {
         parse_fault(root, error);
@@ -547,9 +554,9 @@ parse_action_response(RestProxyCall *call, OvirtVm *vm, GError **error)
     return result;
 }
 
-
-static gboolean ovirt_proxy_vm_action(OvirtProxy *proxy, OvirtVm *vm,
-                                      const char *action, GError **error)
+static gboolean
+ovirt_proxy_vm_action(OvirtProxy *proxy, OvirtVm *vm, const char *action,
+                      ActionResponseParser response_parser, GError **error)
 {
     RestProxyCall *call;
     const char *function;
@@ -574,7 +581,7 @@ static gboolean ovirt_proxy_vm_action(OvirtProxy *proxy, OvirtVm *vm,
         return FALSE;
     }
 
-    parse_action_response(call, vm, error);
+    parse_action_response(call, vm, response_parser, error);
 
     g_object_unref(G_OBJECT(call));
 
@@ -583,17 +590,19 @@ static gboolean ovirt_proxy_vm_action(OvirtProxy *proxy, OvirtVm *vm,
 
 gboolean ovirt_proxy_vm_get_ticket(OvirtProxy *proxy, OvirtVm *vm, GError **error)
 {
-    return ovirt_proxy_vm_action(proxy, vm, "ticket", error);
+    return ovirt_proxy_vm_action(proxy, vm, "ticket",
+                                 parse_ticket_status,
+                                 error);
 }
 
 gboolean ovirt_proxy_vm_start(OvirtProxy *proxy, OvirtVm *vm, GError **error)
 {
-    return ovirt_proxy_vm_action(proxy, vm, "start", error);
+    return ovirt_proxy_vm_action(proxy, vm, "start", NULL, error);
 }
 
 gboolean ovirt_proxy_vm_stop(OvirtProxy *proxy, OvirtVm *vm, GError **error)
 {
-    return ovirt_proxy_vm_action(proxy, vm, "stop", error);
+    return ovirt_proxy_vm_action(proxy, vm, "stop", NULL, error);
 }
 
 static void
-- 
1.7.10.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]