Skip to content

Commit

Permalink
[unit] Added plugins_dbus_service_plugin test. JB#48413
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Dec 22, 2019
1 parent 14f818e commit 5af30b6
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 7 deletions.
1 change: 1 addition & 0 deletions plugins/Makefile
Expand Up @@ -41,6 +41,7 @@ DBUS_SERVICE_PLUGIN_SRC = \
dbus_service_adapter.c \
dbus_service_error.c \
dbus_service_isodep.c \
dbus_service_name.c \
dbus_service_ndef.c \
dbus_service_plugin.c \
dbus_service_tag.c \
Expand Down
13 changes: 13 additions & 0 deletions plugins/dbus_service/dbus_service.h
Expand Up @@ -44,6 +44,7 @@

typedef struct dbus_service_adapter DBusServiceAdapter;
typedef struct dbus_service_ndef DBusServiceNdef;
typedef struct dbus_service_plugin DBusServicePlugin;
typedef struct dbus_service_tag DBusServiceTag;
typedef struct dbus_service_tag_t2 DBusServiceTagType2;
typedef struct dbus_service_isodep DBusServiceIsoDep;
Expand All @@ -65,6 +66,18 @@ typedef enum dbus_service_error {
#define NFC_DBUS_TAG_T2_INTERFACE "org.sailfishos.nfc.TagType2"
#define NFC_DBUS_ISODEP_INTERFACE "org.sailfishos.nfc.IsoDep"

guint
dbus_service_name_own(
DBusServicePlugin* plugin,
const char* name,
GBusAcquiredCallback bus_acquired,
GBusNameAcquiredCallback name_acquired,
GBusNameLostCallback name_lost);

void
dbus_service_name_unown(
guint id);

/* org.sailfishos.nfc.Adapter */

DBusServiceAdapter*
Expand Down
61 changes: 61 additions & 0 deletions plugins/dbus_service/dbus_service_name.c
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the names of the copyright holders 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 HOLDERS 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 "dbus_service.h"

guint
dbus_service_name_own(
DBusServicePlugin* plugin,
const char* name,
GBusAcquiredCallback bus_acquired,
GBusNameAcquiredCallback name_acquired,
GBusNameLostCallback name_lost)
{
return g_bus_own_name(G_BUS_TYPE_SYSTEM, name,
G_BUS_NAME_OWNER_FLAGS_REPLACE, bus_acquired, name_acquired,
name_lost, plugin, NULL);
}

void
dbus_service_name_unown(
guint id)
{
g_bus_unown_name(id);
}

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
13 changes: 6 additions & 7 deletions plugins/dbus_service/dbus_service_plugin.c
Expand Up @@ -63,7 +63,7 @@ enum {
};

typedef NfcPluginClass DBusServicePluginClass;
typedef struct dbus_service_plugin {
struct dbus_service_plugin {
NfcPlugin parent;
guint own_name_id;
GUtilIdlePool* pool;
Expand All @@ -73,7 +73,7 @@ typedef struct dbus_service_plugin {
OrgSailfishosNfcDaemon* iface;
gulong event_id[EVENT_COUNT];
gulong call_id[CALL_COUNT];
} DBusServicePlugin;
};

G_DEFINE_TYPE(DBusServicePlugin, dbus_service_plugin, NFC_TYPE_PLUGIN)
#define DBUS_SERVICE_TYPE_PLUGIN (dbus_service_plugin_get_type())
Expand Down Expand Up @@ -329,10 +329,9 @@ dbus_service_plugin_start(
GVERBOSE("Starting");
self->manager = nfc_manager_ref(manager);
self->iface = org_sailfishos_nfc_daemon_skeleton_new();
self->own_name_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, NFC_SERVICE,
G_BUS_NAME_OWNER_FLAGS_REPLACE, dbus_service_plugin_bus_connected,
dbus_service_plugin_name_acquired, dbus_service_plugin_name_lost,
self, NULL);
self->own_name_id = dbus_service_name_own(self, NFC_SERVICE,
dbus_service_plugin_bus_connected, dbus_service_plugin_name_acquired,
dbus_service_plugin_name_lost);

/* NfcManager events */
self->event_id[EVENT_ADAPTER_ADDED] =
Expand Down Expand Up @@ -374,7 +373,7 @@ dbus_service_plugin_stop(
g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(self->iface));
g_hash_table_remove_all(self->adapters);
g_object_unref(self->iface);
g_bus_unown_name(self->own_name_id);
dbus_service_name_unown(self->own_name_id);
nfc_manager_remove_all_handlers(self->manager, self->event_id);
nfc_manager_unref(self->manager);
if (self->connection) {
Expand Down
1 change: 1 addition & 0 deletions unit/Makefile
Expand Up @@ -25,6 +25,7 @@ all:
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*
@$(MAKE) -C plugins_dbus_service_plugin $*
@$(MAKE) -C plugins_dbus_service_tag $*

clean: unitclean
Expand Down
1 change: 1 addition & 0 deletions unit/coverage/run
Expand Up @@ -27,6 +27,7 @@ plugins_dbus_handlers_type_sp \
plugins_dbus_handlers_type_text \
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter \
plugins_dbus_service_plugin \
plugins_dbus_service_tag"

function err() {
Expand Down
7 changes: 7 additions & 0 deletions unit/plugins_dbus_service_plugin/Makefile
@@ -0,0 +1,7 @@
# -*- Mode: makefile-gmake -*-

EXE = test_plugins_dbus_service_plugin

COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c

include ../common/Makefile.plugins

0 comments on commit 5af30b6

Please sign in to comment.