~thomas-voss/platform-api/add-rotation-vector-sensor

« back to all changes in this revision

Viewing changes to src/ubuntu/application/common/application/sensors/service.cpp

  • Committer: Gerry Boland
  • Date: 2016-01-08 13:46:35 UTC
  • mfrom: (312.3.4 platform-api)
  • Revision ID: gerry.boland@canonical.com-20160108134635-1m1eapeh7pewalkf
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <stdlib.h>
24
24
 
25
 
template<typename T>
26
 
struct Holder
27
 
{
28
 
    Holder(const T&value = T()) : value(value)
29
 
    {
30
 
    }
31
 
 
32
 
    T value;
33
 
};
34
 
 
35
 
template<typename T>
36
 
Holder<T>* make_holder(const T& value)
37
 
{
38
 
    return new Holder<T>(value);
39
 
}
40
 
 
41
25
namespace dbus = core::dbus;
42
26
namespace uas = ubuntu::application::sensors;
43
27
 
50
34
    auto stub_service = dbus::Service::use_service(bus, dbus::traits::Service<uas::USensorD>::interface_name());
51
35
    auto stub = stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/usensord/haptic"));
52
36
 
53
 
    auto holder = make_holder(new UbuntuApplicationSensorsHaptic(stub));
54
 
    holder->value->bus_thread = std::thread{[bus](){ bus->run(); }};
55
 
    holder->value->bus = bus;
56
 
 
57
 
    return make_holder(new UbuntuApplicationSensorsHaptic(stub));
 
37
    auto s = new UbuntuApplicationSensorsHaptic(stub);
 
38
    s->bus_thread = std::thread{[bus](){ bus->run(); }};
 
39
    s->bus = bus;
 
40
 
 
41
    return s;
 
42
}
 
43
 
 
44
void
 
45
ua_sensors_haptic_destroy(UASensorsHaptic* sensor)
 
46
{
 
47
    auto s = static_cast<UbuntuApplicationSensorsHaptic*>(sensor);
 
48
    delete s;
58
49
}
59
50
 
60
51
UStatus
61
52
ua_sensors_haptic_enable(UASensorsHaptic* sensor)
62
53
{
63
 
    auto s = static_cast<Holder<UbuntuApplicationSensorsHaptic*>*>(sensor);
64
 
    s->value->enabled = true;
 
54
    auto s = static_cast<UbuntuApplicationSensorsHaptic*>(sensor);
 
55
    s->enabled = true;
65
56
 
66
57
    return U_STATUS_SUCCESS;
67
58
}
69
60
UStatus
70
61
ua_sensors_haptic_disable(UASensorsHaptic* sensor)
71
62
{
72
 
    auto s = static_cast<Holder<UbuntuApplicationSensorsHaptic*>*>(sensor);
73
 
    s->value->enabled = false;
 
63
    auto s = static_cast<UbuntuApplicationSensorsHaptic*>(sensor);
 
64
    s->enabled = false;
74
65
 
75
66
    return U_STATUS_SUCCESS;
76
67
}
83
74
    if (sensor == nullptr)
84
75
        return U_STATUS_ERROR;
85
76
 
86
 
    auto s = static_cast<Holder<UbuntuApplicationSensorsHaptic*>*>(sensor);
 
77
    auto s = static_cast<UbuntuApplicationSensorsHaptic*>(sensor);
87
78
 
88
 
    if (s->value->enabled == false)
 
79
    if (s->enabled == false)
89
80
        return U_STATUS_ERROR;
90
81
 
91
82
    try
92
83
    {
93
 
        s->value->session->invoke_method_synchronously<uas::USensorD::Haptic::Vibrate, void>(duration);
 
84
        s->session->invoke_method_synchronously<uas::USensorD::Haptic::Vibrate, void>(duration);
94
85
    }
95
86
    catch (const std::runtime_error& e)
96
87
    {
110
101
    if (sensor == nullptr)
111
102
        return U_STATUS_ERROR;
112
103
 
113
 
    auto s = static_cast<Holder<UbuntuApplicationSensorsHaptic*>*>(sensor);
 
104
    auto s = static_cast<UbuntuApplicationSensorsHaptic*>(sensor);
114
105
 
115
 
    if (s->value->enabled == false)
 
106
    if (s->enabled == false)
116
107
        return U_STATUS_ERROR;
117
108
 
118
109
    std::vector<uint32_t> p_arg (pattern, pattern + MAX_PATTERN_SIZE);
119
110
 
120
111
    try
121
112
    {
122
 
        s->value->session->invoke_method_synchronously<uas::USensorD::Haptic::VibratePattern, void>(p_arg, repeat);
 
113
        s->session->invoke_method_synchronously<uas::USensorD::Haptic::VibratePattern, void>(p_arg, repeat);
123
114
    }
124
115
    catch (const std::runtime_error& e)
125
116
    {