From: Hurnjoo Lee Date: Mon, 5 Jan 2015 10:56:50 +0000 (+0900) Subject: Add tizen 2.3 native API X-Git-Tag: accepted/tizen/common/20150224.150829^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81cbce43aacfec872b76f72dbe196727cd705abf;p=platform%2Fcore%2Fappfw%2Fmessage-port-dbus.git Add tizen 2.3 native API To support Tizen 2.3 native application, add tizen native api to message port library. Change-Id: I90928fc241639273a629cc171f847b03af641afb Signed-off-by: Hurnjoo Lee --- diff --git a/configure.ac b/configure.ac index 6d3b9d7..fa4809a 100644 --- a/configure.ac +++ b/configure.ac @@ -43,6 +43,10 @@ PKG_CHECK_MODULES([DLOG], [dlog], [AC_DEFINE([HAVE_DLOG], [1], [Use DLOG])]) AC_SUBST(DLOG_CFLAGS) AC_SUBST(DLOG_LIBS) +PKG_CHECK_MODULES([CAPIBASECOMMON], [capi-base-common]) +AC_SUBST(CAPIBASECOMMON_CFLAGS) +AC_SUBST(CAPIBASECOMMON_LIBS) + AC_DEFINE(MESSAGEPORT_BUS_ADDRESS, ["unix:path=%s/.message-port", "/tmp"], [messageport daemon server socket address]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 7f1709b..496f0a1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -10,6 +10,7 @@ libmessage_port_la_SOURCES = \ msgport-manager.c \ msgport-factory.h \ msgport-factory.c \ + compatibility/message_port_wrapper.c \ $(NULL) libmessage_port_la_LDFLAGS = -version-info $(subst .,:,$(VERSION)) @@ -17,19 +18,20 @@ libmessage_port_la_LDFLAGS = -version-info $(subst .,:,$(VERSION)) libmessage_port_la_includedir = $(includedir)/ libmessage_port_la_include_HEADERS = \ message-port.h \ + compatibility/message_port.h \ $(NULL) libmessage_port_la_CPPFLAGS = \ -I . \ -I $(top_builddir) \ -DLOG_TAG=\"MESSAGEPORT/LIB\" \ - $(GLIB_CFLAGS) $(GIO_CFLAGS) $(BUNDLE_CFLAGS) $(DLOG_CFLAGS) \ + $(GLIB_CFLAGS) $(GIO_CFLAGS) $(BUNDLE_CFLAGS) $(DLOG_CFLAGS) $(CAPIBASECOMMON_CFLAGS) \ -Wall -error $(NULL) libmessage_port_la_LIBADD = \ ../common/libmessageport-common.la \ - $(GLIB_LIBS) $(GIO_LIBS) $(BUNDLE_LIBS) $(DLOG_LIBS) \ + $(GLIB_LIBS) $(GIO_LIBS) $(BUNDLE_LIBS) $(DLOG_LIBS) $(CAPIBASECOMMON_LIBS) \ $(NULL) pkgconfigdir = $(libdir)/pkgconfig diff --git a/lib/compatibility/message_port.h b/lib/compatibility/message_port.h new file mode 100644 index 0000000..8972f37 --- /dev/null +++ b/lib/compatibility/message_port.h @@ -0,0 +1,98 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of message-port. + * + * Copyright (c) 2015 Samsung Electronics + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef __TIZEN_APPFW_MESSAGE_PORT_H__ +#define __TIZEN_APPFW_MESSAGE_PORT_H__ + +#ifdef __GNUC__ +# ifndef EXPORT_API +# define EXPORT_API __attribute__((visibility("default"))) +# endif +#else +# define EXPORT_API +#endif + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* For Tizen 2.3 Native API compatibility*/ +typedef enum +{ + MESSAGE_PORT_ERROR_NONE = MESSAGEPORT_ERROR_NONE, /**< Successful */ + MESSAGE_PORT_ERROR_IO_ERROR = MESSAGEPORT_ERROR_IO_ERROR, /**< Internal I/O error */ + MESSAGE_PORT_ERROR_OUT_OF_MEMORY = MESSAGEPORT_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + MESSAGE_PORT_ERROR_INVALID_PARAMETER = MESSAGEPORT_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + MESSAGE_PORT_ERROR_PORT_NOT_FOUND = MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND, /**< The message port of the remote application is not found */ + MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH = MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH, /**< The remote application is not signed with the same certificate */ + MESSAGE_PORT_ERROR_MAX_EXCEEDED = MESSAGEPORT_ERROR_MAX_EXCEEDED, /**< The size of the message has exceeded the maximum limit */ + MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE = MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE /**< Resource is temporarily unavailable */ +} message_port_error_e; + +typedef void (*message_port_message_cb)(int local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *messagem, void *user_data); +typedef void (*message_port_trusted_message_cb)(int trusted_local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data); + +EXPORT_API int +message_port_register_local_port (const char *local_port, message_port_message_cb callback, void *user_data); + +EXPORT_API int +message_port_register_trusted_local_port (const char *trusted_local_port, message_port_trusted_message_cb callback, void *user_data); + +EXPORT_API int +message_port_unregister_local_port (int local_port_id); + +EXPORT_API int +message_port_unregister_trusted_local_port (int trusted_local_port_id); + +EXPORT_API int +message_port_check_remote_port (const char *remote_app_id, const char *remote_port, bool *exist); + +EXPORT_API int +message_port_check_trusted_remote_port (const char *remote_app_id, const char *remote_port, bool *exist); + +EXPORT_API int +message_port_send_message (const char *remote_app_id, const char *remote_port, bundle *message); + +EXPORT_API int +message_port_send_trusted_message (const char *remote_app_id, const char *remote_port, bundle *message); + +EXPORT_API int +message_port_send_message_with_local_port (const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id); + +EXPORT_API int +message_port_send_trusted_message_with_local_port (const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_MESSAGE_PORT_H__ */ diff --git a/lib/compatibility/message_port_wrapper.c b/lib/compatibility/message_port_wrapper.c new file mode 100644 index 0000000..26c7c84 --- /dev/null +++ b/lib/compatibility/message_port_wrapper.c @@ -0,0 +1,87 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of message-port. + * + * Copyright (c) 2015 Samsung Electronics + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include "message_port.h" + +EXPORT_API int +message_port_register_local_port (const char *local_port, message_port_message_cb callback, void *user_data) +{ + return messageport_register_local_port_full (local_port, callback, user_data); +} + +EXPORT_API int +message_port_register_trusted_local_port (const char *trusted_local_port, message_port_trusted_message_cb callback, void *user_data) +{ + return messageport_register_trusted_local_port_full (trusted_local_port, callback, user_data); +} + +EXPORT_API int +message_port_unregister_local_port (int local_port_id) +{ + return messageport_unregister_local_port (local_port_id); +} + +EXPORT_API int +message_port_unregister_trusted_local_port (int trusted_local_port_id) +{ + return messageport_unregister_trusted_local_port (trusted_local_port_id); +} + +EXPORT_API int +message_port_check_remote_port (const char *remote_app_id, const char *remote_port, bool *exist) +{ + return messageport_check_remote_port (remote_app_id, remote_port, exist); +} + +EXPORT_API int +message_port_check_trusted_remote_port (const char *remote_app_id, const char *remote_port, bool *exist) +{ + return messageport_check_trusted_remote_port (remote_app_id, remote_port, exist); +} + +EXPORT_API int +message_port_send_message (const char *remote_app_id, const char *remote_port, bundle *message) +{ + return messageport_send_message (remote_app_id, remote_port, message); +} + +EXPORT_API int +message_port_send_trusted_message( const char *remote_app_id, const char *remote_port, bundle *message) +{ + return messageport_send_trusted_message (remote_app_id, remote_port, message); +} + +EXPORT_API int +message_port_send_message_with_local_port (const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id) +{ + return messageport_send_bidirectional_message (local_port_id, remote_app_id, remote_port, message); +} + +EXPORT_API int +message_port_send_trusted_message_with_local_port (const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id) +{ + return messageport_send_bidirectional_trusted_message (local_port_id, remote_app_id, remote_port, message); +} + + diff --git a/lib/message-port.c b/lib/message-port.c index cfe023b..56ff233 100644 --- a/lib/message-port.c +++ b/lib/message-port.c @@ -51,6 +51,26 @@ _messageport_register_port (const char *name, gboolean is_trusted, messageport_m return port_id > 0 ? port_id : (int)res; } +static int +_messageport_unregister_port (int local_port_id, gboolean is_trusted) +{ + messageport_error_e res, res_check_trust; + gboolean is_trusted_out = FALSE; + MsgPortManager *manager = msgport_factory_get_manager (); + if (!manager) return MESSAGEPORT_ERROR_IO_ERROR; + + res_check_trust = msgport_manager_get_service_is_trusted (manager, local_port_id, &is_trusted_out); + if (res_check_trust != MESSAGEPORT_ERROR_NONE) + return (int)res_check_trust; + + if (is_trusted_out == is_trusted) + return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND; + + res = msgport_manager_unregister_service (manager, local_port_id); + + return (int)res; +} + static messageport_error_e _messageport_check_remote_port (const char *app_id, const char *port, gboolean is_trusted, bool *exists) { @@ -72,6 +92,7 @@ _messageport_send_message (const char *app_id, const char *port, gboolean is_tru MsgPortManager *manager = msgport_factory_get_manager (); if (!manager) return MESSAGEPORT_ERROR_IO_ERROR; + if (!message) return MESSAGEPORT_ERROR_INVALID_PARAMETER; GVariant *v_data = bundle_to_variant_map (message); @@ -84,6 +105,7 @@ _messageport_send_bidirectional_message (int id, const gchar *remote_app_id, con MsgPortManager *manager = msgport_factory_get_manager (); if (!manager) return MESSAGEPORT_ERROR_IO_ERROR; + if (!message) return MESSAGEPORT_ERROR_INVALID_PARAMETER; GVariant *v_data = bundle_to_variant_map (message); @@ -118,6 +140,18 @@ messageport_register_trusted_local_port_full (const char *local_port, messagepor return _messageport_register_port (local_port, TRUE, callback, userdata); } +int +messageport_unregister_local_port (int local_port_id) +{ + return _messageport_unregister_port (local_port_id, FALSE); +} + +int +messageport_unregister_trusted_local_port (int trusted_local_port_id) +{ + return _messageport_unregister_port (trusted_local_port_id, TRUE); +} + messageport_error_e messageport_check_remote_port (const char *remote_app_id, const char *port_name, bool *exists) { @@ -178,3 +212,4 @@ messageport_check_trusted_local_port (int id, bool *is_trusted_out) return res; } + diff --git a/lib/message-port.h b/lib/message-port.h index 69b023d..f8cfdfb 100644 --- a/lib/message-port.h +++ b/lib/message-port.h @@ -36,10 +36,8 @@ #include #include - -#ifndef __cplusplus -typedef guint8 bool; -#endif +#include +#include G_BEGIN_DECLS @@ -58,13 +56,14 @@ G_BEGIN_DECLS */ typedef enum _messageport_error_e { - MESSAGEPORT_ERROR_NONE = 0, - MESSAGEPORT_ERROR_IO_ERROR = -1, - MESSAGEPORT_ERROR_OUT_OF_MEMORY = -2, - MESSAGEPORT_ERROR_INVALID_PARAMETER = -3, - MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = -4, - MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = -5, - MESSAGEPORT_ERROR_MAX_EXCEEDED = -6, + MESSAGEPORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + MESSAGEPORT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */ + MESSAGEPORT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + MESSAGEPORT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = TIZEN_ERROR_MESSAGE_PORT | 0x01, /**< The message port of the remote application is not found */ + MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = TIZEN_ERROR_MESSAGE_PORT | 0x02, /**< The remote application is not signed with the same certificate */ + MESSAGEPORT_ERROR_MAX_EXCEEDED = TIZEN_ERROR_MESSAGE_PORT | 0x03, /**< The size of the message has exceeded the maximum limit */ + MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE = TIZEN_ERROR_MESSAGE_PORT | 0x04 /**< Resource is temporarily unavailable */ } messageport_error_e; /** @@ -169,6 +168,40 @@ EXPORT_API int messageport_register_trusted_local_port_full(const char* local_port, messageport_message_cb_full callback, void *userdata); /** + * messageport_unregister_local_port: + * @local_port_id: The local message port ID + * + * Unregisters the local message port. + * This method unregisters the callback function with the specified local port ID. + * + * Returns: 0 on success, otherwise a negative error value. + * #MESSAGEPORT_ERROR_NONE Successful + * #MESSAGEPORT_ERROR_INVALID_PARAMETER The specified @a local_port_id is not positive + * #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The specified @a local_port_id cannot be found + * #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory + * #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error + */ +EXPORT_API int +messageport_unregister_local_port(int local_port_id); + +/** + * messageport_unregister_trusted_local_port: + * @trusted_local_port_id: The trusted local message port ID + * + * Unregisters the trusted local message port. + * This method unregisters the callback function with the specified trusted local port ID. + * + * Returns: 0 on success, otherwise a negative error value. + * #MESSAGEPORT_ERROR_NONE Successful + * #MESSAGEPORT_ERROR_INVALID_PARAMETER The specified @a local_port_id is not positive + * #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The specified @a local_port_id cannot be found + * #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory + * #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error + */ +EXPORT_API int +messageport_unregister_trusted_local_port(int trusted_local_port_id); + +/** * messageport_check_remote_port: * @remote_app_id: The ID of the remote application * @remote_port: the name of the remote message port to check for. diff --git a/lib/message-port.pc.in b/lib/message-port.pc.in index c10ba14..54058f6 100644 --- a/lib/message-port.pc.in +++ b/lib/message-port.pc.in @@ -7,7 +7,7 @@ Name: Message port client library Description: Message port client library for WRT plugin Version: @PACKAGE_VERSION@ URL: @PACKAGE_URL@ -Requires: glib-2.0 >= 2.30 gio-2.0 gio-unix-2.0 bundle dlog +Requires: glib-2.0 >= 2.30 gio-2.0 gio-unix-2.0 bundle dlog capi-base-common Libs: -L${libdir} -lmessage-port Cflags: -I${includedir} diff --git a/lib/msgport-manager.c b/lib/msgport-manager.c index 16137e5..2e88e1c 100644 --- a/lib/msgport-manager.c +++ b/lib/msgport-manager.c @@ -27,7 +27,6 @@ #include "msgport-manager.h" #include "msgport-service.h" #include "msgport-utils.h" /* msgport_daemon_error_to_error */ -#include "message-port.h" /* messageport_error_e */ #include "common/dbus-manager-glue.h" #ifdef USE_SESSION_BUS #include "common/dbus-server-glue.h" @@ -264,7 +263,7 @@ _get_local_port (MsgPortManager *manager, int service_id) } messageport_error_e -msgport_manager_unregister_servcie (MsgPortManager *manager, int service_id) +msgport_manager_unregister_service (MsgPortManager *manager, int service_id) { const gchar *object_path = NULL; MsgPortService *service = NULL; @@ -342,7 +341,7 @@ msgport_manager_get_service_is_trusted (MsgPortManager *manager, int service_id, MsgPortService *service = NULL; g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), MESSAGEPORT_ERROR_IO_ERROR); g_return_val_if_fail (manager->proxy, MESSAGEPORT_ERROR_IO_ERROR); - g_return_val_if_fail (service_id && is_trusted_out, MESSAGEPORT_ERROR_INVALID_PARAMETER); + g_return_val_if_fail (service_id > 0 && is_trusted_out, MESSAGEPORT_ERROR_INVALID_PARAMETER); service = _get_local_port (manager, service_id); if (!service) return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND; diff --git a/packaging/message-port.spec b/packaging/message-port.spec index be90a97..c11dddf 100644 --- a/packaging/message-port.spec +++ b/packaging/message-port.spec @@ -19,6 +19,7 @@ BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(glib-2.0) >= 2.30 BuildRequires: pkgconfig(gobject-2.0) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(capi-base-common) %description This daemon allows the webapplications to communicates using @@ -115,13 +116,14 @@ ldconfig %manifest %{name}.manifest %defattr(-,root,root,-) %doc AUTHORS COPYING.LIB -%{_libdir}/lib%{name}.so* +%{_libdir}/lib%{name}.so.* #libmessage-port-devel %files -n lib%{name}-devel %defattr(-,root,root,-) %manifest %{name}.manifest %{_libdir}/pkgconfig/%{name}.pc +%{_libdir}/lib%{name}.so %{_includedir}/*.h %if %{build_tests} == 1