[Xfce4-commits] <xfce4-power-manager:xfce-4.10> Added some code (very little) for Power DBus Service that will be used by both the session and the power manager.

Ali Abdallah noreply at xfce.org
Wed Jul 6 21:48:02 CEST 2011


Updating branch refs/heads/xfce-4.10
         to 900acdbb5ad48254c28ec9a3672d116995005104 (commit)
       from 4c705bee7f3bb154ad7212a4604e26de1ef123cc (commit)

commit 900acdbb5ad48254c28ec9a3672d116995005104
Author: Ali Abdallah <aliov at xfce.org>
Date:   Wed Jul 6 21:46:13 2011 +0200

    Added some code (very little) for Power DBus Service that will be used
    by both the session and the power manager.

 Makefile.am                                        |    1 +
 configure.ac.in                                    |    1 +
 xfce-powerd/Makefile.am                            |   49 +++++++++++
 .../brightness-plugin.c => xfce-powerd/main.c      |   43 ++++++---
 xfce-powerd/org.xfce.Power.service.in              |    3 +
 xfce-powerd/org.xfce.Power.xml                     |   20 ++++
 xfce-powerd/xfce-power.c                           |   92 ++++++++++++++++++++
 src/xfpm-errors.h => xfce-powerd/xfce-power.h      |   34 ++++----
 8 files changed, 211 insertions(+), 32 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 328aa68..ada596d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,6 +6,7 @@ endif
 
 SUBDIRS =        	\
 	data		\
+	xfce-powerd	\
 	libdbus		\
 	common		\
 	src		\
