Skip to content

Commit

Permalink
append orphan to provide a fallback when family device is unknown fro…
Browse files Browse the repository at this point in the history
…m cxx lib
  • Loading branch information
Rodriguez committed Oct 13, 2023
1 parent 5615c3f commit d8f8098
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_sources(${LIBRARY_NAME}
pza/utils/topic.cxx

pza/devices/bps.cxx
pza/devices/orphan.cxx

pza/interfaces/meter.cxx
pza/interfaces/bps_chan_ctrl.cxx
Expand Down
8 changes: 4 additions & 4 deletions source/pza/core/device.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ int device::_set_identity(const std::string &payload)
// Convert to lowercase
std::transform(family.begin(), family.end(), family.begin(), ::tolower);

if (family != get_family()) {
spdlog::error("Device is not compatible {} != {}", family, get_family());
return -1;
}
// if (family != get_family()) {
// spdlog::error("Device is not compatible {} != {}", family, get_family());
// return -1;
// }

return 0;
}
Expand Down
7 changes: 6 additions & 1 deletion source/pza/core/device_factory.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "device_factory.hxx"

#include <pza/devices/bps.hxx>
#include <pza/devices/orphan.hxx>


using namespace pza;

std::map<std::string, device_factory::factory_function> device_factory::_factory_map = {
Expand All @@ -11,7 +15,8 @@ device::ptr device_factory::create_device(const std::string &family, const std::
auto it = _factory_map.find(family);
if (it == _factory_map.end()) {
spdlog::error("Unknown device type {}", family);
return nullptr;

return device_factory::allocate_device<orphan>(group, name);
}

return it->second(group, name);
Expand Down
1 change: 0 additions & 1 deletion source/pza/core/device_factory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <magic_enum.hpp>

#include <pza/core/device.hxx>
#include <pza/devices/bps.hxx>

namespace pza
{
Expand Down
25 changes: 25 additions & 0 deletions source/pza/devices/orphan.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "orphan.hxx"

using namespace pza;

orphan::orphan(const std::string &group, const std::string &name)
: device(group, name)
{

}

int orphan::_register_interfaces(const std::map<std::string, std::string> &map)
{
// int ret;

// ret = grouped_interface::register_interfaces<bps_channel>(this, "channel", map, channel);
// if (ret < 0)
// return ret;

// for (auto &chan : channel) {
// register_interface(chan->voltmeter);
// register_interface(chan->ampermeter);
// register_interface(chan->ctrl);
// }
return 0;
}
28 changes: 28 additions & 0 deletions source/pza/devices/orphan.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <pza/core/device.hxx>
#include <pza/core/grouped_interface.hxx>


#include <pza/utils/string.hxx>

namespace pza
{

class orphan : public device
{
public:
using ptr = std::shared_ptr<orphan>;

explicit orphan(const std::string &group, const std::string &name);

const std::string &get_family() override { return _family; };
// size_t get_num_channels() { return channel.size(); }
// std::vector<bps_channel::ptr> channel;

private:
int _register_interfaces(const std::map<std::string, std::string> &map) override;

std::string _family = "orphan";
};
};

0 comments on commit d8f8098

Please sign in to comment.