Back to index

libunity  5.92.0
unity-inspector.c
Go to the documentation of this file.
00001 /* unity-inspector.c generated by valac 0.17.2, the Vala compiler
00002  * generated from unity-inspector.vala, do not modify */
00003 
00004 /*
00005  * Copyright (C) 2011 Canonical, Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License
00009  * version 3.0 as published by the Free Software Foundation.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License version 3.0 for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library. If not, see
00018  * <http://www.gnu.org/licenses/>.
00019  *
00020  * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
00021  *
00022  */
00023 /*
00024  * IMPLEMENTATION NOTE:
00025  * We want the generated C API to be nice and not too Vala-ish. We must
00026  * anticipate that libunity consumers will be written in both Vala , C,
00027  * and through GObject Introspection
00028  *
00029  */
00030 
00031 #include <glib.h>
00032 #include <glib-object.h>
00033 #include "unity.h"
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <gio/gio.h>
00037 
00038 #define _g_free0(var) (var = (g_free (var), NULL))
00039 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
00040 #define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
00041 #define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
00042 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
00043 
00044 struct _UnityInspectorPrivate {
00045        gboolean _unity_running;
00046        gchar* _unity_bus_name;
00047        GDBusConnection* bus;
00048        guint unity_watcher;
00049 };
00050 
00051 
00052 static gpointer unity_inspector_parent_class = NULL;
00053 static UnityInspector* unity_inspector_singleton;
00054 static UnityInspector* unity_inspector_singleton = NULL;
00055 
00056 #define UNITY_INSPECTOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UNITY_TYPE_INSPECTOR, UnityInspectorPrivate))
00057 enum  {
00058        UNITY_INSPECTOR_DUMMY_PROPERTY,
00059        UNITY_INSPECTOR_UNITY_RUNNING,
00060        UNITY_INSPECTOR_UNITY_BUS_NAME
00061 };
00062 static UnityInspector* unity_inspector_new (void);
00063 static UnityInspector* unity_inspector_construct (GType object_type);
00064 static void unity_inspector_on_unity_appeared (UnityInspector* self, GDBusConnection* conn, const gchar* name, const gchar* name_owner);
00065 static void _unity_inspector_on_unity_appeared_gbus_name_appeared_callback (GDBusConnection* connection, const gchar* name, const gchar* name_owner, gpointer self);
00066 static void unity_inspector_on_unity_vanished (UnityInspector* self, GDBusConnection* conn, const gchar* name);
00067 static void _unity_inspector_on_unity_vanished_gbus_name_vanished_callback (GDBusConnection* connection, const gchar* name, gpointer self);
00068 static void unity_inspector_finalize (GObject* obj);
00069 static void _vala_unity_inspector_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
00070 
00071 
00080 UnityInspector* unity_inspector_get_default (void) {
00081        UnityInspector* result = NULL;
00082        UnityInspector* _tmp0_;
00083        UnityInspector* _tmp2_;
00084        _tmp0_ = unity_inspector_singleton;
00085        if (_tmp0_ == NULL) {
00086               UnityInspector* _tmp1_;
00087               _tmp1_ = unity_inspector_new ();
00088               _g_object_unref0 (unity_inspector_singleton);
00089               unity_inspector_singleton = _tmp1_;
00090        }
00091        _tmp2_ = unity_inspector_singleton;
00092        result = _tmp2_;
00093        return result;
00094 }
00095 
00096 
00097 static void _unity_inspector_on_unity_appeared_gbus_name_appeared_callback (GDBusConnection* connection, const gchar* name, const gchar* name_owner, gpointer self) {
00098        unity_inspector_on_unity_appeared (self, connection, name, name_owner);
00099 }
00100 
00101 
00102 static void _unity_inspector_on_unity_vanished_gbus_name_vanished_callback (GDBusConnection* connection, const gchar* name, gpointer self) {
00103        unity_inspector_on_unity_vanished (self, connection, name);
00104 }
00105 
00106 
00107 static UnityInspector* unity_inspector_construct (GType object_type) {
00108        UnityInspector * self = NULL;
00109        GError * _inner_error_ = NULL;
00110        self = (UnityInspector*) g_object_new (object_type, NULL);
00111        {
00112               GDBusConnection* _tmp0_ = NULL;
00113               GDBusConnection* _tmp1_;
00114               GDBusConnection* _tmp2_;
00115               guint _tmp3_ = 0U;
00116               GDBusConnection* _tmp4_;
00117               GVariant* _tmp5_;
00118               GVariant* _tmp6_;
00119               GVariantType* _tmp7_;
00120               GVariantType* _tmp8_;
00121               GVariant* _tmp9_ = NULL;
00122               GVariant* _tmp10_;
00123               GVariant* is_running;
00124               GVariant* _tmp11_;
00125               _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
00126               _tmp1_ = _tmp0_;
00127               if (_inner_error_ != NULL) {
00128                      goto __catch11_g_error;
00129               }
00130               _g_object_unref0 (self->priv->bus);
00131               self->priv->bus = _tmp1_;
00132               _tmp2_ = self->priv->bus;
00133               _tmp3_ = g_bus_watch_name_on_connection_with_closures (_tmp2_, "com.canonical.Unity", G_BUS_NAME_WATCHER_FLAGS_NONE, (GClosure*) ((_unity_inspector_on_unity_appeared_gbus_name_appeared_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _unity_inspector_on_unity_appeared_gbus_name_appeared_callback, g_object_ref (self), g_object_unref)), (GClosure*) ((_unity_inspector_on_unity_vanished_gbus_name_vanished_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _unity_inspector_on_unity_vanished_gbus_name_vanished_callback, g_object_ref (self), g_object_unref)));
00134               self->priv->unity_watcher = _tmp3_;
00135               _tmp4_ = self->priv->bus;
00136               _tmp5_ = g_variant_new ("(s)", "com.canonical.Unity", NULL);
00137               g_variant_ref_sink (_tmp5_);
00138               _tmp6_ = _tmp5_;
00139               _tmp7_ = g_variant_type_new ("(b)");
00140               _tmp8_ = _tmp7_;
00141               _tmp9_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/dbus", "org.freedesktop.DBus", "NameHasOwner", _tmp6_, _tmp8_, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &_inner_error_);
00142               _tmp10_ = _tmp9_;
00143               _g_variant_type_free0 (_tmp8_);
00144               _g_variant_unref0 (_tmp6_);
00145               is_running = _tmp10_;
00146               if (_inner_error_ != NULL) {
00147                      goto __catch11_g_error;
00148               }
00149               _tmp11_ = is_running;
00150               g_variant_get (_tmp11_, "(b)", &self->priv->_unity_running, NULL);
00151               _g_variant_unref0 (is_running);
00152        }
00153        goto __finally11;
00154        __catch11_g_error:
00155        {
00156               GError* e = NULL;
00157               GError* _tmp12_;
00158               const gchar* _tmp13_;
00159               e = _inner_error_;
00160               _inner_error_ = NULL;
00161               _tmp12_ = e;
00162               _tmp13_ = _tmp12_->message;
00163               g_critical ("unity-inspector.vala:96: Unable to connect to session bus: %s", _tmp13_);
00164               _g_error_free0 (e);
00165        }
00166        __finally11:
00167        if (_inner_error_ != NULL) {
00168               g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
00169               g_clear_error (&_inner_error_);
00170               return NULL;
00171        }
00172        return self;
00173 }
00174 
00175 
00176 static UnityInspector* unity_inspector_new (void) {
00177        return unity_inspector_construct (UNITY_TYPE_INSPECTOR);
00178 }
00179 
00180 
00181 static void unity_inspector_on_unity_appeared (UnityInspector* self, GDBusConnection* conn, const gchar* name, const gchar* name_owner) {
00182        const gchar* _tmp0_;
00183        const gchar* _tmp2_;
00184        gchar* _tmp3_;
00185        g_return_if_fail (self != NULL);
00186        g_return_if_fail (conn != NULL);
00187        g_return_if_fail (name != NULL);
00188        g_return_if_fail (name_owner != NULL);
00189        _tmp0_ = name;
00190        if (g_strcmp0 (_tmp0_, "com.canonical.Unity") != 0) {
00191               const gchar* _tmp1_;
00192               _tmp1_ = name;
00193               g_critical ("Internal error in libunity: Got name owner notification " "from '%'. Expected 'com.canonical.Unity'", _tmp1_);
00194               return;
00195        }
00196        self->priv->_unity_running = TRUE;
00197        _tmp2_ = name_owner;
00198        _tmp3_ = g_strdup (_tmp2_);
00199        _g_free0 (self->priv->_unity_bus_name);
00200        self->priv->_unity_bus_name = _tmp3_;
00201        g_object_notify ((GObject*) self, "unity-running");
00202        g_object_notify ((GObject*) self, "unity-bus-name");
00203 }
00204 
00205 
00206 static void unity_inspector_on_unity_vanished (UnityInspector* self, GDBusConnection* conn, const gchar* name) {
00207        g_return_if_fail (self != NULL);
00208        g_return_if_fail (conn != NULL);
00209        g_return_if_fail (name != NULL);
00210        self->priv->_unity_running = FALSE;
00211        _g_free0 (self->priv->_unity_bus_name);
00212        self->priv->_unity_bus_name = NULL;
00213        g_object_notify ((GObject*) self, "unity-running");
00214        g_object_notify ((GObject*) self, "unity-bus-name");
00215 }
00216 
00217 
00218 gboolean unity_inspector_get_unity_running (UnityInspector* self) {
00219        gboolean result;
00220        gboolean _tmp0_;
00221        g_return_val_if_fail (self != NULL, FALSE);
00222        _tmp0_ = self->priv->_unity_running;
00223        result = _tmp0_;
00224        return result;
00225 }
00226 
00227 
00228 const gchar* unity_inspector_get_unity_bus_name (UnityInspector* self) {
00229        const gchar* result;
00230        const gchar* _tmp0_;
00231        g_return_val_if_fail (self != NULL, NULL);
00232        _tmp0_ = self->priv->_unity_bus_name;
00233        result = _tmp0_;
00234        return result;
00235 }
00236 
00237 
00238 static void unity_inspector_class_init (UnityInspectorClass * klass) {
00239        unity_inspector_parent_class = g_type_class_peek_parent (klass);
00240        g_type_class_add_private (klass, sizeof (UnityInspectorPrivate));
00241        G_OBJECT_CLASS (klass)->get_property = _vala_unity_inspector_get_property;
00242        G_OBJECT_CLASS (klass)->finalize = unity_inspector_finalize;
00247        g_object_class_install_property (G_OBJECT_CLASS (klass), UNITY_INSPECTOR_UNITY_RUNNING, g_param_spec_boolean ("unity-running", "unity-running", "unity-running", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
00252        g_object_class_install_property (G_OBJECT_CLASS (klass), UNITY_INSPECTOR_UNITY_BUS_NAME, g_param_spec_string ("unity-bus-name", "unity-bus-name", "unity-bus-name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
00253 }
00254 
00255 
00256 static void unity_inspector_instance_init (UnityInspector * self) {
00257        self->priv = UNITY_INSPECTOR_GET_PRIVATE (self);
00258        self->priv->_unity_running = FALSE;
00259        self->priv->_unity_bus_name = NULL;
00260 }
00261 
00262 
00263 static void unity_inspector_finalize (GObject* obj) {
00264        UnityInspector * self;
00265        self = G_TYPE_CHECK_INSTANCE_CAST (obj, UNITY_TYPE_INSPECTOR, UnityInspector);
00266        _g_free0 (self->priv->_unity_bus_name);
00267        _g_object_unref0 (self->priv->bus);
00268        G_OBJECT_CLASS (unity_inspector_parent_class)->finalize (obj);
00269 }
00270 
00271 
00280 GType unity_inspector_get_type (void) {
00281        static volatile gsize unity_inspector_type_id__volatile = 0;
00282        if (g_once_init_enter (&unity_inspector_type_id__volatile)) {
00283               static const GTypeInfo g_define_type_info = { sizeof (UnityInspectorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) unity_inspector_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UnityInspector), 0, (GInstanceInitFunc) unity_inspector_instance_init, NULL };
00284               GType unity_inspector_type_id;
00285               unity_inspector_type_id = g_type_register_static (G_TYPE_OBJECT, "UnityInspector", &g_define_type_info, 0);
00286               g_once_init_leave (&unity_inspector_type_id__volatile, unity_inspector_type_id);
00287        }
00288        return unity_inspector_type_id__volatile;
00289 }
00290 
00291 
00292 static void _vala_unity_inspector_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
00293        UnityInspector * self;
00294        self = G_TYPE_CHECK_INSTANCE_CAST (object, UNITY_TYPE_INSPECTOR, UnityInspector);
00295        switch (property_id) {
00296               case UNITY_INSPECTOR_UNITY_RUNNING:
00297               g_value_set_boolean (value, unity_inspector_get_unity_running (self));
00298               break;
00299               case UNITY_INSPECTOR_UNITY_BUS_NAME:
00300               g_value_set_string (value, unity_inspector_get_unity_bus_name (self));
00301               break;
00302               default:
00303               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
00304               break;
00305        }
00306 }
00307 
00308 
00309