Leosac  0.8.0
Open Source Access Control
DeviceSerializer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2017 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
22 #include "tools/JSONUtils.hpp"
23 
24 namespace Leosac
25 {
26 namespace Hardware
27 {
29 {
30  json serialized = {{"id", in.id()},
31  {"type", "device"},
32  {"attributes",
33  {{"name", in.name()},
34  {"device-class", in.device_class()},
35  {"enabled", in.enabled()}}}};
36 
37  return serialized;
38 }
39 
41  const SecurityContext &)
42 {
43  using namespace JSONUtil;
44 
45  out.name(extract_with_default(in, "name", out.name()));
46  out.enabled(extract_with_default(in, "enabled", out.enabled()));
47 }
48 }
49 }
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
Leosac::JSONUtil::extract_with_default
std::chrono::system_clock::time_point extract_with_default(const nlohmann::json &obj, const std::string &key, const std::chrono::system_clock::time_point &tp)
Extract an ISO 8601 datetime string from a json object.
Definition: JSONUtils.cpp:45
Leosac::Hardware::Device
Base class for hardware devices.
Definition: Device.hpp:44
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Hardware::Device::id
UUID id() const
Definition: Device.cpp:49
Leosac::Hardware::Device::device_class
DeviceClass device_class() const
Definition: Device.cpp:65
JSONUtils.hpp
Leosac::Hardware::Device::name
const std::string & name() const
Definition: Device.cpp:55
Leosac::Hardware::Device::enabled
bool enabled() const
Definition: Device.cpp:75
Leosac::Hardware::DeviceSerializer::serialize
static json serialize(const Hardware::Device &in, const SecurityContext &sc)
Definition: DeviceSerializer.cpp:28
Leosac::Hardware::DeviceSerializer::unserialize
static void unserialize(Hardware::Device &out, const json &in, const SecurityContext &sc)
Definition: DeviceSerializer.cpp:40
DeviceSerializer.hpp
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40