2007-04-20 2007-04-20 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Fri, 20 Apr 2007 17:16:07 +0000 (17:16 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Fri, 20 Apr 2007 17:16:07 +0000 (17:16 +0000)
* configure.ac:
        * src/Makefile.am:
        * src/dbus_api/Makefile.am:
        * src/dbus_api/modest-dbus-callbacks.c:
        * src/dbus_api/modest-dbus-callbacks.h:
        * src/maemo/modest-platform.c: (modest_platform_init):
        Added the beginnings of a D-Bus API. At the moment it just has a HelloWorld
        method.
        * tests/Makefile.am:
        * tests/dbus_api/Makefile.am:
        * tests/dbus_api/test_hello.c: (main): Very simple test of the D-Bus API.

pmo-trunk-r1616

ChangeLog2
configure.ac
src/Makefile.am
src/dbus_api/Makefile.am [new file with mode: 0644]
src/dbus_api/modest-dbus-callbacks.c [new file with mode: 0644]
src/dbus_api/modest-dbus-callbacks.h [new file with mode: 0644]
src/maemo/modest-platform.c
tests/Makefile.am
tests/dbus_api/Makefile.am [new file with mode: 0644]
tests/dbus_api/test_hello.c [new file with mode: 0644]

index be36338..3fff506 100644 (file)
@@ -1,3 +1,17 @@
+2007-04-20  2007-04-20  Murray Cumming  <murrayc@murrayc.com>
+
+       * configure.ac:
+       * src/Makefile.am:
+       * src/dbus_api/Makefile.am:
+       * src/dbus_api/modest-dbus-callbacks.c:
+       * src/dbus_api/modest-dbus-callbacks.h:
+       * src/maemo/modest-platform.c: (modest_platform_init):
+       Added the beginnings of a D-Bus API. At the moment it just has a HelloWorld 
+       method.
+       * tests/Makefile.am:
+       * tests/dbus_api/Makefile.am:
+       * tests/dbus_api/test_hello.c: (main): Very simple test of the D-Bus API.
+
 2007-04-20  Murray Cumming  <murrayc@murrayc.com>
 
        * src/maemo/modest-account-settings-dialog.c:
index df900fe..6a282ef 100644 (file)
@@ -201,6 +201,7 @@ po/Makefile.in
 Makefile
 man/Makefile
 src/Makefile
+src/dbus_api/Makefile
 src/gnome/Makefile
 src/maemo/Makefile
 src/maemo/easysetup/Makefile
@@ -208,6 +209,7 @@ src/widgets/Makefile
 docs/Makefile
 docs/reference/Makefile
 tests/Makefile
+tests/dbus_api/Makefile
 src/maemo/modest.desktop
 src/maemo/modest.service
 ])
index 0faa06f..6ac9aed 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Makefile.am
 # Time-stamp: <2007-04-10 10:58:05 (djcb)>
-SUBDIRS=$(MODEST_PLATFORM) widgets
+SUBDIRS=$(MODEST_PLATFORM) widgets dbus_api
 DIST_SUBDIRS = widgets gnome maemo
 
 INCLUDES=\
@@ -90,6 +90,7 @@ modest_LDADD =                                                \
        $(MODEST_LIBTINYMAIL_MAEMO_LIBS)                \
        ${easysetupmaybe}                               \
        $(MODEST_PLATFORM)/libmodest-ui.la              \
-       widgets/libmodest-widgets.la                    
+       widgets/libmodest-widgets.la \
+       dbus_api/libmodest-dbus-api.la          
 
 EXTRA_DIST=modest-marshal.list
