emulator_fuzz: Add test plugin
authorDenis Kenzior <denkenz@gmail.com>
Sat, 1 Feb 2014 15:05:10 +0000 (09:05 -0600)
committerDenis Kenzior <denkenz@gmail.com>
Mon, 20 Oct 2014 18:40:28 +0000 (13:40 -0500)
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.

Makefile.am
plugins/emulator_fuzz.c [new file with mode: 0644]

index 42b2136..fdf26b6 100644 (file)
@@ -493,6 +493,9 @@ builtin_sources += examples/private-network.c
 
 builtin_modules += stktest
 builtin_sources += plugins/stktest.c
+
+builtin_modules += emulator_fuzz
+builtin_sources += plugins/emulator_fuzz.c
 endif
 
 builtin_modules += smart_messaging
diff --git a/plugins/emulator_fuzz.c b/plugins/emulator_fuzz.c
new file mode 100644 (file)
index 0000000..9863de8
--- /dev/null
@@ -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)