[libcloudproviders/account-wrapper: 1/2] cloudprovider: Add wrapper for CloudProviderAccount1 skeleton



commit 05bddeb75684e205f696e657abd49dfbcf33fc5d
Author: Julius Härtl <jus bitgrid net>
Date:   Thu Aug 31 18:19:28 2017 +0200

    cloudprovider: Add wrapper for CloudProviderAccount1 skeleton

 src/cloudprovider.c            |  13 +++
 src/cloudprovider.h            |   5 ++
 src/cloudprovideraccount.c     | 191 +++++++++++++++++++++++++++++++++++++++++
 src/cloudprovideraccount.h     |  56 ++++++++++++
 src/cloudprovideraccountpriv.h |  32 +++++++
 src/meson.build                |   2 +
 6 files changed, 299 insertions(+)
---
diff --git a/src/cloudprovider.c b/src/cloudprovider.c
index c312f66..9da5e61 100644
--- a/src/cloudprovider.c
+++ b/src/cloudprovider.c
@@ -18,6 +18,7 @@
  */
 
 #include "cloudprovider.h"
+#include "cloudprovideraccountpriv.h"
 #include "cloudprovider-generated.h"
 #include <gio/gio.h>
 
@@ -35,6 +36,18 @@ typedef struct
 G_DEFINE_TYPE_WITH_PRIVATE (CloudProvider, cloud_provider, G_TYPE_OBJECT)
 
 void
+cloud_provider_add_account (CloudProvider* cloud_provider, CloudProviderAccount *account)
+{
+  CloudProviderPrivate *priv = cloud_provider_get_instance_private(cloud_provider);
+  CloudProviderObjectSkeleton *object;
+  gchar *object_path = g_strconcat (priv->object_path, "/", cloud_provider_account_get_object_name 
(account), NULL);
+  object = cloud_provider_object_skeleton_new(object_path);
+  cloud_provider_object_skeleton_set_account1(object, CLOUD_PROVIDER_ACCOUNT1 
(cloud_provider_account_get_skeleton (account)));
+  g_dbus_object_manager_server_export (priv->manager, G_DBUS_OBJECT_SKELETON(object));
+  g_free(object_path);
+}
+
+void
 cloud_provider_export_account(CloudProvider* cloud_provider,
                               const gchar *account_name,
                               CloudProviderAccount1 *account)
diff --git a/src/cloudprovider.h b/src/cloudprovider.h
index 687032b..c10a655 100644
--- a/src/cloudprovider.h
+++ b/src/cloudprovider.h
@@ -22,6 +22,7 @@
 #include "cloudprovider-generated.h"
 /* for CloudProviderStatus enum */
 #include "cloudproviderproxy.h"
+#include "cloudprovideraccount.h"
 
 G_BEGIN_DECLS
 
@@ -71,6 +72,10 @@ cloud_provider_unexport_action_group (CloudProvider *cloud_provider,
                                       const gchar   *account_name);
 
 void
+cloud_provider_add_account (CloudProvider* cloud_provider,
+                            CloudProviderAccount *account);
+
+void
 cloud_provider_export_objects (CloudProvider* cloud_provider);
 
 void