diff --git a/src/dbus_api/Makefile.am b/src/dbus_api/Makefile.am
new file mode 100644 (file)
index 0000000..8b8b26b
--- /dev/null
@@ -0,0 +1,52 @@
+# Copyright (c) 2006,2007 Nokia Corporation
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+# 
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# * Neither the name of the Nokia Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived from
+#   this software without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+INCLUDES=\
+       $(MODEST_GSTUFF_CFLAGS) \
+       $(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) \
+       -DMODEST_PLATFORM_ID=$(MODEST_PLATFORM_ID) \
+       -I ${top_srcdir}/src/widgets  \
+       -I ${top_srcdir}/src  \
+       -DPREFIX=\"@prefix@\" \
+       -DMAEMO_CHANGES \
+       -DPIXMAP_PREFIX=\"${datadir}/pixmaps/modest/\" \
+       -DMODEST_UIDIR=\""$(datadir)/modest/ui/"\" \
+       -DPROVIDER_DATA_DIR=\""${datadir}/modest/provider-data/"\" \
+       -Wall
+
+noinst_LTLIBRARIES=\
+       libmodest-dbus-api.la
+
+libmodest_dbus_api_la_SOURCES=              \
+       modest-dbus-callbacks.h modest-dbus-callbacks.c
+
+LDADD = \
+       $(MODEST_GSTUFF_LIBS) \
+       $(MODEST_LIBTINYMAIL_MAEMO_LIBS)
+
diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c
new file mode 100644 (file)
index 0000000..c15f62e
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "modest-dbus-callbacks.h"
+#include <stdio.h>
+
+/* Callback for normal D-BUS messages */
+gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
+                      GArray * arguments, gpointer data,
+                      osso_rpc_t * retval)
+{
+       printf("debug: modest_dbus_req_handler()\n");
+       
+        if (g_ascii_strcasecmp(method, MODEST_DBUS_EXAMPLE_MESSAGE) == 0) {
+        printf("debug: method received:" MODEST_DBUS_EXAMPLE_MESSAGE "\n");
+    }
+    
+       return OSSO_OK;
+}
diff --git a/src/dbus_api/modest-dbus-callbacks.h b/src/dbus_api/modest-dbus-callbacks.h
new file mode 100644 (file)
index 0000000..a4db566
--- /dev/null
@@ -0,0 +1,50 @@
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef __MODEST_DBUS_CALLBACKS_H__
+#define __MODEST_DBUS_CALLBACKS_H__
+
+#include <glib.h>
+#include <libosso.h>
+
+/* Note that the com.nokia service name and /com/nokia object name 
+ * are what is assumed by the, bizarrely named, osso_rpc_run_with_defaults() function, 
+ * so they are probably a good choice. */
+#define MODEST_DBUS_NAME    "modestemail"
+#define MODEST_DBUS_EXAMPLE_SERVICE "com.nokia."MODEST_DBUS_NAME
+#define MODEST_DBUS_EXAMPLE_OBJECT  "/com/nokia/"MODEST_DBUS_NAME
+#define MODEST_DBUS_EXAMPLE_IFACE   "com.nokia."MODEST_DBUS_NAME
+#define MODEST_DBUS_EXAMPLE_MESSAGE "HelloWorld"
+
+gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
+                      GArray * arguments, gpointer data,
+                      osso_rpc_t * retval);
+                      
+#endif /* __MODEST_DBUS_CALLBACKS_H__ */
index e70eb05..fc7caa5 100644 (file)
@@ -30,6 +30,7 @@
 #include <config.h>
 #include <glib/gi18n.h>
 #include <modest-platform.h>
+#include <dbus_api/modest-dbus-callbacks.h>
 #include <libosso.h>
 
 #ifdef MODEST_HILDON_VERSION_0
@@ -57,6 +58,29 @@ modest_platform_init (void)
                g_printerr ("modest: failed to acquire osso context\n");
                return FALSE;
        }
