Moved purple_core_init to cython, added purple debug methods, added checks for core...
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:08:16 +0000 (20:08 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:09 +0000 (17:11 -0400)
FIXES:
 - Moved purple_core_init from c_purple.c directly to Cython code. Now only callbacks are done inside c_purple code.
 - Added purple debug methods, so we can use it inside code.
 - Added check for core initialization.
 - Added check to ensure that it has only one instance of libpurple running.

Signed-off-by: Bruno Abinader <bruno.abinader@indt.org.br>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1273 596f6dd7-e928-0410-a184-9e12fd12cf7e

c_purple.c
c_purple.h
purple.pyx

index b77d659..5c1cb23 100644 (file)
@@ -139,8 +139,7 @@ static PurpleConversationUiOps conv_uiops =
 };
 
 /* FIXME: Is this a valid struct? */
-static void
-ui_init(void)
+static void ui_init(void)
 {
        /**
         * This should initialize the UI components for all the modules. Here we
@@ -163,19 +162,8 @@ static PurpleCoreUiOps core_uiops =
        NULL
 };
 
-void init_libpurple(const char *ui_id)
+void set_uiops(void)
 {
        purple_core_set_ui_ops(&core_uiops);
-
        purple_eventloop_set_ui_ops(&glib_eventloops);
-
-       if (!purple_core_init(ui_id)) {
-               /* Initializing the core failed. Terminate. */
-               fprintf(stderr,
-                               "libpurple initialization failed. Dumping core.\n"
-                               "Please report this!\n");
-               abort();
-       }
-
-       printf("libpurple initialized");
 }
index b8aa5b6..016f186 100644 (file)
  *
  */
 
-#include <glib.h>
-
-#define CUSTOM_USER_DIRECTORY  "/dev/null"
-#define CUSTOM_PLUGIN_PATH     ""
-/* FIXME: Check this path */
-#define PLUGIN_SAVE_PREF       "/purple/nullclient/plugins/saved"
-#define UI_ID                  "carman-purple-client"
-
-void init_libpurple(const char *ui_id);
+void set_uiops(void);
index c45858f..efe8eed 100644 (file)
@@ -25,7 +25,21 @@ cdef extern from *:
 cdef extern from "time.h":
     ctypedef long int time_t
 
+cdef extern from "libpurple/core.h":
+    gboolean c_purple_core_init "purple_core_init" (const_char_ptr ui_name)
+    void c_purple_core_quit "purple_core_quit" ()
+    gboolean c_purple_core_ensure_single_instance "purple_core_ensure_single_instance" ()
+
 cdef extern from "libpurple/debug.h":
+    ctypedef enum PurpleDebugLevel:
+        PURPLE_DEBUG_ALL
+        PURPLE_DEBUG_MISC
+        PURPLE_DEBUG_INFO
+        PURPLE_DEBUG_WARNING
+        PURPLE_DEBUG_ERROR
+        PURPLE_DEBUG_FATAL
+
+    void c_purple_debug "purple_debug" (PurpleDebugLevel level, const_char_ptr category, const_char_ptr format)
     void c_purple_debug_set_enabled "purple_debug_set_enabled" (gboolean debug_enabled)
 
 cdef extern from "libpurple/plugin.h":
@@ -35,7 +49,7 @@ cdef extern from "libpurple/util.h":
     void c_purple_util_set_user_dir "purple_util_set_user_dir" (char *dir)
 
 cdef extern from "c_purple.h":
-     void init_libpurple(const_char_ptr ui_id)
+     void set_uiops()
 
 class Purple(object):
     def __init__(self):
@@ -46,9 +60,71 @@ class Purple(object):
         self.util_set_user_dir(self.DEFAULT_PATH)
         self.plugin_add_search_path(self.DEFAULT_PATH)
 
-        init_libpurple(self.APP_NAME)
+        set_uiops()
+
+        ret = self.core_init(self.APP_NAME)
+        if ret is False:
+            self.debug_info("main", "Exiting because libpurple initialization failed.")
+            return
+
+        # check if there is another instance of libpurple running
+        if self.core_ensure_single_instance() == False:
+            self.debug_info("main", "Exiting because another instance of libpurple is already running.")
+            self.core_quit()
+            return
     # __init__
 
+    def __del__(self):
+        self.core_quit()
+    # __del__
+
+    def core_ensure_single_instance(self):
+        return c_purple_core_ensure_single_instance()
+    # core_ensure_single_instance
+
+    def core_init(self, ui_name):
+        return c_purple_core_init(ui_name)
+    # core_init
+
+    def core_quit(self):
+        c_purple_core_quit()
+    # core_quit
+
+    def debug_misc(self, category, format):
+        if category == None:
+            c_purple_debug(PURPLE_DEBUG_MISC, NULL, format)
+        else:
+            c_purple_debug(PURPLE_DEBUG_MISC, category, format)
+    # debug_misc
+
+    def debug_info(self, category, format):
+        if category == None:
+            c_purple_debug(PURPLE_DEBUG_INFO, NULL, format)
+        else:
+            c_purple_debug(PURPLE_DEBUG_INFO, category, format)
+    # debug_info
+
+    def debug_warning(self, category, format):
+        if category == None:
+            c_purple_debug(PURPLE_DEBUG_WARNING, NULL, format)
+        else:
+            c_purple_debug(PURPLE_DEBUG_WARNING, category, format)
+    # debug_warning
+
+    def debug_error(self, category, format):
+        if category == None:
+            c_purple_debug(PURPLE_DEBUG_ERROR, NULL, format)
+        else:
+            c_purple_debug(PURPLE_DEBUG_ERROR, category, format)
+    # debug_error
+
+    def debug_fatal(self, category, format):
+        if category == None:
+            c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format)
+        else:
+            c_purple_debug(PURPLE_DEBUG_FATAL, category, format)
+    # debug_fatal
+
     def debug_set_enabled(self, debug_enabled):
         c_purple_debug_set_enabled(debug_enabled)
     # debug_set_enabled