PrusaSlicer-NonPlainar/xs/src/avrdude/avrdude-slic3r.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

2018-04-19 08:35:47 +00:00
#include "avrdude-slic3r.hpp"
extern "C" {
#include "ac_cfg.h"
#include "avrdude.h"
}
2018-05-04 14:04:43 +00:00
2018-04-19 08:35:47 +00:00
namespace Slic3r {
namespace AvrDude {
2018-05-04 14:04:43 +00:00
// Used by our custom code in avrdude to receive messages that avrdude normally outputs on stdout (see avrdude_message())
static void avrdude_message_handler_closure(const char *msg, unsigned size, void *user_p)
2018-04-19 08:35:47 +00:00
{
2018-05-04 14:04:43 +00:00
auto *message_fn = reinterpret_cast<MessageFn*>(user_p);
(*message_fn)(msg, size);
2018-04-19 08:35:47 +00:00
}
2018-05-04 14:04:43 +00:00
int main(std::vector<std::string> args, std::string sys_config, MessageFn message_fn)
2018-04-19 08:35:47 +00:00
{
std::vector<char *> c_args {{ const_cast<char*>(PACKAGE_NAME) }};
for (const auto &arg : args) {
c_args.push_back(const_cast<char*>(arg.data()));
}
2018-05-04 14:04:43 +00:00
::avrdude_message_handler_set(avrdude_message_handler_closure, reinterpret_cast<void*>(&message_fn));
2018-04-19 08:35:47 +00:00
const auto res = ::avrdude_main(static_cast<int>(c_args.size()), c_args.data(), sys_config.c_str());
::avrdude_message_handler_set(nullptr, nullptr);
return res;
}
2018-05-04 14:04:43 +00:00
int main(std::vector<std::string> args, std::string sys_config, std::ostream &os)
{
return main(std::move(args), std::move(sys_config), std::move([&os](const char *msg, unsigned /* size */) {
os << msg;
}));
}
2018-05-04 14:06:53 +00:00
2018-04-19 08:35:47 +00:00
}
}