~charlesk/platform-api/lp-1216473

« back to all changes in this revision

Viewing changes to src/ubuntu/application/location/session.cpp

  • Committer: Tarmac
  • Author(s): Thomas Voß, thomas-voss
  • Date: 2013-08-22 16:29:26 UTC
  • mfrom: (118.2.7 location-service)
  • Revision ID: tarmac-20130822162926-0rrcoj4962tri7mx
Reimplement location submodule on top of location-service.

Approved by Ricardo Salveti, PS Jenkins bot, Michael Frey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "ubuntu/application/location/session.h"
20
20
 
 
21
#include "session_p.h"
 
22
 
 
23
#include "heading_update_p.h"
 
24
#include "position_update_p.h"
 
25
#include "velocity_update_p.h"
 
26
 
21
27
void
22
28
ua_location_service_session_ref(
23
29
    UALocationServiceSession *session)
24
30
{
25
 
    (void) session;
 
31
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
32
    s->ref();
26
33
}
27
34
 
28
35
void
29
36
ua_location_service_session_unref(
30
37
    UALocationServiceSession *session)
31
38
{
32
 
    (void) session;
 
39
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
40
    s->unref();
33
41
}
34
42
 
35
43
void
38
46
    UALocationServiceSessionPositionUpdatesHandler handler,
39
47
    void *context)
40
48
{
41
 
    (void) session;
42
 
    (void) handler;
43
 
    (void) context;
 
49
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
50
    s->session->install_position_updates_handler(
 
51
        [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Position>& new_position)
 
52
        {
 
53
            UbuntuApplicationLocationPositionUpdate pu{new_position};
 
54
            handler(std::addressof(pu), context);
 
55
        });
44
56
}
45
57
 
46
58
void
49
61
    UALocationServiceSessionHeadingUpdatesHandler handler,
50
62
    void *context)
51
63
{
52
 
    (void) session;
53
 
    (void) handler;
54
 
    (void) context;
 
64
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
65
    s->session->install_heading_updates_handler(
 
66
        [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Heading>& new_heading) 
 
67
        {
 
68
            UbuntuApplicationLocationHeadingUpdate hu{new_heading};
 
69
            handler(std::addressof(hu), context);
 
70
        });
55
71
}
56
72
 
57
73
void
60
76
    UALocationServiceSessionVelocityUpdatesHandler handler,
61
77
    void *context)
62
78
{
63
 
    (void) session;
64
 
    (void) handler;
65
 
    (void) context;
 
79
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
80
    s->session->install_velocity_updates_handler(
 
81
        [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& new_velocity) 
 
82
        {
 
83
            UbuntuApplicationLocationVelocityUpdate vu{new_velocity};
 
84
            handler(std::addressof(vu), context);
 
85
        });
66
86
}
67
87
 
68
88
UStatus
69
89
ua_location_service_session_start_position_updates(
70
90
    UALocationServiceSession *session)
71
91
{
72
 
    (void) session;
73
 
    return U_STATUS_ERROR;
 
92
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
93
    if (!s)
 
94
        return U_STATUS_ERROR;
 
95
 
 
96
    try
 
97
    {
 
98
        s->session->start_position_updates();
 
99
    } catch(...)
 
100
    {
 
101
        return U_STATUS_ERROR;
 
102
    }
 
103
    
 
104
    return U_STATUS_SUCCESS;
74
105
}
75
106
 
76
107
void
77
108
ua_location_service_session_stop_position_updates(
78
109
    UALocationServiceSession *session)
79
110
{
80
 
    (void) session;
 
111
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
112
    if (!s)
 
113
        return;
 
114
 
 
115
    try
 
116
    {
 
117
        s->session->stop_position_updates();
 
118
    } catch(...)
 
119
    {
 
120
    }    
81
121
}
82
122
 
83
123
UStatus
84
124
ua_location_service_session_start_heading_updates(
85
125
    UALocationServiceSession *session)
86
126
{
87
 
    (void) session;
88
 
    return U_STATUS_ERROR;
 
127
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
128
    if (!s)
 
129
        return U_STATUS_ERROR;
 
130
 
 
131
    try
 
132
    {
 
133
        s->session->start_heading_updates();
 
134
    } catch(...)
 
135
    {
 
136
        return U_STATUS_ERROR;
 
137
    }
 
138
    
 
139
    return U_STATUS_SUCCESS;
89
140
}
90
141
 
91
142
void
92
143
ua_location_service_session_stop_heading_updates(
93
144
    UALocationServiceSession *session)
94
145
{
95
 
    (void) session;
 
146
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
147
    if (!s)
 
148
        return;
 
149
 
 
150
    try
 
151
    {
 
152
        s->session->stop_heading_updates();
 
153
    } catch(...)
 
154
    {
 
155
    }
96
156
}
97
157
 
98
158
UStatus
99
159
ua_location_service_session_start_velocity_updates(
100
160
    UALocationServiceSession *session)
101
161
{
102
 
    (void) session;
103
 
    return U_STATUS_ERROR;
 
162
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
163
    if (!s)
 
164
        return U_STATUS_ERROR;
 
165
 
 
166
    try
 
167
    {
 
168
        s->session->start_velocity_updates();
 
169
    } catch(...)
 
170
    {
 
171
        return U_STATUS_ERROR;
 
172
    }
 
173
    
 
174
    return U_STATUS_SUCCESS;
104
175
}
105
176
 
106
177
void
107
178
ua_location_service_session_stop_velocity_updates(
108
179
    UALocationServiceSession *session)
109
180
{
110
 
    (void) session;
 
181
    auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
 
182
    if (!s)
 
183
        return;
 
184
 
 
185
    try
 
186
    {
 
187
        s->session->stop_velocity_updates();
 
188
    } catch(...)
 
189
    {
 
190
    }
111
191
}