soc.2010.detachablepurple: c83d1598: Introduced a new "state" for purple core...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Fri Jul 16 01:17:09 EDT 2010


----------------------------------------------------------------------
Revision: c83d15980f3f412383ac2ff042aef839f8db4377
Parent:   5592c43d412cfd0a12547ae00b653b4a3bc93033
Author:   gillux at soc.pidgin.im
Date:     07/15/10 22:23:51
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/c83d15980f3f412383ac2ff042aef839f8db4377

Changelog: 

Introduced a new "state" for purple core. Before we had remote vs. normal mode,
now we have remote, daemon (= old "normal"), and normal mode. See the comments.

Changes against parent 5592c43d412cfd0a12547ae00b653b4a3bc93033

  patched  libpurple/core.c
  patched  libpurple/core.h

-------------- next part --------------
============================================================
--- libpurple/core.c	1aad35cd0d9787488e23da4d8b66a4218b354163
+++ libpurple/core.c	b66d4414a72e9c27dc986b85d607000fe56f74fd
@@ -72,7 +72,7 @@ static PurpleCore      *_core = NULL;
 
 static PurpleCoreUiOps *_ops  = NULL;
 static PurpleCore      *_core = NULL;
-static gboolean        _remote_mode = FALSE;
+static PurpleRunningMode _running_mode = PURPLE_RUN_NORMAL_MODE;
 
 STATIC_PROTO_INIT
 
@@ -317,24 +317,21 @@ purple_core_get_ui_ops(void)
 	return _ops;
 }
 
-gboolean
-purple_core_get_remote_mode(void)
+PurpleRunningMode
+purple_core_get_running_mode(void)
 {
-#if HAVE_DBUS
-	return _remote_mode;
-#else
-	return FALSE;
-#endif
+	return _running_mode;
 }
 
 void
-purple_core_set_remote_mode(gboolean mode)
+purple_core_set_running_mode(PurpleRunningMode mode)
 {
 #if HAVE_DBUS
-	_remote_mode = mode;
+	g_return_if_fail(mode < PURPLE_RUN_MODE_LAST);
+	_running_mode = mode;
 #else
-	if (mode)
-		purple_debug_warning("core", "Couldn't activate remote mode: this feature is not compiled in.\n");
+	if (mode != PURPLE_RUN_NORMAL_MODE)
+		purple_debug_warning("core", "Couldn't change running mode: this feature requires DBus which is not compiled in.\n");
 #endif
 }
 
============================================================
--- libpurple/core.h	7bd4e9c6268135652c8b21bfca7367b6cf46cfab
+++ libpurple/core.h	aef43be581c1ed25d6dd9ec65258896a73dd23f4
@@ -38,6 +38,7 @@ typedef struct PurpleCore PurpleCore;
 #define _PURPLE_CORE_H_
 
 typedef struct PurpleCore PurpleCore;
+typedef enum _PurpleRunningMode PurpleRunningMode;
 
 /** Callbacks that fire at different points of the initialization and teardown
  *  of libpurple, along with a hook to return descriptive information about the
@@ -76,11 +77,46 @@ typedef struct
 	void (*_purple_reserved3)(void);
 } PurpleCoreUiOps;
 
+/**
+ * The mode libpurple is currently running as.
+ * PURPLE_RUN_NORMAL_MODE: regular use, with one purple and one UI client
+ *     interacting with function calls and callbacks.
+ * PURPLE_RUN_DAEMON_MODE: used in detachable session context, for the daemon
+ *     instance, which wraps libpurple and communicate with several UI clients
+ *     through DBus.
+ * PURPLE_RUN_REMOTE_MODE: used in detachable session context, for UI client
+ *     instance, which makes its libpurple to connects to the daemon a forward
+ *     calls and events.
+ */
+enum _PurpleRunningMode {
+	PURPLE_RUN_NORMAL_MODE,
+	PURPLE_RUN_DAEMON_MODE,
+	PURPLE_RUN_REMOTE_MODE,
+	PURPLE_RUN_MODE_LAST
+};
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
+ * Convenience macros for checking the current running mode.
+ */
+#ifdef HAVE_DBUS
+#  define purple_core_is_remote_mode() \
+	(purple_core_get_running_mode() == PURPLE_RUN_REMOTE_MODE)
+#  define purple_core_is_daemon_mode() \
+	(purple_core_get_running_mode() == PURPLE_RUN_DAEMON_MODE)
+#  define purple_core_is_normal_mode() \
+	(purple_core_get_running_mode() == PURPLE_RUN_NORMAL_MODE)
+
+#else /* !HAVE_DBUS */
+#  define purple_core_is_remote_mode() (FALSE)
+#  define purple_core_is_daemon_mode() (FALSE)
+#  define purple_core_is_normal_mode() (TRUE )
+#endif
+
+/**
  * Initializes the core of purple.
  *
  * This will setup preferences for all the core subsystems.
@@ -142,26 +178,18 @@ PurpleCore *purple_get_core(void);
 PurpleCore *purple_get_core(void);
 
 /**
- * Returns the remote mode flag of the purple core.
+ * Returns the running mode state of the purple core.
  *
- * Remote mode is used in detachable sessions scenarios. It is set
- * by UI clients which want to attach and detach from purpled. As
- * a default beheaviour this flag is FALSE.
- *
- * @return TRUE if remote mode is activated, FALSE if not.
+ * @return One of the PurpleRunningMode enum values
  */
-gboolean purple_core_get_remote_mode(void);
+PurpleRunningMode purple_core_get_running_mode(void);
 
 /**
- * Sets the remote mode flag of the purple core.
+ * Sets the running mode state of the purple core.
  *
- * Remote mode is used in detachable sessions scenarios. It is set
- * by UI clients which want to attach and detach from purpled. As
- * a default beheaviour this flag is FALSE.
- *
- * @param mode The wanted remote mode flag.
+ * @param mode The wanted running mode state.
  */
-void purple_core_set_remote_mode(gboolean mode);
+void purple_core_set_running_mode(PurpleRunningMode mode);
 
 /**
  * Sets the UI ops for the core.


More information about the Commits mailing list