From: Jonathan Maw Date: Fri, 15 Jun 2012 09:57:08 +0000 (+0100) Subject: Add skeleton for the legacy-app-handler service application X-Git-Tag: boot-manager-0.1.0~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=945bfed36b23ad1eb8e3c6fe2f3248588dd6fafa;p=profile%2Fivi%2Fnode-startup-controller.git Add skeleton for the legacy-app-handler service application This is analogue to the boot-manager and luc-handler skeletons and involves a GApplication subclass (LAHandlerApplication), an (empty) implementation of the org.genivi.LegacyAppHandler1 D-Bus interface (LAHandlerService) and an org.genivi.LegacyAppHandler1.service file to allow D-Bus to activate the service on demand. --- diff --git a/Makefile.am b/Makefile.am index 572ae90..8a574ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ SUBDIRS = \ boot-manager \ + legacy-app-handler \ luc-handler \ tests diff --git a/configure.ac b/configure.ac index 01b24f1..14f0d8f 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,7 @@ fi AC_OUTPUT([ Makefile boot-manager/Makefile +legacy-app-handler/Makefile luc-handler/Makefile luc-handler/org.genivi.LUCHandler1.gschema.xml tests/Makefile diff --git a/legacy-app-handler/Makefile.am b/legacy-app-handler/Makefile.am new file mode 100644 index 0000000..2615b17 --- /dev/null +++ b/legacy-app-handler/Makefile.am @@ -0,0 +1,79 @@ +# vi:set ts=8 sw=8 noet ai nocindent: + +legacy_app_handlerdir = \ + $(libdir)/legacy-app-handler-$(BOOT_MANAGER_VERSION_API) + +legacy_app_handler_PROGRAMS = \ + legacy-app-handler + +legacy_app_handler_built_headers = \ + la-handler-dbus.h + +legacy_app_handler_built_sources = \ + la-handler-dbus.c \ + $(legacy_app_handler_built_headers) + +legacy_app_handler_SOURCES = \ + ../common/glib-extensions.c \ + ../common/glib-extensions.h \ + ../common/watchdog-client.c \ + ../common/watchdog-client.h \ + la-handler-application.c \ + la-handler-application.h \ + la-handler-service.c \ + la-handler-service.h \ + main.c \ + $(legacy_app_handler_built_sources) + +legacy_app_handler_CFLAGS = \ + -DG_LOG_DOMAIN=\"legacy-app-handler\" \ + -I$(top_srcdir) \ + $(GIO_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(PLATFORM_CFLAGS) \ + $(PLATFORM_CPPFLAGS) \ + $(SYSTEMD_DAEMON_CFLAGS) + +legacy_app_handler_LDFLAGS = \ + -no-undefined \ + $(PLATFORM_LDFLAGS) + +legacy_app_handler_LDADD = \ + $(GIO_LIBS) \ + $(GIO_UNIX_LIBS) \ + $(GLIB_LIBS) \ + $(SYSTEMD_DAEMON_LIBS) + +servicedir = $(datadir)/dbus-1/services +service_in_files = \ + org.genivi.LAHandler1.service.in + +service_DATA = $(service_in_files:.service.in=.service) + +%.service: %.service.in + sed -e "s,\@libdir\@,$(libdir),g" \ + -e "s,\@BOOT_MANAGER_VERSION_API\@,$(BOOT_MANAGER_VERSION_API),g" < $< > $@ + +CLEANFILES = \ + $(service_DATA) + +EXTRA_DIST = \ + $(service_in_files) \ + $(gsettingsschema_in_files) \ + la-handler-dbus.xml + +DISTCLEANFILES = \ + $(legacy_app_handler_built_sources) \ + $(gsettings_SCHEMAS) + +BUILT_SOURCES = \ + $(legacy_app_handler_built_headers) + +la-handler-dbus.h: la-handler-dbus.xml Makefile + $(AM_V_GEN) $(GDBUS_CODEGEN) \ + --interface-prefix org.genivi \ + --c-namespace "" \ + --generate-c-code la-handler-dbus \ + --annotate org.genivi.LegacyAppHandler1 org.gtk.GDBus.C.Name \ + LA_Handler $< diff --git a/legacy-app-handler/la-handler-application.c b/legacy-app-handler/la-handler-application.c new file mode 100644 index 0000000..0ce2b78 --- /dev/null +++ b/legacy-app-handler/la-handler-application.c @@ -0,0 +1,182 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/* - + * Copyright (c) 2012 GENIVI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +#include +#include +#include + + + +/* property identifiers */ +enum +{ + PROP_0, + PROP_LA_HANDLER_SERVICE, +}; + + + +static void la_handler_application_finalize (GObject *object); +static void la_handler_application_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void la_handler_application_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void la_handler_application_startup (GApplication *application); + + + +struct _LAHandlerApplicationClass +{ + GApplicationClass __parent__; +}; + +struct _LAHandlerApplication +{ + GApplication __parent__; + + /* systemd watchdog client that repeatedly asks systemd to update + * the watchdog timestamp */ + WatchdogClient *watchdog_client; + + /* service object that implements the Legacy App Handler D-Bus interface */ + LAHandlerService *service; +}; + + + +G_DEFINE_TYPE (LAHandlerApplication, la_handler_application, G_TYPE_APPLICATION); + + + +static void +la_handler_application_class_init (LAHandlerApplicationClass *klass) +{ + GApplicationClass *gapplication_class; + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = la_handler_application_finalize; + gobject_class->get_property = la_handler_application_get_property; + gobject_class->set_property = la_handler_application_set_property; + + gapplication_class = G_APPLICATION_CLASS (klass); + gapplication_class->startup = la_handler_application_startup; + + g_object_class_install_property (gobject_class, + PROP_LA_HANDLER_SERVICE, + g_param_spec_object ("la-handler-service", + "la-handler-service", + "la-handler-service", + LA_HANDLER_TYPE_SERVICE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + + + +static void +la_handler_application_init (LAHandlerApplication *application) +{ +} + + + +static void +la_handler_application_finalize (GObject *object) +{ + LAHandlerApplication *application = LA_HANDLER_APPLICATION (object); + + /* release the watchdog client */ + g_object_unref (application->watchdog_client); + + /* release the Legacy App Handler service implementation */ + if (application->service != NULL) + g_object_unref (application->service); + + (*G_OBJECT_CLASS (la_handler_application_parent_class)->finalize) (object); +} + + + +static void +la_handler_application_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + LAHandlerApplication *application = LA_HANDLER_APPLICATION (object); + + switch (prop_id) + { + case PROP_LA_HANDLER_SERVICE: + g_value_set_object (value, application->service); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +static void +la_handler_application_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + LAHandlerApplication *application = LA_HANDLER_APPLICATION (object); + + switch (prop_id) + { + case PROP_LA_HANDLER_SERVICE: + application->service = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +static void +la_handler_application_startup (GApplication *app) +{ + LAHandlerApplication *application = LA_HANDLER_APPLICATION (app); + + /* update systemd's watchdog timestamp every 120 seconds */ + application->watchdog_client = watchdog_client_new (120); +} + + + +LAHandlerApplication * +la_handler_application_new (LAHandlerService *service) +{ + return g_object_new (LA_HANDLER_TYPE_APPLICATION, + "application-id", "org.genivi.LegacyAppHandler1", + "flags", G_APPLICATION_IS_SERVICE, + "la-handler-service", service, + NULL); +} diff --git a/legacy-app-handler/la-handler-application.h b/legacy-app-handler/la-handler-application.h new file mode 100644 index 0000000..aea8d14 --- /dev/null +++ b/legacy-app-handler/la-handler-application.h @@ -0,0 +1,34 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/* - + * Copyright (c) 2012 GENIVI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __LA_HANDLER_APPLICATION_H__ +#define __LA_HANDLER_APPLICATION_H__ + +#include + +G_BEGIN_DECLS + +#define LA_HANDLER_TYPE_APPLICATION (la_handler_application_get_type ()) +#define LA_HANDLER_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LA_HANDLER_TYPE_APPLICATION, LAHandlerApplication)) +#define LA_HANDLER_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LA_HANDLER_TYPE_APPLICATION, LAHandlerApplicationClass)) +#define LA_HANDLER_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LA_HANDLER_TYPE_APPLICATION)) +#define LA_HANDLER_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LA_HANDLER_TYPE_APPLICATION) +#define LA_HANDLER_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LA_HANDLER_TYPE_APPLICATION, LAHandlerApplicationClass)) + +typedef struct _LAHandlerApplicationClass LAHandlerApplicationClass; +typedef struct _LAHandlerApplication LAHandlerApplication; + +GType la_handler_application_get_type (void) G_GNUC_CONST; + +LAHandlerApplication *la_handler_application_new (LAHandlerService *service) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + +G_END_DECLS + +#endif /* !__LA_HANDLER_APPLICATION_H__ */ + diff --git a/legacy-app-handler/la-handler-dbus.xml b/legacy-app-handler/la-handler-dbus.xml new file mode 100644 index 0000000..b4975aa --- /dev/null +++ b/legacy-app-handler/la-handler-dbus.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + diff --git a/legacy-app-handler/la-handler-service.c b/legacy-app-handler/la-handler-service.c new file mode 100644 index 0000000..7312c0d --- /dev/null +++ b/legacy-app-handler/la-handler-service.c @@ -0,0 +1,227 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/* - + * Copyright (c) 2012 GENIVI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +#include +#include + + + +/* property identifiers */ +enum +{ + PROP_0, + PROP_CONNECTION, +}; + + + +static void la_handler_service_finalize (GObject *object); +static void la_handler_service_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void la_handler_service_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static gboolean la_handler_service_handle_register (LAHandler *interface, + GDBusMethodInvocation *invocation, + GVariant *apps, + LAHandlerService *service); +static gboolean la_handler_service_handle_deregister (LAHandler *interface, + GDBusMethodInvocation *invocation, + GVariant *apps, + LAHandlerService *service); + + + +struct _LAHandlerServiceClass +{ + GObjectClass __parent__; +}; + +struct _LAHandlerService +{ + GObject __parent__; + + GDBusConnection *connection; + LAHandler *interface; +}; + + + +G_DEFINE_TYPE (LAHandlerService, la_handler_service, G_TYPE_OBJECT); + + + +static void +la_handler_service_class_init (LAHandlerServiceClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = la_handler_service_finalize; + gobject_class->get_property = la_handler_service_get_property; + gobject_class->set_property = la_handler_service_set_property; + + g_object_class_install_property (gobject_class, + PROP_CONNECTION, + g_param_spec_object ("connection", + "connection", + "connection", + G_TYPE_DBUS_CONNECTION, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + + + +static void +la_handler_service_init (LAHandlerService *service) +{ + service->interface = la_handler_skeleton_new (); + + /* implement the Register() handler */ + g_signal_connect (service->interface, "handle-register", + G_CALLBACK (la_handler_service_handle_register), + service); + + /* implement the Deregister() handler */ + g_signal_connect (service->interface, "handle-deregister", + G_CALLBACK (la_handler_service_handle_deregister), + service); +} + + + + +static void +la_handler_service_finalize (GObject *object) +{ + LAHandlerService *service = LA_HANDLER_SERVICE (object); + + /* release the D-Bus connection object */ + if (service->connection != NULL) + g_object_unref (service->connection); + + /* release the interface skeleton */ + g_signal_handlers_disconnect_matched (service->interface, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, service); + g_object_unref (service->interface); + + (*G_OBJECT_CLASS (la_handler_service_parent_class)->finalize) (object); +} + + + +static void +la_handler_service_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + LAHandlerService *service = LA_HANDLER_SERVICE (object); + + switch (prop_id) + { + case PROP_CONNECTION: + g_value_set_object (value, service->connection); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +static void +la_handler_service_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + LAHandlerService *service = LA_HANDLER_SERVICE (object); + + switch (prop_id) + { + case PROP_CONNECTION: + service->connection = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +static gboolean +la_handler_service_handle_register (LAHandler *object, + GDBusMethodInvocation *invocation, + GVariant *apps, + LAHandlerService *service) +{ + g_debug ("Register called:"); + + /* Notify the caller that we have handled the registration request */ + g_dbus_method_invocation_return_value (invocation, NULL); + return TRUE; +} + + + +static gboolean +la_handler_service_handle_deregister (LAHandler *object, + GDBusMethodInvocation *invocation, + GVariant *apps, + LAHandlerService *service) +{ + g_debug ("Deregister called:"); + + /* Notify the caller that we have handled the registration request */ + g_dbus_method_invocation_return_value (invocation, NULL); + return TRUE; +} + + + +LAHandlerService * +la_handler_service_new (GDBusConnection *connection) +{ + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); + return g_object_new (LA_HANDLER_TYPE_SERVICE, "connection", connection, NULL); +} + + + +gboolean +la_handler_service_start (LAHandlerService *service, + GError **error) +{ + g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* announce the org.genivi.LegacyAppHandler1 service on the bus */ + return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (service->interface), + service->connection, + "/org/genivi/LegacyAppHandler1", + error); +} diff --git a/legacy-app-handler/la-handler-service.h b/legacy-app-handler/la-handler-service.h new file mode 100644 index 0000000..8db9ffe --- /dev/null +++ b/legacy-app-handler/la-handler-service.h @@ -0,0 +1,36 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/* - + * Copyright (c) 2012 GENIVI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __LA_HANDLER_SERVICE_H__ +#define __LA_HANDLER_SERVICE_H__ + +#include + +G_BEGIN_DECLS + +#define LA_HANDLER_TYPE_SERVICE (la_handler_service_get_type ()) +#define LA_HANDLER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LA_HANDLER_TYPE_SERVICE, LAHandlerService)) +#define LA_HANDLER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LA_HANDLER_TYPE_SERVICE, LAHandlerServiceClass)) +#define LA_HANDLER_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LA_HANDLER_TYPE_SERVICE)) +#define LA_HANDLER_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LA_HANDLER_TYPE_SERVICE) +#define LA_HANDLER_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LA_HANDLER_TYPE_SERVICE, LAHandlerServiceClass)) + +typedef struct _LAHandlerServiceClass LAHandlerServiceClass; +typedef struct _LAHandlerService LAHandlerService; + +GType la_handler_service_get_type (void) G_GNUC_CONST; + +LAHandlerService *la_handler_service_new (GDBusConnection *connection) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gboolean la_handler_service_start (LAHandlerService *service, + GError **error); + +G_END_DECLS + +#endif /* !__LA_HANDLER_SERVICE_H__ */ + diff --git a/legacy-app-handler/main.c b/legacy-app-handler/main.c new file mode 100644 index 0000000..9338f37 --- /dev/null +++ b/legacy-app-handler/main.c @@ -0,0 +1,75 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/* - + * Copyright (c) 2012 GENIVI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#include +#include + +#include +#include + + + +int +main (int argc, + char **argv) +{ + LAHandlerApplication *application; + LAHandlerService *service; + GDBusConnection *connection; + GError *error = NULL; + gint exit_status = EXIT_SUCCESS; + + /* initialize the GType type system */ + g_type_init (); + + /* attempt to connect to D-Bus */ + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + if (connection == NULL) + { + g_warning ("Failed to connect to D-Bus: %s", error->message); + + /* clean up */ + g_error_free (error); + + return EXIT_FAILURE; + } + + /* Instantiate the LegacyAppHandler service implementation */ + service = la_handler_service_new (connection); + if (!la_handler_service_start (service, &error)) + { + g_warning ("Failed to start the LegacyAppHandler service: %s", error->message); + + /* clean up */ + g_error_free (error); + g_object_unref (service); + g_object_unref (connection); + + return EXIT_FAILURE; + } + + /* create and run the main application */ + application = la_handler_application_new (service); + exit_status = g_application_run (G_APPLICATION (application), 0, NULL); + g_object_unref (application); + + /* release allocated objects */ + g_object_unref (service); + g_object_unref (connection); + + return exit_status; +} diff --git a/legacy-app-handler/org.genivi.LAHandler1.service b/legacy-app-handler/org.genivi.LAHandler1.service new file mode 100644 index 0000000..d4d0878 --- /dev/null +++ b/legacy-app-handler/org.genivi.LAHandler1.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.genivi.LegacyAppHandler1 +Exec=/usr/local/lib/legacy-app-handler-1/legacy-app-handler diff --git a/legacy-app-handler/org.genivi.LAHandler1.service.in b/legacy-app-handler/org.genivi.LAHandler1.service.in new file mode 100644 index 0000000..699c728 --- /dev/null +++ b/legacy-app-handler/org.genivi.LAHandler1.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.genivi.LAHandler1 +Exec=@libdir@/legacy-app-handler-@BOOT_MANAGER_VERSION_API@/legacy-app-handler