24 #include "hardware/GPIO_odb.h" 40 return std::make_unique<HardwareSearch>(ctx);
49 ASSERT_LOG(!c1->id().is_nil(),
"c1 has no id.");
50 ASSERT_LOG(!c2->id().is_nil(),
"c2 has no id.");
51 return c1->id() < c2->id();
57 json rep = json::array();
59 odb::transaction t(db->begin());
60 using Query = odb::query<Hardware::Device>;
61 std::string partial_name = req.at(
"partial_name");
62 std::set<Hardware::DevicePtr, HardwareComparator> hardware_devices;
69 for (
auto i = 0u; i < partial_name.length(); ++i)
71 auto partial_name_copy = partial_name;
72 partial_name_copy[i] = std::toupper(partial_name[i]);
73 Query q(Query::name.like(
"%" + partial_name_copy +
"%"));
74 auto results = db->query(q);
75 for (
const auto &device : results)
83 Query q(Query::name.like(
"%" + partial_name +
"%"));
84 auto results = db->query(q);
85 for (
const auto &dev : results)
92 auto hardware_service =
94 ASSERT_LOG(hardware_service,
"Failed to retrieve hardware service");
95 for (
const auto &dev : hardware_devices)
98 json result_json = {{
"id", dev->id()},
99 {
"name", dev->name()},
100 {
"device-class", dev->device_class()},
101 {
"type", hardware_service->hardware_device_type(*dev)}};
102 rep.push_back(result_json);
108 std::vector<ActionActionParam>
111 std::vector<ActionActionParam> perm_;
HardwareSearch(RequestContext ctx)
The base class for API method handler implementation.
This is the header file for a generated source file, GitSHA1.cpp.
static MethodHandlerUPtr create(RequestContext)
ServiceRegistry & get_service_registry()
A function to retrieve the ServiceRegistry from pretty much anywhere.
std::unique_ptr< MethodHandler > MethodHandlerUPtr
Base class for hardware devices.
odb::query< Tools::LogEntry > Query
Database aware Hardware Service.
All modules that provides features to Leosac shall be in this namespace.
bool operator()(const Hardware::DevicePtr &c1, const Hardware::DevicePtr &c2)
#define ASSERT_LOG(cond, msg)
std::vector< ActionActionParam > required_permission(const json &req) const override
Return a list of "Action" / "ActionParam" that must pass before the request is processed.
std::shared_ptr< ServiceInterface > get_service() const
Retrieve the service instance implementing the ServiceInterface, or nullptr if no such service was re...
virtual json process_impl(const json &req) override
The API method implementation.
std::shared_ptr< Device > DevicePtr
Holds valuable pointer to provide context to a request.
std::shared_ptr< odb::database > DBPtr