From fa8cfc5abf9fd542fe3fa058f7e2eef294b8121a Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 20 Apr 2007 17:16:07 +0000 Subject: [PATCH] 2007-04-20 2007-04-20 Murray Cumming * 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 | 14 +++++++++ configure.ac | 2 ++ src/Makefile.am | 5 ++-- src/dbus_api/Makefile.am | 52 ++++++++++++++++++++++++++++++++++ src/dbus_api/modest-dbus-callbacks.c | 45 +++++++++++++++++++++++++++++ src/dbus_api/modest-dbus-callbacks.h | 50 ++++++++++++++++++++++++++++++++ src/maemo/modest-platform.c | 24 ++++++++++++++++ tests/Makefile.am | 4 +++ tests/dbus_api/Makefile.am | 21 ++++++++++++++ tests/dbus_api/test_hello.c | 37 ++++++++++++++++++++++++ 10 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 src/dbus_api/Makefile.am create mode 100644 src/dbus_api/modest-dbus-callbacks.c create mode 100644 src/dbus_api/modest-dbus-callbacks.h create mode 100644 tests/dbus_api/Makefile.am create mode 100644 tests/dbus_api/test_hello.c diff --git a/ChangeLog2 b/ChangeLog2 index be36338..3fff506 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,17 @@ +2007-04-20 2007-04-20 Murray Cumming + + * 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 * src/maemo/modest-account-settings-dialog.c: diff --git a/configure.ac b/configure.ac index df900fe..6a282ef 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]) diff --git a/src/Makefile.am b/src/Makefile.am index 0faa06f..6ac9aed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000..8b8b26b --- /dev/null +++ b/src/dbus_api/Makefile.am @@ -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 index 0000000..c15f62e --- /dev/null +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -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 + +/* 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 index 0000000..a4db566 --- /dev/null +++ b/src/dbus_api/modest-dbus-callbacks.h @@ -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 +#include + +/* 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__ */ diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index e70eb05..fc7caa5 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #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; } diff --git a/tests/Makefile.am b/tests/Makefile.am index d7fb8d9..fec105b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..d827648 --- /dev/null +++ b/tests/dbus_api/Makefile.am @@ -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 index 0000000..bb96b82 --- /dev/null +++ b/tests/dbus_api/test_hello.c @@ -0,0 +1,37 @@ +#include +#include + +#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; +} -- 1.7.9.5