diff --git a/src/cloudprovideraccount.c b/src/cloudprovideraccount.c
new file mode 100644
index 0000000..3f662e3
--- /dev/null
+++ b/src/cloudprovideraccount.c
@@ -0,0 +1,191 @@
+/* cloudprovideraccount.c
+ *
+ * Copyright (C) 2017 Julius Haertl <jus bitgrid net>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cloudprovideraccount.h"
+#include "cloudprovider-generated.h"
+#include <gio/gio.h>
+
+typedef struct
+{
+  gchar *object_name;
+  CloudProviderAccount1 *skeleton;
+} CloudProviderAccountPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderAccount, cloud_provider_account, G_TYPE_OBJECT)
+
+gchar *
+cloud_provider_account_get_object_name (CloudProviderAccount *self)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  return priv->object_name;
+}
+
+GDBusInterfaceSkeleton*
+cloud_provider_account_get_skeleton (CloudProviderAccount *self)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  return G_DBUS_INTERFACE_SKELETON(priv->skeleton);
+}
+
+static void
+on_get_name (CloudProviderAccount   *self,
+             GDBusMethodInvocation  *invocation,
+             gpointer                user_data)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  gchar *name;
+  g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT(self), "handle_get_name", &name);
+  cloud_provider_account1_complete_get_name (priv->skeleton, invocation, name);
+}
+
+static void
+on_get_icon (CloudProviderAccount   *self,
+             GDBusMethodInvocation  *invocation,
+             gpointer                user_data)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  GIcon *icon = NULL;
+  g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT(self), "handle_get_icon", &icon);
+  cloud_provider_account1_complete_get_icon (priv->skeleton, invocation, g_variant_new("v", 
g_icon_serialize(icon)));
+}
+
+static void
+on_get_path (CloudProviderAccount   *self,
+             GDBusMethodInvocation  *invocation,
+             gpointer                user_data)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  gchar *path = NULL;
+  g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT(self), "handle_get_path", &path);
+  cloud_provider_account1_complete_get_path (priv->skeleton, invocation, path);
+}
+
+static void
+on_get_status (CloudProviderAccount   *self,
+               GDBusMethodInvocation  *invocation,
+               gpointer                user_data)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  guint *status = 0;
+  g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT(self), "handle_get_status", &status);
+  cloud_provider_account1_complete_get_status (priv->skeleton, invocation, status);
+}
+
+static void
+on_get_status_details (CloudProviderAccount   *self,
+                       GDBusMethodInvocation  *invocation,
+                       gpointer                user_data)
+{
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+  gchar *status_details = NULL;
+  g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT(self), "handle_get_status_details", &status_details);
+  cloud_provider_account1_complete_get_status_details (priv->skeleton, invocation, status_details);
+}
+
+CloudProviderAccount*
+cloud_provider_account_new (const gchar *object_name)
+{
+  CloudProviderAccount *self;
+  CloudProviderAccountPrivate *priv;
+
+  self = g_object_new (TYPE_CLOUD_PROVIDER_ACCOUNT, NULL);
+  priv = cloud_provider_account_get_instance_private (self);
+
+  priv->skeleton = cloud_provider_account1_skeleton_new ();
+
+  g_signal_connect_swapped(priv->skeleton, "handle_get_name", G_CALLBACK (on_get_name), self);
+  g_signal_connect_swapped(priv->skeleton, "handle_get_icon", G_CALLBACK (on_get_icon), self);
+  g_signal_connect_swapped(priv->skeleton, "handle_get_path", G_CALLBACK (on_get_path), self);
+  g_signal_connect_swapped(priv->skeleton, "handle_get_status", G_CALLBACK (on_get_status), self);
+  g_signal_connect_swapped(priv->skeleton, "handle_get_status_details", G_CALLBACK (on_get_status_details), 
self);
+
+  priv->object_name = g_strdup (object_name);
+
+  return self;
+}
+
+static void
+cloud_provider_account_finalize (GObject *object)
+{
+  CloudProviderAccount *self = (CloudProviderAccount *)object;
+  CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self);
+
+  g_free (priv->object_name);
+  g_object_unref (priv->skeleton);
+
+  G_OBJECT_CLASS (cloud_provider_account_parent_class)->finalize (object);
+}
+
+static void
+cloud_provider_account_class_init (CloudProviderAccountClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = cloud_provider_account_finalize;
+
+  g_signal_new ("handle_get_name",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_POINTER,
+                  0);
+  g_signal_new ("handle_get_icon",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_POINTER,
+                  0);
+  g_signal_new ("handle_get_path",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_POINTER,
+                  0);
+  g_signal_new ("handle_get_status",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_POINTER,
+                  0);
+  g_signal_new ("handle_get_status_details",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_POINTER,
+                  0);
+}
+
+static void
+cloud_provider_account_init (CloudProviderAccount *self)
+{
+}
diff --git a/src/cloudprovideraccount.h b/src/cloudprovideraccount.h
new file mode 100644
index 0000000..ca432ee
--- /dev/null
+++ b/src/cloudprovideraccount.h
@@ -0,0 +1,56 @@
+/* cloudprovideraccount.h
+ *
+ * Copyright (C) 2017 Julius Haertl <jus bitgrid net>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CLOUD_PROVIDER_ACCOUNT_H
+#define CLOUD_PROVIDER_ACCOUNT_H
+
+G_BEGIN_DECLS
+
+#define TYPE_CLOUD_PROVIDER_ACCOUNT            (cloud_provider_account_get_type())
+#define CLOUD_PROVIDER_ACCOUNT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccount))
+#define CLOUD_PROVIDER_ACCOUNT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass))
+#define IS_CLOUD_PROVIDER_ACCOUNT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
TYPE_CLOUD_PROVIDER_ACCOUNT))
+#define IS_CLOUD_PROVIDER_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
TYPE_CLOUD_PROVIDER_ACCOUNT))
+#define CLOUD_PROVIDER_ACCOUNT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass))
+
+typedef struct _CloudProviderAccount CloudProviderAccount;
+typedef struct _CloudProviderAccountClass CloudProviderAccountClass;
+
+
+struct _CloudProviderAccountClass
+{
+  GObjectClass parent_class;
+};
+
+struct _CloudProviderAccount
+{
+  GObject parent_instance;
+};
+
+GType
+cloud_provider_account_get_type (void) G_GNUC_CONST;
+
+void
+cloud_provider_account_emit_changed (CloudProviderAccount *cloud_provider_account);
+
+CloudProviderAccount*
+cloud_provider_account_new (const gchar *account_object_name);
+
+G_END_DECLS
+
+#endif /* CLOUD_PROVIDER_ACCOUNT_H */
diff --git a/src/cloudprovideraccountpriv.h b/src/cloudprovideraccountpriv.h
new file mode 100644
index 0000000..77908d3
--- /dev/null
+++ b/src/cloudprovideraccountpriv.h
@@ -0,0 +1,32 @@
+/* cloudprovideraccountpriv.h
+ *
+ * Copyright (C) 2017 Julius Haertl <jus bitgrid net>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CLOUD_PROVIDER_ACCOUNT_PRIV_H
+#define CLOUD_PROVIDER_ACCOUNT_PRIV_H
+
+#include "cloudprovideraccount.h"
+#include <gio/gio.h>
+G_BEGIN_DECLS
+
+GDBusInterfaceSkeleton*
+cloud_provider_account_get_skeleton (CloudProviderAccount *self);
+
+gchar *
+cloud_provider_account_get_object_name (CloudProviderAccount *self);
+
+#endif
diff --git a/src/meson.build b/src/meson.build
index 0c66384..10273a6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -3,6 +3,7 @@ libcloudproviders_headers = [
   'cloudproviderproxy.h',
   'cloudproviders.h',
   'cloudprovider.h',
+  'cloudprovideraccount.h',
 ]
 
 libcloudproviders_sources = [
@@ -10,6 +11,7 @@ libcloudproviders_sources = [
   'cloudproviderproxy.c',
   'cloudproviders.c',
   'cloudprovider.c',
+  'cloudprovideraccount.c',
 ]
 
 libcloudproviders_deps = [glib, gio, gio_unix]


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