Leosac  0.8.0
Open Source Access Control
PFGPIO.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 
22 #include "tools/JSONUtils.hpp"
23 #include "tools/log.hpp"
24 
25 namespace Leosac
26 {
27 namespace Module
28 {
29 namespace Piface
30 {
31 
33  : hardware_address_(0)
34 {
35 }
36 
38 {
39  auto serialized = Hardware::GPIOSerializer::serialize(in, sc);
40  // Now we override the type.
41  ASSERT_LOG(serialized.at("type").is_string(),
42  "Base GPIO serialization did something unexpected.");
43  serialized["type"] = "piface-digital-gpio";
44 
45  serialized["attributes"]["hardware-address"] = in.hardware_address();
46  return serialized;
47 }
48 
50  const SecurityContext &sc)
51 {
52  using namespace JSONUtil;
54 
55  out.hardware_address(
56  extract_with_default(in, "hardware-address", out.hardware_address()));
57 }
58 }
59 }
60 }
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::Module::Piface::PFGPIO::hardware_address
uint8_t hardware_address() const
Definition: PFGPIO.hpp:49
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
GPIOSerializer.hpp
Leosac::Module::Piface::PFGPIO
Piface Module GPIO descriptor.
Definition: PFGPIO.hpp:44
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Hardware::GPIOSerializer::serialize
static json serialize(const Hardware::GPIO &in, const SecurityContext &sc)
Definition: GPIOSerializer.cpp:30
Leosac::Module::Piface::PFGPIOSerializer::serialize
static json serialize(const PFGPIO &in, const SecurityContext &sc)
Definition: PFGPIO.cpp:37
JSONUtils.hpp
log.hpp
Leosac::Hardware::GPIOSerializer::unserialize
static void unserialize(Hardware::GPIO &out, const json &in, const SecurityContext &sc)
Definition: GPIOSerializer.cpp:47
PFGPIO.hpp
Leosac::Module::Piface::json
nlohmann::json json
Definition: PFGPIO.hpp:36
Leosac::Module::Piface::PFGPIO::PFGPIO
PFGPIO()
Definition: PFGPIO.cpp:32
Leosac::Module::Piface::PFGPIOSerializer::unserialize
static void unserialize(PFGPIO &out, const json &in, const SecurityContext &sc)
Definition: PFGPIO.cpp:49
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40