+
+       /* Register our D-Bus callbacks, via the osso API: */
+       osso_return_t result = osso_rpc_set_cb_f(osso_context, 
+                               MODEST_DBUS_EXAMPLE_SERVICE, 
+                               MODEST_DBUS_EXAMPLE_OBJECT, 
+                               MODEST_DBUS_EXAMPLE_IFACE,
+                               modest_dbus_req_handler, NULL /* user_data */);
+       if (result != OSSO_OK) {
+                       g_print("Error setting D-BUS callback (%d)\n", result);
+                       return OSSO_ERROR;
+       }
+
+       /* Add handler for Exit D-BUS messages.
+        * Not used because osso_application_set_exit_cb() is deprecated and obsolete:
+       result = osso_application_set_exit_cb(osso_context,
+                                          modest_dbus_exit_event_handler,
+                                          (gpointer) NULL);
+       if (result != OSSO_OK) {
+               g_print("Error setting exit callback (%d)\n", result);
+               return OSSO_ERROR;
+       }
+       */
+
        return TRUE;
 }
 
index d7fb8d9..fec105b 100644 (file)
@@ -2,6 +2,9 @@
 # Makefile.am
 #
 
+SUBDIRS = dbus_api
+
+# TODO: Why is this line here?
 MAINTAINERCLEANFILES    = Makefile.in
 
 TESTS_ENVIRONMENT       = top_builddir=$(top_builddir)  \
@@ -38,6 +41,7 @@ objects=\
         $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \
         ${top_srcdir}/src/$(MODEST_PLATFORM)/libmodest-ui.la \
         ${top_srcdir}/src/widgets/libmodest-widgets.la \
+        ${top_srcdir}/src/dbus_api/libmodest-dbus-api.la \
        ${top_srcdir}/src/modest-runtime.o \
        ${top_srcdir}/src/modest-singletons.o \
        ${top_srcdir}/src/modest-tny-account.o \
diff --git a/tests/dbus_api/Makefile.am b/tests/dbus_api/Makefile.am
new file mode 100644 (file)
index 0000000..d827648
--- /dev/null
@@ -0,0 +1,21 @@
+INCLUDES=\
+       @CHECK_CFLAGS@ \
+       $(MODEST_GSTUFF_CFLAGS)\
+       $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_CFLAGS) \
+       $(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) \
+       -I$(MODEST_PLATFORM) \
+       -I${top_srcdir}/src \
+       -DPREFIX=\"@prefix@\" \
+       -DMODESTLOCALEDIR=\""$(modestlocaledir)"\"
+       
+objects=\
+       @CHECK_LIBS@ \
+       $(MODEST_GSTUFF_LIBS) \
+        $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_LIBS) \
+        $(MODEST_LIBTINYMAIL_MAEMO_LIBS)
+        
+noinst_PROGRAMS = test_hello
+
+test_hello_SOURCES = test_hello.c
+test_hello_LDADD = $(objects)
+
diff --git a/tests/dbus_api/test_hello.c b/tests/dbus_api/test_hello.c
new file mode 100644 (file)
index 0000000..bb96b82
--- /dev/null
@@ -0,0 +1,37 @@
+#include <libosso.h>
+#include <stdio.h>
+
+#define MODEST_DBUS_NAME    "modestemail"
+#define MODEST_DBUS_EXAMPLE_MESSAGE "HelloWorld"
+
+
+
+int main(int argc, char *argv[])
+{
+       /* Initialize maemo application */
+       osso_context_t * osso_context = osso_initialize(
+           "test_hello", "0.0.1", TRUE, NULL);
+              
+       /* Check that initialization was ok */
+       if (osso_context == NULL)
+       {
+               printf("osso_initialize() failed.\n");
+           return OSSO_ERROR;
+       }
+       
+       osso_rpc_t retval;
+       osso_return_t ret = osso_rpc_run_with_defaults(osso_context, 
+                  MODEST_DBUS_NAME, 
+                  MODEST_DBUS_EXAMPLE_MESSAGE, &retval, DBUS_TYPE_INVALID);
+       if (ret != OSSO_OK) {
+                       printf("osso_rpc_run() failed.\n");
+               return OSSO_ERROR;
+       } else {
+               printf("osso_rpc_run() succeeded.\n");
+       }
+               
+       osso_rpc_free_val(&retval);
+               
+    /* Exit */
+    return 0;
+}