summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2014-02-01 09:05:10 -0600
committerDenis Kenzior <denkenz@gmail.com>2014-10-20 13:40:28 -0500
commitcf90f1505d5b6a9cacc0e010cf57c300d472894e (patch)
tree5f200d9e65d4fc6d3b314022d98cf850638bb2d8 /plugins
parentf9d5ee5fa9d0fffbe588eaac6771804a3d297674 (diff)
downloadofono-cf90f1505d5b6a9cacc0e010cf57c300d472894e.tar.bz2
emulator_fuzz: Add test plugin
This plugin creates an org.ofono.test.EmulatorFuzz interface on path /test. Currently only one method is implemented, SetIndicatorActive. SetIndicatorActive("DistractedDrivingReduction", True|False) allows to activate / deactivate the HF indicator via +BIND unsolicited notification.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/emulator_fuzz.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/plugins/emulator_fuzz.c b/plugins/emulator_fuzz.c
new file mode 100644
index 00000000..9863de8d
--- /dev/null
+++ b/plugins/emulator_fuzz.c
@@ -0,0 +1,126 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <sys/socket.h>
+#include <glib.h>
+#include <ofono.h>
+#include <gdbus.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/emulator.h>
+
+#include "hfp.h"
+
+#define EMULATOR_FUZZ_INTERFACE "org.ofono.test.EmulatorFuzz"
+#define EMULATOR_FUZZ_PATH "/test"
+
+static void emulator_set_indicator(struct ofono_atom *atom, void *data)
+{
+ struct ofono_emulator *em = __ofono_atom_get_data(atom);
+ ofono_bool_t active = GPOINTER_TO_INT(data);
+
+ ofono_emulator_set_hf_indicator_active(em,
+ HFP_HF_INDICATOR_ENHANCED_SAFETY, active);
+}
+
+static void modem_set_indicators(struct ofono_modem *modem, void *user)
+{
+ __ofono_modem_foreach_registered_atom(modem,
+ OFONO_ATOM_TYPE_EMULATOR_HFP,
+ emulator_set_indicator,
+ user);
+}
+
+static DBusMessage *set_indicator_active(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ const char *indicator;
+ dbus_bool_t active;
+
+ DBG("");
+
+ if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &indicator,
+ DBUS_TYPE_BOOLEAN, &active,
+ DBUS_TYPE_INVALID) == FALSE)
+ goto invalid;
+
+ DBG("%s,%d", indicator, active);
+
+ if (strcmp(indicator, "DistractedDrivingReduction"))
+ goto invalid;
+
+ __ofono_modem_foreach(modem_set_indicators, GINT_TO_POINTER(active));
+
+ return dbus_message_new_method_return(msg);
+
+invalid:
+ return g_dbus_create_error(msg, "org.ofono.test.Error",
+ "Invalid arguments in method call");
+}
+
+static const GDBusMethodTable emulator_fuzz_methods[] = {
+ { GDBUS_ASYNC_METHOD("SetIndicatorActive",
+ GDBUS_ARGS({ "indicator", "s" }, { "active", "b" }),
+ NULL, set_indicator_active) },
+ { },
+};
+
+static int emulator_fuzz_init(void)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ DBG("");
+
+ if (!g_dbus_register_interface(conn, EMULATOR_FUZZ_PATH,
+ EMULATOR_FUZZ_INTERFACE,
+ emulator_fuzz_methods, NULL,
+ NULL, NULL, NULL)) {
+ ofono_error("Register Profile interface failed: %s",
+ EMULATOR_FUZZ_PATH);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static void emulator_fuzz_exit(void)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ DBG("");
+
+ g_dbus_unregister_interface(conn, EMULATOR_FUZZ_PATH,
+ EMULATOR_FUZZ_INTERFACE);
+}
+
+OFONO_PLUGIN_DEFINE(emulator_fuzz, "Emulator Fuzz",
+ VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+ emulator_fuzz_init, emulator_fuzz_exit)