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

[virt-tools-list] [virt-viewer 14/20] Make OvirtProxy inherit from RestProxy



This makes more sense, I don't know why I haven't done it earlier.
---
 src/ovirt-proxy.c |   86 +++++++----------------------------------------------
 src/ovirt-proxy.h |    6 ++--
 2 files changed, 14 insertions(+), 78 deletions(-)

diff --git a/src/ovirt-proxy.c b/src/ovirt-proxy.c
index 16e1eaa..7e3a071 100644
--- a/src/ovirt-proxy.c
+++ b/src/ovirt-proxy.c
@@ -31,23 +31,17 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <rest/rest-proxy.h>
 #include <rest/rest-xml-node.h>
 #include <rest/rest-xml-parser.h>
 
-G_DEFINE_TYPE (OvirtProxy, ovirt_proxy, G_TYPE_OBJECT);
+G_DEFINE_TYPE (OvirtProxy, ovirt_proxy, REST_TYPE_PROXY);
 
 struct _OvirtProxyPrivate {
-    RestProxy *rest_proxy;
     GHashTable *vms;
 };
 
 #define OVIRT_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), OVIRT_TYPE_PROXY, OvirtProxyPrivate))
 
-enum {
-    PROP_0,
-    PROP_URI,
-};
 
 #define ADMIN_LOGIN "admin internal"
 #define ADMIN_PASSWORD "XXXXXXX"
@@ -373,9 +367,8 @@ static gboolean ovirt_proxy_fetch_vms(OvirtProxy *proxy, GError **error)
     RestProxyCall *call;
 
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
-    g_return_val_if_fail(REST_IS_PROXY(proxy->priv->rest_proxy), FALSE);
 
-    call = REST_PROXY_CALL(ovirt_rest_call_new(proxy->priv->rest_proxy));
+    call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));
     rest_proxy_call_set_function(call, "vms");
 
     if (!rest_proxy_call_sync(call, error)) {
@@ -458,7 +451,6 @@ gboolean ovirt_proxy_lookup_vm_async(OvirtProxy *proxy, const char *vm_name,
     OvirtVm *vm;
 
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
-    g_return_val_if_fail(REST_IS_PROXY(proxy->priv->rest_proxy), FALSE);
     g_return_val_if_fail(vm_name != NULL, FALSE);
     g_return_val_if_fail(async_cb != NULL, FALSE);
 
@@ -473,7 +465,7 @@ gboolean ovirt_proxy_lookup_vm_async(OvirtProxy *proxy, const char *vm_name,
         data->async_cb = async_cb;
         data->user_data = user_data;
         data->vm_name = g_strdup(vm_name);
-        call = REST_PROXY_CALL(ovirt_rest_call_new(proxy->priv->rest_proxy));
+        call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));
         rest_proxy_call_set_function(call, "vms");
 
         if (!rest_proxy_call_async(call, fetch_vms_async_cb, G_OBJECT(proxy),
@@ -635,13 +627,12 @@ ovirt_proxy_vm_action(OvirtProxy *proxy, OvirtVm *vm, const char *action,
     g_return_val_if_fail(OVIRT_IS_VM(vm), FALSE);
     g_return_val_if_fail(action != NULL, FALSE);
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
-    g_return_val_if_fail(REST_IS_PROXY(proxy->priv->rest_proxy), FALSE);
     g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
 
     function = ovirt_vm_get_action(vm, action);
     g_return_val_if_fail(function != NULL, FALSE);
 
-    call = REST_PROXY_CALL(ovirt_rest_call_new(proxy->priv->rest_proxy));
+    call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));
     rest_proxy_call_set_method(call, "POST");
     rest_proxy_call_set_function(call, function);
     rest_proxy_call_add_param(call, "async", "false");
@@ -728,13 +719,12 @@ ovirt_proxy_vm_action_async(OvirtProxy *proxy, OvirtVm *vm,
     g_return_val_if_fail(OVIRT_IS_VM(vm), FALSE);
     g_return_val_if_fail(action != NULL, FALSE);
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
-    g_return_val_if_fail(REST_IS_PROXY(proxy->priv->rest_proxy), FALSE);
     g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
 
     function = ovirt_vm_get_action(vm, action);
     g_return_val_if_fail(function != NULL, FALSE);
 
-    call = REST_PROXY_CALL(ovirt_rest_call_new(proxy->priv->rest_proxy));
+    call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));
     rest_proxy_call_set_method(call, "POST");
     rest_proxy_call_set_function(call, function);
     rest_proxy_call_add_param(call, "async", "false");
@@ -787,57 +777,10 @@ ovirt_proxy_vm_stop_async(OvirtProxy *proxy, OvirtVm *vm,
 }
 
 static void
-ovirt_get_property(GObject *object, guint property_id,
-                   GValue *value, GParamSpec *pspec)
-{
-    OvirtProxy *self = OVIRT_PROXY(object);
-
-    switch (property_id) {
-    case PROP_URI: {
-        char *uri;
-        g_object_get(G_OBJECT(self->priv->rest_proxy),
-                     "url-format", &uri,
-                     NULL);
-        g_value_take_string(value, uri);
-        break;
-    }
-
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-    }
-}
-
-static void
-ovirt_set_property(GObject *object, guint property_id,
-                   const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
-{
-    OvirtProxy *self = OVIRT_PROXY(object);
-
-    switch (property_id) {
-    case PROP_URI:
-        if (self->priv->rest_proxy)
-            g_object_unref(self->priv->rest_proxy);
-        self->priv->rest_proxy = rest_proxy_new_with_authentication(g_value_get_string(value),
-                                                                    FALSE,
-                                                                    ADMIN_LOGIN,
-                                                                    ADMIN_PASSWORD);
-        g_object_set(G_OBJECT(self->priv->rest_proxy),
-                     "ssl-strict", FALSE,
-                     NULL);
-        break;
-
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-    }
-}
-
-
-static void
 ovirt_proxy_dispose(GObject *obj)
 {
     OvirtProxy *proxy = OVIRT_PROXY(obj);
 
-    g_clear_object(&proxy->priv->rest_proxy);
     if (proxy->priv->vms) {
         g_hash_table_unref(proxy->priv->vms);
         proxy->priv->vms = NULL;
@@ -852,20 +795,8 @@ ovirt_proxy_class_init(OvirtProxyClass *klass)
     GObjectClass *oclass = G_OBJECT_CLASS(klass);
 
     oclass->dispose = ovirt_proxy_dispose;
-    oclass->get_property = ovirt_get_property;
-    oclass->set_property = ovirt_set_property;
 
     g_type_class_add_private(klass, sizeof(OvirtProxyPrivate));
-
-    g_object_class_install_property(oclass,
-                                    PROP_URI,
-                                    g_param_spec_string("uri",
-                                                        "REST URI",
-                                                        "REST URI",
-                                                        NULL,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT_ONLY |
-                                                        G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -876,5 +807,10 @@ ovirt_proxy_init(OvirtProxy *self)
 
 OvirtProxy *ovirt_proxy_new(const char *uri)
 {
-    return g_object_new(OVIRT_TYPE_PROXY, "uri", uri, NULL);
+    return g_object_new(OVIRT_TYPE_PROXY,
+                        "url-format", uri,
+                        "ssl-strict", FALSE,
+                        "username", ADMIN_LOGIN,
+                        "password", ADMIN_PASSWORD,
+                        NULL);
 }
diff --git a/src/ovirt-proxy.h b/src/ovirt-proxy.h
index 1272b9d..fc796a5 100644
--- a/src/ovirt-proxy.h
+++ b/src/ovirt-proxy.h
@@ -22,7 +22,7 @@
 #ifndef __OVIRT_PROXY_H__
 #define __OVIRT_PROXY_H__
 
-#include <glib-object.h>
+#include <rest/rest-proxy.h>
 #include <ovirt-vm.h>
 
 G_BEGIN_DECLS
@@ -49,13 +49,13 @@ typedef struct _OvirtProxyClass OvirtProxyClass;
 typedef struct _OvirtProxyPrivate OvirtProxyPrivate;
 
 struct _OvirtProxy {
-    GObject parent;
+    RestProxy parent;
 
     OvirtProxyPrivate *priv;
 };
 
 struct _OvirtProxyClass {
-    GObjectClass parent_class;
+    RestProxyClass parent_class;
 };
 
 typedef enum {
-- 
1.7.10.2


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