2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
20
#include <biometry/dbus/skeleton/template_store.h>
22
#include <biometry/application.h>
23
#include <biometry/user.h>
24
#include <biometry/dbus/codec.h>
25
#include <biometry/dbus/interface.h>
26
#include <biometry/dbus/skeleton/operation.h>
28
#include <util/atomic_counter.h>
29
#include <util/synchronized.h>
31
#include <boost/format.hpp>
33
biometry::dbus::skeleton::TemplateStore::Ptr biometry::dbus::skeleton::TemplateStore::create_for_service_and_object(
34
const core::dbus::Bus::Ptr& bus,
35
const core::dbus::Service::Ptr& service,
36
const core::dbus::Object::Ptr& object,
37
const std::reference_wrapper<biometry::TemplateStore>& impl)
39
return Ptr{new TemplateStore{bus, service, object, impl}};
42
biometry::Operation<biometry::TemplateStore::SizeQuery>::Ptr biometry::dbus::skeleton::TemplateStore::size(const biometry::Application& app, const biometry::User& user)
44
return impl.get().size(app, user);
47
biometry::Operation<biometry::TemplateStore::Enrollment>::Ptr biometry::dbus::skeleton::TemplateStore::enroll(const biometry::Application& app, const biometry::User& user)
49
return impl.get().enroll(app, user);
52
biometry::Operation<biometry::TemplateStore::Clearance>::Ptr biometry::dbus::skeleton::TemplateStore::clear(const biometry::Application& app, const biometry::User& user)
54
return impl.get().clear(app, user);
57
biometry::dbus::skeleton::TemplateStore::TemplateStore(
58
const core::dbus::Bus::Ptr& bus,
59
const core::dbus::Service::Ptr& service,
60
const core::dbus::Object::Ptr& object,
61
const std::reference_wrapper<biometry::TemplateStore>& impl)
67
object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Size>([this](const core::dbus::Message::Ptr& msg)
69
biometry::User user; biometry::Application app = biometry::Application::system();
70
auto reader = msg->reader(); reader >> app >> user;
71
auto op = size(app, user);
73
core::dbus::types::ObjectPath op_path
75
(boost::format{"%1%/operation/size/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
78
ops.size.synchronized([this, op_path, op](SizeOps::ValueType& ops)
80
ops[op_path] = skeleton::Operation<SizeQuery>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
83
auto reply = core::dbus::Message::make_method_return(msg);
84
reply->writer() << op_path;
85
this->bus->send(reply);
88
object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Enroll>([this](const core::dbus::Message::Ptr& msg)
90
biometry::User user; biometry::Application app = biometry::Application::system();
91
auto reader = msg->reader(); reader >> app >> user;
92
auto op = enroll(app, user);
94
core::dbus::types::ObjectPath op_path
96
(boost::format{"%1%/operation/enroll/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
99
ops.enroll.synchronized([this, op_path, op](EnrollOps::ValueType& ops)
101
ops[op_path] = skeleton::Operation<Enrollment>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
104
auto reply = core::dbus::Message::make_method_return(msg);
105
reply->writer() << op_path;
106
this->bus->send(reply);
109
object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Clear>([this](const core::dbus::Message::Ptr& msg)
111
biometry::User user; biometry::Application app = biometry::Application::system();
112
auto reader = msg->reader(); reader >> app >> user;
113
auto op = clear(app, user);
115
core::dbus::types::ObjectPath op_path
117
(boost::format{"%1%/operation/clear/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
120
ops.clear.synchronized([this, op_path, op](ClearOps::ValueType& ops)
122
ops[op_path] = skeleton::Operation<Clearance>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
125
auto reply = core::dbus::Message::make_method_return(msg);
126
reply->writer() << op_path;
127
this->bus->send(reply);
131
biometry::dbus::skeleton::TemplateStore::~TemplateStore()
133
object->uninstall_method_handler<biometry::dbus::interface::TemplateStore::Methods::Size>();
134
object->uninstall_method_handler<biometry::dbus::interface::TemplateStore::Methods::Enroll>();
135
object->uninstall_method_handler<biometry::dbus::interface::TemplateStore::Methods::Clear>();