~thomas-voss/biometryd/remove-obsolete-configuration-header

« back to all changes in this revision

Viewing changes to src/biometry/dbus/skeleton/template_store.cpp

  • Committer: Thomas Voß
  • Date: 2016-05-02 06:16:01 UTC
  • Revision ID: thomas.voss@canonical.com-20160502061601-vqzwfw4c0rxfna04
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
17
 *
 
18
 */
 
19
 
 
20
#include <biometry/dbus/skeleton/template_store.h>
 
21
 
 
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>
 
27
 
 
28
#include <util/atomic_counter.h>
 
29
#include <util/synchronized.h>
 
30
 
 
31
#include <boost/format.hpp>
 
32
 
 
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)
 
38
{
 
39
    return Ptr{new TemplateStore{bus, service, object, impl}};
 
40
}
 
41
 
 
42
biometry::Operation<biometry::TemplateStore::SizeQuery>::Ptr biometry::dbus::skeleton::TemplateStore::size(const biometry::Application& app, const biometry::User& user)
 
43
{
 
44
    return impl.get().size(app, user);
 
45
}
 
46
 
 
47
biometry::Operation<biometry::TemplateStore::Enrollment>::Ptr biometry::dbus::skeleton::TemplateStore::enroll(const biometry::Application& app, const biometry::User& user)
 
48
{
 
49
    return impl.get().enroll(app, user);
 
50
}
 
51
 
 
52
biometry::Operation<biometry::TemplateStore::Clearance>::Ptr biometry::dbus::skeleton::TemplateStore::clear(const biometry::Application& app, const biometry::User& user)
 
53
{
 
54
    return impl.get().clear(app, user);
 
55
}
 
56
 
 
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)
 
62
    : impl{impl},
 
63
      bus{bus},
 
64
      service{service},
 
65
      object{object}
 
66
{
 
67
    object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Size>([this](const core::dbus::Message::Ptr& msg)
 
68
    {
 
69
        biometry::User user; biometry::Application app = biometry::Application::system();
 
70
        auto reader = msg->reader(); reader >> app >> user;
 
71
        auto op = size(app, user);
 
72
 
 
73
        core::dbus::types::ObjectPath op_path
 
74
        {
 
75
            (boost::format{"%1%/operation/size/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
 
76
        };
 
77
 
 
78
        ops.size.synchronized([this, op_path, op](SizeOps::ValueType& ops)
 
79
        {
 
80
            ops[op_path] = skeleton::Operation<SizeQuery>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
 
81
        });
 
82
 
 
83
        auto reply = core::dbus::Message::make_method_return(msg);
 
84
        reply->writer() << op_path;
 
85
        this->bus->send(reply);
 
86
    });
 
87
 
 
88
    object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Enroll>([this](const core::dbus::Message::Ptr& msg)
 
89
    {
 
90
        biometry::User user; biometry::Application app = biometry::Application::system();
 
91
        auto reader = msg->reader(); reader >> app >> user;
 
92
        auto op = enroll(app, user);
 
93
 
 
94
        core::dbus::types::ObjectPath op_path
 
95
        {
 
96
            (boost::format{"%1%/operation/enroll/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
 
97
        };
 
98
 
 
99
        ops.enroll.synchronized([this, op_path, op](EnrollOps::ValueType& ops)
 
100
        {
 
101
            ops[op_path] = skeleton::Operation<Enrollment>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
 
102
        });
 
103
 
 
104
        auto reply = core::dbus::Message::make_method_return(msg);
 
105
        reply->writer() << op_path;
 
106
        this->bus->send(reply);
 
107
    });
 
108
 
 
109
    object->install_method_handler<biometry::dbus::interface::TemplateStore::Methods::Clear>([this](const core::dbus::Message::Ptr& msg)
 
110
    {
 
111
        biometry::User user; biometry::Application app = biometry::Application::system();
 
112
        auto reader = msg->reader(); reader >> app >> user;
 
113
        auto op = clear(app, user);
 
114
 
 
115
        core::dbus::types::ObjectPath op_path
 
116
        {
 
117
            (boost::format{"%1%/operation/clear/%2%"} % this->object->path().as_string() % util::counter<TemplateStore>().increment()).str()
 
118
        };
 
119
 
 
120
        ops.clear.synchronized([this, op_path, op](ClearOps::ValueType& ops)
 
121
        {
 
122
            ops[op_path] = skeleton::Operation<Clearance>::create_for_object(this->bus, this->service->add_object_for_path(op_path), op);
 
123
        });
 
124
 
 
125
        auto reply = core::dbus::Message::make_method_return(msg);
 
126
        reply->writer() << op_path;
 
127
        this->bus->send(reply);
 
128
    });
 
129
}
 
130
 
 
131
biometry::dbus::skeleton::TemplateStore::~TemplateStore()
 
132
{
 
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>();
 
136
}