diff --git a/configure.ac.in b/configure.ac.in
index b925ec1..4221b14 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -209,6 +209,7 @@ AC_SUBST([PLATFORM_LDFLAGS])
 
 AC_OUTPUT([
 Makefile
+xfce-powerd/Makefile
 libdbus/Makefile
 common/Makefile
 src/Makefile
diff --git a/xfce-powerd/Makefile.am b/xfce-powerd/Makefile.am
new file mode 100644
index 0000000..849deff
--- /dev/null
+++ b/xfce-powerd/Makefile.am
@@ -0,0 +1,49 @@
+xfce_powerddir = $(libdir)/xfce4/power/xfce-powerd
+
+xfce_powerd_PROGRAMS =				\
+	xfce-powerd
+
+
+xfce_powerd_SOURCES = 				\
+	main.c					\
+	xfce-power.c				\
+	xfce-power.h				\
+	xfce-polkit.c				\
+	xfce-polkit.h				\
+	$(BUILT_SOURCES)
+
+
+xfce_powerd_CFLAGS =				\
+	-I$(top_srcdir)				\
+	$(DBUS_GLIB_CFLAGS)
+
+xfce_powerd_LDADD =				\
+	$(DBUS_GLIB_LIBS)
+
+
+servicedir = $(datadir)/dbus-1/services
+service_in_files =                              \
+	org.xfce.Power.service.in
+
+service_DATA = $(service_in_files:.service.in=.service)
+
+$(service_DATA): $(service_in_files) Makefile
+	@sed -e "s|\@libdir\@|$(libdir)|" $< > $@
+
+
+BUILT_SOURCES =					\
+	xfce-power-dbus-server.h					
+
+xfce-power-dbus-server.h: org.xfce.Power.xml Makefile.am
+	dbus-binding-tool --prefix=xfce_power --mode=glib-server --output=xfce-power-dbus-server.h org.xfce.Power.xml
+
+
+CLEANFILES =                                   	\
+	$(service_DATA)				\
+	$(BUILT_SOURCES)
+
+EXTRA_DIST =                                    \
+	org.xfce.Power.xml			\
+	$(service_in_files)
+
+
diff --git a/panel-plugins/brightness/brightness-plugin.c b/xfce-powerd/main.c
similarity index 57%
copy from panel-plugins/brightness/brightness-plugin.c
copy to xfce-powerd/main.c
index f7e84d0..f49dcbf 100644
--- a/panel-plugins/brightness/brightness-plugin.c
+++ b/xfce-powerd/main.c
@@ -1,5 +1,5 @@
 /*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2011 Ali <aliov at xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -22,26 +22,41 @@
 #include <config.h>
 #endif
 
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
-#include <gtk/gtk.h>
 #include <glib.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
 
-#include <libxfce4panel/libxfce4panel.h>
-#include <libxfce4panel/xfce-panel-plugin.h>
+#include <dbus/dbus-glib.h>
 
-#include "brightness-button.h"
 
-static void
-register_brightness_plugin (XfcePanelPlugin *plugin)
+int main (int argc,  char **argv)
 {
-    GtkWidget *button;
+    GMainLoop *main_loop;
     
-    button = brightness_button_new (plugin);
     
-    brightness_button_show (BRIGHTNESS_BUTTON (button));
-}
+    /* set the program name */
+    g_set_prgname (G_LOG_DOMAIN);
+
+    g_set_application_name (_("Xfce Power Service"));
+
+    /* initialize the GLib type system */
+    g_type_init ();
+
+    /* initialize threading system */
+    if (!g_thread_supported ())
+	g_thread_init (NULL);
+	
+
+    /* Create the main loop */
+    main_loop = g_main_loop_new (NULL, FALSE);
+    
+    
+    g_main_loop_run (main_loop);
+    
 
-XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(register_brightness_plugin);
+    g_main_loop_unref (main_loop);
+    
+    return EXIT_SUCCESS;
+}
diff --git a/xfce-powerd/org.xfce.Power.service.in b/xfce-powerd/org.xfce.Power.service.in
new file mode 100644
index 0000000..182c597
--- /dev/null
+++ b/xfce-powerd/org.xfce.Power.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.xfce.Power
+Exec=@libdir@/xfce4/power/xfce-powerd
diff --git a/xfce-powerd/org.xfce.Power.xml b/xfce-powerd/org.xfce.Power.xml
new file mode 100644
index 0000000..16fb7fa
--- /dev/null
+++ b/xfce-powerd/org.xfce.Power.xml
@@ -0,0 +1,20 @@
+<!DOCTYPE node PUBLIC
+"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
+    
+    <interface name="org.xfce.Power">
+	<method name="Hibernate">
+	    <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+	    <doc:doc>
+		<doc:description>
+		    <doc:para>
+			Hibernate the computer.
+		    </doc:para>
+		</doc:description>
+	    </doc:doc>
+	</method>
+
+    
+    </interface>
+</node>
diff --git a/xfce-powerd/xfce-polkit.c b/xfce-powerd/xfce-polkit.c
new file mode 100644
index 0000000..e69de29
diff --git a/xfce-powerd/xfce-polkit.h b/xfce-powerd/xfce-polkit.h
new file mode 100644
index 0000000..e69de29
diff --git a/xfce-powerd/xfce-power.c b/xfce-powerd/xfce-power.c
new file mode 100644
index 0000000..f5f978b
--- /dev/null
+++ b/xfce-powerd/xfce-power.c
@@ -0,0 +1,92 @@
+/*
+ * * Copyright (C) 2011 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+ 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "xfce-power.h"
+#include "xfce-power-dbus-server.h"
+
+struct _XfcePowerClass
+{
+    GObjectClass parent_class;
+};
+
+
+struct _XfcePower
+{
+    GObject parent;
+    
+};
+
+static void xfce_power_finalize (GObject *object);
+
+
+G_DEFINE_TYPE (XfcePower, xfce_power, G_TYPE_OBJECT)
+
+static void
+xfce_power_class_init (XfcePowerClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+    object_class->finalize = xfce_power_finalize;
+
+}
+
+
+static void
+xfce_power_init (XfcePower *power)
+{
+
+}
+
+static void
+xfce_power_finalize (GObject *object)
+{
+//    XfcePower *power;
+
+//    power = XFCE_POWER (object);
+
+    G_OBJECT_CLASS (xfce_power_parent_class)->finalize (object);
+}
+
+XfcePower *
+xfce_power_new (void)
+{
+    XfcePower *xfce_power = NULL;
+    xfce_power = g_object_new (XFCE_TYPE_POWER, NULL);
+    return xfce_power;
+    
+}
+
+
+/**
+ *xfce_power_hibernate
+ **/
+gboolean
+xfce_power_hibernate (XfcePower *power, DBusGMethodInvocation *context)
+{
+    
+    return TRUE;
+}
diff --git a/src/xfpm-errors.h b/xfce-powerd/xfce-power.h
similarity index 54%
copy from src/xfpm-errors.h
copy to xfce-powerd/xfce-power.h
index 10d4845..ee20532 100644
--- a/src/xfpm-errors.h
+++ b/xfce-powerd/xfce-power.h
@@ -1,5 +1,5 @@
 /*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2011 Ali <aliov at xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -18,32 +18,30 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef __XFPM_ERRORS_H
-#define __XFPM_ERRORS_H
+#ifndef __XFCE_POWER_H
+#define __XFCE_POWER_H
 
 #include <glib-object.h>
+#include <dbus/dbus-glib.h>
 
 G_BEGIN_DECLS
 
-#define XFPM_TYPE_ERROR	(xfpm_error_get_type  ())
-#define XFPM_ERROR      (xfpm_get_error_quark ())
+#define XFCE_TYPE_POWER        (xfce_power_get_type () )
+#define XFCE_POWER(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), XFCE_TYPE_POWER, XfcePower))
+#define XFCE_IS_POWER(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFCE_TYPE_POWER))
 
+typedef struct _XfcePowerClass XfcePowerClass;
+typedef struct _XfcePower      XfcePower;
 
-typedef enum
-{
-    XFPM_ERROR_UNKNOWN = 0,
-    XFPM_ERROR_PERMISSION_DENIED,
-    XFPM_ERROR_NO_HARDWARE_SUPPORT,
-    XFPM_ERROR_COOKIE_NOT_FOUND,
-    XFPM_ERROR_INVALID_ARGUMENTS,
-    XFPM_ERROR_SLEEP_FAILED
-    
-} XfpmError;
+GType                   xfce_power_get_type             (void) G_GNUC_CONST;
 
-GType	xfpm_error_get_type  (void) G_GNUC_CONST;
-GQuark  xfpm_get_error_quark (void);
+XfcePower	       *xfce_power_new			(void);
 
 
+/* exported */
+gboolean		xfce_power_hibernate 		(XfcePower *power, 
+							 DBusGMethodInvocation *context);
+
 G_END_DECLS
 
-#endif /*__XFPM_ERRORS_H */
+#endif /* __XFCE_POWER_H */



More information about the Xfce4-commits mailing list