From 012681a1afa2d3b272aa8b6045f7c6c43192f9b5 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 19 May 2022 17:35:18 +0300 Subject: [PATCH] [sample] Initial commit --- .gitignore | 2 + LICENSE | 34 ++++ Makefile | 146 +++++++++++++++++ README | 27 +++ rpm/ofono-binder-plugin-ext-sample.spec | 40 +++++ sample.conf | 2 + src/sample_ext.c | 107 ++++++++++++ src/sample_ext.h | 58 +++++++ src/sample_ims.c | 208 ++++++++++++++++++++++++ src/sample_ims.h | 56 +++++++ src/sample_plugin.c | 75 +++++++++ src/sample_slot.c | 149 +++++++++++++++++ src/sample_slot.h | 59 +++++++ 13 files changed, 963 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 rpm/ofono-binder-plugin-ext-sample.spec create mode 100644 sample.conf create mode 100644 src/sample_ext.c create mode 100644 src/sample_ext.h create mode 100644 src/sample_ims.c create mode 100644 src/sample_ims.h create mode 100644 src/sample_plugin.c create mode 100644 src/sample_slot.c create mode 100644 src/sample_slot.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdc5af0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..928d7af --- /dev/null +++ b/LICENSE @@ -0,0 +1,34 @@ +Copyright (C) 2022 Jolla Ltd. +Copyright (C) 2022 Slava Monich + +You may use this file under the terms of the 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 +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. + +The views and conclusions contained in the software and documentation +are those of the authors and should not be interpreted as representing +any official policies, either expressed or implied. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b3c2d6 --- /dev/null +++ b/Makefile @@ -0,0 +1,146 @@ +# -*- Mode: makefile-gmake -*- + +.PHONY: clean all debug release + +# +# Required packages +# +# ofono.pc adds -export-symbols-regex linker option which doesn't work +# on all platforms. +# + +LDPKGS = libofonobinderpluginext libgbinder-radio libgbinder libglibutil gobject-2.0 glib-2.0 +PKGS = ofono $(LDPKGS) + +# +# Default target +# + +all: debug release + +# +# Library name +# + +NAME = samplebinderpluginext +LIB_NAME = $(NAME) +LIB_SONAME = $(LIB_NAME).so +LIB = $(LIB_SONAME) +STATIC_LIB = $(NAME).a + +# +# Sources +# + +SRC = \ + sample_ext.c \ + sample_ims.c \ + sample_plugin.c \ + sample_slot.c + +# +# Directories +# + +SRC_DIR = src +BUILD_DIR = build +DEBUG_BUILD_DIR = $(BUILD_DIR)/debug +RELEASE_BUILD_DIR = $(BUILD_DIR)/release + +# +# Tools and flags +# + +CC = $(CROSS_COMPILE)gcc +LD = $(CC) +WARNINGS = -Wall +BASE_FLAGS = -fPIC -fvisibility=hidden +FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) -MMD -MP \ + $(shell pkg-config --cflags $(PKGS)) +FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared \ + $(shell pkg-config --libs $(LDPKGS)) +DEBUG_FLAGS = -g +RELEASE_FLAGS = + +KEEP_SYMBOLS ?= 0 +ifneq ($(KEEP_SYMBOLS),0) +RELEASE_FLAGS += -g +endif + +DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS) +RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS) +DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG +RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2 + +# +# Files +# + +DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o) +RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) + +DEBUG_SO = $(DEBUG_BUILD_DIR)/$(LIB) +RELEASE_SO = $(RELEASE_BUILD_DIR)/$(LIB) + +# +# Dependencies +# + +DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d) +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(DEPS)),) +-include $(DEPS) +endif +endif + +$(DEBUG_OBJS) $(DEBUG_SO): | $(DEBUG_BUILD_DIR) +$(RELEASE_OBJS) $(RELEASE_SO): | $(RELEASE_BUILD_DIR) + +# +# Rules +# + +debug: $(DEBUG_SO) + +release: $(RELEASE_SO) + +clean: + rm -f $(SRC_DIR)/*~ rpm/*~ *~ + rm -fr $(BUILD_DIR) + +$(DEBUG_BUILD_DIR): + mkdir -p $@ + +$(RELEASE_BUILD_DIR): + mkdir -p $@ + +$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c + $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ + +$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c + $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ + +$(DEBUG_SO): $(DEBUG_OBJS) + $(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) $(DEBUG_LIBS) -o $@ + +$(RELEASE_SO): $(RELEASE_OBJS) + $(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) $(RELEASE_LIBS) -o $@ +ifeq ($(KEEP_SYMBOLS),0) + $(STRIP) $@ +endif + +# +# Install +# + +PLUGINDIR ?= $$(pkg-config ofono --variable=plugindir) +ABS_PLUGINDIR := $(shell echo /$(PLUGINDIR) | sed -r 's|/+|/|g') + +INSTALL = install +INSTALL_PLUGIN_DIR = $(DESTDIR)$(ABS_PLUGINDIR) + +install: $(INSTALL_PLUGIN_DIR) + $(INSTALL) -m 755 $(RELEASE_SO) $(INSTALL_PLUGIN_DIR) + +$(INSTALL_PLUGIN_DIR): + $(INSTALL) -d $@ diff --git a/README b/README new file mode 100644 index 0000000..06a7a12 --- /dev/null +++ b/README @@ -0,0 +1,27 @@ +Sample ofono binder plugin extension +==================================== + +It doesn't really do anything. It's just a demonstration of how +the extension interfaces (BINDER_EXT_TYPE_IMS being used as an +example) are supposed to be implemented. + +Here is what happens when this extension gets loaded. + +1. ofono calls sample_plugin_init(). That function creates an + instance of SampleExt and registers it under the name "sample" + by calling binder_ext_plugin_register() + +2. ofono-binder-plugin finds the extension by name which it reads + from /etc/ofono/binder.d/sample.conf + +3. ofono-binder-plugin calls sample_ext_new_slot() method of SampleExt + for each configured/detected slot. That creates per-slot SampleSlot + objects. + +4. ofono-binder-plugin asks SampleSlot for particular interfaces by + calling its sample_slot_get_interface() method. SampleSlot only + reacts to BINDER_EXT_TYPE_IMS query and returns a pointer to + SampleIms object implementing BinderExtImsInterface + +5. ofono-binder-plugin then goes on to call BinderExtImsInterface + methods of SampleIms object(s). diff --git a/rpm/ofono-binder-plugin-ext-sample.spec b/rpm/ofono-binder-plugin-ext-sample.spec new file mode 100644 index 0000000..e22e8c1 --- /dev/null +++ b/rpm/ofono-binder-plugin-ext-sample.spec @@ -0,0 +1,40 @@ +Name: ofono-binder-plugin-ext-sample + +Version: 1.0.0 +Release: 1 +Summary: Sample extension for ofono binder plugin +License: BSD +URL: https://github.com/monich/ofono-binder-plugin-ext-sample +Source: %{name}-%{version}.tar.bz2 + +BuildRequires: ofono-devel +BuildRequires: pkgconfig +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(libglibutil) +BuildRequires: pkgconfig(libgbinder-radio) +BuildRequires: pkgconfig(libofonobinderpluginext) + +%define plugin_dir %(pkg-config ofono --variable=plugindir) +%define config_dir /etc/ofono/binder.d/ + +%description +Sample extension for ofono binder plugin + +%prep +%setup -q -n %{name}-%{version} + +%build +make %{_smp_mflags} PLUGINDIR=%{plugin_dir} KEEP_SYMBOLS=1 release + +%install +rm -rf %{buildroot} +make DESTDIR=%{buildroot} PLUGINDIR=%{plugin_dir} install +mkdir -p %{buildroot}%{config_dir} +install -m 644 sample.conf %{buildroot}%{config_dir} + +%files +%dir %{plugin_dir} +%dir %{config_dir} +%defattr(-,root,root,-) +%config %{config_dir}/sample.conf +%{plugin_dir}/samplebinderpluginext.so diff --git a/sample.conf b/sample.conf new file mode 100644 index 0000000..714c9c9 --- /dev/null +++ b/sample.conf @@ -0,0 +1,2 @@ +[Settings] +extPlugin = sample diff --git a/src/sample_ext.c b/src/sample_ext.c new file mode 100644 index 0000000..f9e3e10 --- /dev/null +++ b/src/sample_ext.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "sample_ext.h" +#include "sample_slot.h" + +#include + +typedef struct sample_ext { + BinderExtPlugin parent; +} SampleExt; + +typedef BinderExtPluginClass SampleExtClass; + +GType sample_ext_get_type() G_GNUC_INTERNAL; +G_DEFINE_TYPE(SampleExt, sample_ext, BINDER_EXT_TYPE_PLUGIN) + +#define THIS_TYPE sample_ext_get_type() +#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, SampleExt) + +const char sample_plugin_name[] = "sample"; + +/*==========================================================================* + * BinderExtPluginClass + *==========================================================================*/ + +static +BinderExtSlot* +sample_ext_new_slot( + BinderExtPlugin* plugin, + RadioInstance* radio, + GHashTable* params) +{ + return sample_slot_new(radio, params); +} + +/*==========================================================================* + * API + *==========================================================================*/ + +BinderExtPlugin* +sample_ext_new() +{ + return g_object_new(THIS_TYPE, NULL); +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +sample_ext_init( + SampleExt* self) +{ +} + +static +void +sample_ext_class_init( + SampleExtClass* klass) +{ + klass->plugin_name = sample_plugin_name; + klass->new_slot = sample_ext_new_slot; +} + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_ext.h b/src/sample_ext.h new file mode 100644 index 0000000..9988a67 --- /dev/null +++ b/src/sample_ext.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef SAMPLE_EXT_H +#define SAMPLE_EXT_H + +#include + +extern const char sample_plugin_name[] G_GNUC_INTERNAL; + +BinderExtPlugin* +sample_ext_new( + void) + G_GNUC_INTERNAL; + +#endif /* SAMPLE_EXT_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_ims.c b/src/sample_ims.c new file mode 100644 index 0000000..8f99e77 --- /dev/null +++ b/src/sample_ims.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "sample_ims.h" +#include "sample_slot.h" + +#include + +#include + +typedef GObjectClass SampleImsClass; +typedef struct sample_ims { + GObject parent; + char* slot; +} SampleIms; + +static +void +sample_ims_iface_init( + BinderExtImsInterface* iface); + +GType sample_ims_get_type() G_GNUC_INTERNAL; +G_DEFINE_TYPE_WITH_CODE(SampleIms, sample_ims, G_TYPE_OBJECT, +G_IMPLEMENT_INTERFACE(BINDER_EXT_TYPE_IMS, sample_ims_iface_init)) + +#define THIS_TYPE sample_ims_get_type() +#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, SampleIms) +#define PARENT_CLASS sample_ims_parent_class + +enum sample_ims_signal { + SIGNAL_STATE_CHANGED, + SIGNAL_COUNT +}; + +#define SIGNAL_STATE_CHANGED_NAME "sample-ims-state-changed" + +static guint sample_ims_signals[SIGNAL_COUNT] = { 0 }; + +/*==========================================================================* + * BinderExtImsInterface + *==========================================================================*/ + +static +BINDER_EXT_IMS_STATE +sample_ims_get_state( + BinderExtIms* ext) +{ + SampleIms* self = THIS(ext); + + DBG("%s", self->slot); +#pragma message("TODO: return the actual state") + return BINDER_EXT_IMS_STATE_UNKNOWN; +} + +static +guint +sample_ims_set_registration( + BinderExtIms* ext, + BINDER_EXT_IMS_REGISTRATION registration, + BinderExtImsResultFunc complete, + GDestroyNotify destroy, + void* user_data) +{ + SampleIms* self = THIS(ext); + const gboolean on = (registration != BINDER_EXT_IMS_REGISTRATION_OFF); + + DBG("%s %s", self->slot, on ? "on" : "off"); + if (on) { +#pragma message("TODO: turn IMS registration on") + } else { +#pragma message("TODO: turn IMS registration off") + } + return 0; +} + +static +void +sample_ims_cancel( + BinderExtIms* ext, + guint id) +{ + SampleIms* self = THIS(ext); + + /* + * Cancel a pending operation identified by the id returned by the + * above sample_ims_set_registration() call. + */ + DBG("%s %u", self->slot, id); +} + +static +gulong +sample_ims_add_state_handler( + BinderExtIms* ext, + BinderExtImsFunc handler, + void* user_data) +{ + SampleIms* self = THIS(ext); + + DBG("%s", self->slot); + return G_LIKELY(handler) ? g_signal_connect(self, + SIGNAL_STATE_CHANGED_NAME, G_CALLBACK(handler), user_data) : 0; +} + +static +void +sample_ims_iface_init( + BinderExtImsInterface* iface) +{ + iface->version = BINDER_EXT_IMS_INTERFACE_VERSION; + iface->get_state = sample_ims_get_state; + iface->set_registration = sample_ims_set_registration; + iface->cancel = sample_ims_cancel; + iface->add_state_handler = sample_ims_add_state_handler; +} + +/*==========================================================================* + * API + *==========================================================================*/ + +BinderExtIms* +sample_ims_new( + const char* slot) +{ + SampleIms* self = g_object_new(THIS_TYPE, NULL); + + /* + * This could be the place to register a listener that gets invoked + * on registration state change and emits SIGNAL_STATE_CHANGED. + */ + self->slot = g_strdup(slot); + return BINDER_EXT_IMS(self); +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +sample_ims_finalize( + GObject* object) +{ + SampleIms* self = THIS(object); + + g_free(self->slot); + G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); +} + +static +void +sample_ims_init( + SampleIms* self) +{ +} + +static +void +sample_ims_class_init( + SampleImsClass* klass) +{ + G_OBJECT_CLASS(klass)->finalize = sample_ims_finalize; + sample_ims_signals[SIGNAL_STATE_CHANGED] = + g_signal_new(SIGNAL_STATE_CHANGED_NAME, G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); +} + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_ims.h b/src/sample_ims.h new file mode 100644 index 0000000..e444c75 --- /dev/null +++ b/src/sample_ims.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef SAMPLE_IMS_H +#define SAMPLE_IMS_H + +#include + +BinderExtIms* +sample_ims_new( + const char* slot) + G_GNUC_INTERNAL; + +#endif /* SAMPLE_IMS_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_plugin.c b/src/sample_plugin.c new file mode 100644 index 0000000..99b20bf --- /dev/null +++ b/src/sample_plugin.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "sample_ext.h" + +#include + +#include +#include + +static +int +sample_plugin_init() +{ + BinderExtPlugin* ext; + + DBG(""); + ext = sample_ext_new(); + binder_ext_plugin_register(ext); + binder_ext_plugin_unref(ext); /* libofonobinderpluginext keeps the ref */ + return 0; +} + +static +void +sample_plugin_exit() +{ + DBG(""); + binder_ext_plugin_unregister(sample_plugin_name); +} + +OFONO_PLUGIN_DEFINE(sample, "Sample binder plugin extension", OFONO_VERSION, + OFONO_PLUGIN_PRIORITY_DEFAULT, sample_plugin_init, sample_plugin_exit) + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_slot.c b/src/sample_slot.c new file mode 100644 index 0000000..6c62d5a --- /dev/null +++ b/src/sample_slot.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "sample_slot.h" +#include "sample_ims.h" + +#include + +#include + +typedef BinderExtSlotClass SampleSlotClass; +typedef struct sample_slot { + BinderExtSlot parent; + BinderExtIms* ims; +} SampleSlot; + +GType sample_slot_get_type() G_GNUC_INTERNAL; +G_DEFINE_TYPE(SampleSlot, sample_slot, BINDER_EXT_TYPE_SLOT) + +#define THIS_TYPE sample_slot_get_type() +#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, SampleSlot) +#define PARENT_CLASS sample_slot_parent_class + +static +void +sample_slot_terminate( + SampleSlot* self) +{ + if (self->ims) { + binder_ext_ims_unref(self->ims); + self->ims = NULL; + } +} + +/*==========================================================================* + * BinderExtSlot + *==========================================================================*/ + +static +gpointer +sample_slot_get_interface( + BinderExtSlot* slot, + GType iface) +{ + SampleSlot* self = THIS(slot); + + if (iface == BINDER_EXT_TYPE_IMS) { + return self->ims; + } else { + return BINDER_EXT_SLOT_CLASS(PARENT_CLASS)->get_interface(slot, iface); + } +} + +static +void +sample_slot_shutdown( + BinderExtSlot* slot) +{ + sample_slot_terminate(THIS(slot)); + BINDER_EXT_SLOT_CLASS(PARENT_CLASS)->shutdown(slot); +} + +/*==========================================================================* + * API + *==========================================================================*/ + +BinderExtSlot* +sample_slot_new( + RadioInstance* radio, + GHashTable* params) +{ + SampleSlot* self = g_object_new(THIS_TYPE, NULL); + BinderExtSlot* slot = &self->parent; + + self->ims = sample_ims_new(radio->slot); + return slot; +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +sample_slot_finalize( + GObject* object) +{ + sample_slot_terminate(THIS(object)); + G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); +} + +static +void +sample_slot_init( + SampleSlot* self) +{ +} + +static +void +sample_slot_class_init( + SampleSlotClass* klass) +{ + klass->get_interface = sample_slot_get_interface; + klass->shutdown = sample_slot_shutdown; + G_OBJECT_CLASS(klass)->finalize = sample_slot_finalize; +} + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/src/sample_slot.h b/src/sample_slot.h new file mode 100644 index 0000000..2703d70 --- /dev/null +++ b/src/sample_slot.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 Jolla Ltd. + * Copyright (C) 2022 Slava Monich + * + * You may use this file under the terms of the 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 + * 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef SAMPLE_SLOT_H +#define SAMPLE_SLOT_H + +#include + +#include + +BinderExtSlot* +sample_slot_new( + RadioInstance* radio, + GHashTable* params) + G_GNUC_INTERNAL; + +#endif /* SAMPLE_SLOT_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */