aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--debian/control1
-rw-r--r--include/notifications/dbus-shared.h4
-rw-r--r--src/haptic.cpp80
4 files changed, 62 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3bc7e81..9b4987e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,8 +41,7 @@ pkg_check_modules (SERVICE_DEPS REQUIRED
gstreamer-1.0>=1.2
libnotify>=0.7.6
url-dispatcher-1>=1
- properties-cpp>=0.0.1
- ubuntu-platform-api>=2.2.0)
+ properties-cpp>=0.0.1)
include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})
CHECK_INCLUDE_FILE(ubuntu/hardware/alarm.h HAVE_UBUNTU_HW_ALARM_H)
diff --git a/debian/control b/debian/control
index 15b981a..9e7133e 100644
--- a/debian/control
+++ b/debian/control
@@ -24,7 +24,6 @@ Build-Depends: cmake,
libproperties-cpp-dev,
libubuntu-platform-hardware-api-headers [armhf i386 amd64],
libubuntu-platform-hardware-api-dev [armhf i386 amd64],
- libubuntu-application-api-dev [armhf i386 amd64],
libdbustest1-dev,
locales,
Standards-Version: 3.9.3
diff --git a/include/notifications/dbus-shared.h b/include/notifications/dbus-shared.h
index 7738cb7..af714e7 100644
--- a/include/notifications/dbus-shared.h
+++ b/include/notifications/dbus-shared.h
@@ -29,4 +29,8 @@
#define BUS_POWERD_PATH "/com/canonical/powerd"
#define BUS_POWERD_INTERFACE "com.canonical.powerd"
+#define BUS_HAPTIC_NAME "com.canonical.usensord"
+#define BUS_HAPTIC_PATH "/com/canonical/usensord/haptic"
+#define BUS_HAPTIC_INTERFACE "com.canonical.usensord.haptic"
+
#endif /* INDICATOR_NOTIFICATIONS_DBUS_SHARED_H */
diff --git a/src/haptic.cpp b/src/haptic.cpp
index 90c75f7..2b1ee21 100644
--- a/src/haptic.cpp
+++ b/src/haptic.cpp
@@ -17,11 +17,10 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
+#include <notifications/dbus-shared.h>
#include <notifications/haptic.h>
-#include <ubuntu/application/sensors/haptic.h>
-
-#include <glib.h>
+#include <gio/gio.h>
namespace unity {
namespace indicator {
@@ -37,34 +36,58 @@ public:
Impl(const Mode& mode):
m_mode(mode),
- m_sensor(ua_sensors_haptic_new())
+ m_cancellable(g_cancellable_new())
{
- if (m_sensor == nullptr)
- {
- g_warning ("Haptic device unavailable");
- }
- else
- {
- /* We only support one vibrate mode for now: an on/off pulse at
- one-second intervals. So, set a timer to go off every 2 seconds
- that vibrates for one second. */
- ua_sensors_haptic_enable(m_sensor);
- m_tag = g_timeout_add_seconds (2, on_timeout, this);
- on_timeout (this);
- }
+ g_bus_get (G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this);
}
~Impl()
{
- if (m_sensor != nullptr)
- ua_sensors_haptic_disable(m_sensor);
-
if (m_tag)
g_source_remove(m_tag);
+
+ g_cancellable_cancel (m_cancellable);
+ g_object_unref (m_cancellable);
+
+ g_clear_object (&m_bus);
}
private:
+ static void on_bus_ready (GObject*, GAsyncResult* res, gpointer gself)
+ {
+ GError * error;
+ GDBusConnection * bus;
+
+ error = nullptr;
+ bus = g_bus_get_finish (res, &error);
+ if (error != nullptr)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Unable to get bus: %s", error->message);
+
+ g_error_free (error);
+ }
+ else if (bus != nullptr)
+ {
+ auto self = static_cast<Impl*>(gself);
+
+ self->m_bus = G_DBUS_CONNECTION (g_object_ref (bus));
+ self->start_vibrating();
+
+ g_object_unref (bus);
+ }
+ }
+
+ void start_vibrating()
+ {
+ /* We only support one vibrate mode for now: an on/off pulse at
+ one-second intervals. So set a looping 2-second timer that asks
+ the phone to vibrate for one second. */
+ m_tag = g_timeout_add_seconds (2, on_timeout, this);
+ on_timeout (this);
+ }
+
static gboolean on_timeout (gpointer gself)
{
static_cast<Impl*>(gself)->vibrate_now();
@@ -73,12 +96,23 @@ private:
void vibrate_now()
{
- const uint32_t msec = 1000;
- (void) ua_sensors_haptic_vibrate_once (m_sensor, msec);
+ g_dbus_connection_call (m_bus,
+ BUS_HAPTIC_NAME,
+ BUS_HAPTIC_PATH,
+ BUS_HAPTIC_INTERFACE,
+ "Vibrate",
+ g_variant_new("(u)", 1000u),
+ nullptr,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ m_cancellable,
+ nullptr,
+ nullptr);
}
const Mode m_mode;
- UASensorsHaptic * m_sensor = nullptr;
+ GCancellable * m_cancellable = nullptr;
+ GDBusConnection * m_bus = nullptr;
guint m_tag = 0;
};