/usr/include/ubuntu-location-service-0/com/ubuntu/location/provider.h is in libubuntu-location-service-dev 0.0.2+14.04.20140307-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | /*
* Copyright © 2012-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
#include "com/ubuntu/location/channel.h"
#include "com/ubuntu/location/criteria.h"
#include "com/ubuntu/location/heading.h"
#include "com/ubuntu/location/position.h"
#include "com/ubuntu/location/update.h"
#include "com/ubuntu/location/velocity.h"
#include <atomic>
#include <bitset>
#include <memory>
namespace com
{
namespace ubuntu
{
namespace location
{
class Provider
{
public:
typedef std::shared_ptr<Provider> Ptr;
enum class Feature : std::size_t
{
position,
velocity,
heading
};
typedef std::bitset<3> FeatureFlags;
enum class Requirement : std::size_t
{
satellites,
cell_network,
data_network,
monetary_spending
};
typedef std::bitset<4> RequirementFlags;
class Controller
{
public:
typedef std::shared_ptr<Controller> Ptr;
template<typename T>
class Cache
{
public:
Cache() : d{ T{}, false }
{
}
const T& value() const { return d.value; }
void update(const T& new_value) { d.value = new_value; d.is_valid = true; }
bool is_valid() const { return d.is_valid; }
void invalidate() { d.is_valid = false; }
private:
struct
{
T value;
bool is_valid;
} d;
};
virtual ~Controller() = default;
Controller(const Controller&) = delete;
Controller& operator=(const Controller&) = delete;
virtual void start_position_updates();
virtual void stop_position_updates();
bool are_position_updates_running() const;
virtual void start_heading_updates();
virtual void stop_heading_updates();
bool are_heading_updates_running() const;
virtual void start_velocity_updates();
virtual void stop_velocity_updates();
bool are_velocity_updates_running() const;
const Cache<Update<Position>>& cached_position_update() const;
const Cache<Update<Heading>>& cached_heading_update() const;
const Cache<Update<Velocity>>& cached_velocity_update() const;
protected:
friend class Provider;
explicit Controller(Provider& instance);
private:
void on_position_updated(const Update<Position>& position);
void on_velocity_updated(const Update<Velocity>& velocity);
void on_heading_updated(const Update<Heading>& heading);
Provider& instance;
std::atomic<int> position_updates_counter;
std::atomic<int> heading_updates_counter;
std::atomic<int> velocity_updates_counter;
ScopedChannelConnection position_update_connection;
ScopedChannelConnection velocity_update_connection;
ScopedChannelConnection heading_update_connection;
struct
{
Cache<Update<Position>> position;
Cache<Update<Velocity>> velocity;
Cache<Update<Heading>> heading;
} cached;
};
virtual ~Provider() = default;
Provider(const Provider&) = delete;
Provider& operator=(const Provider&) = delete;
virtual const Controller::Ptr& state_controller() const;
virtual ChannelConnection subscribe_to_position_updates(std::function<void(const Update<Position>&)> f);
virtual ChannelConnection subscribe_to_heading_updates(std::function<void(const Update<Heading>&)> f);
virtual ChannelConnection subscribe_to_velocity_updates(std::function<void(const Update<Velocity>&)> f);
virtual bool supports(const Feature& f) const;
virtual bool requires(const Requirement& r) const;
virtual bool matches_criteria(const Criteria&);
protected:
explicit Provider(
const FeatureFlags& feature_flags = FeatureFlags(),
const RequirementFlags& requirement_flags = RequirementFlags());
void deliver_position_updates(const Update<Position>& update);
void deliver_heading_updates(const Update<Heading>& update);
void deliver_velocity_updates(const Update<Velocity>& update);
virtual void start_position_updates();
virtual void stop_position_updates();
virtual void start_heading_updates();
virtual void stop_heading_updates();
virtual void start_velocity_updates();
virtual void stop_velocity_updates();
private:
FeatureFlags feature_flags;
RequirementFlags requirement_flags;
Channel<Update<Position>> position_updates_channel;
Channel<Update<Heading>> heading_updates_channel;
Channel<Update<Velocity>> velocity_updates_channel;
Controller::Ptr controller;
};
}
}
}
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
|