diff options
author | Vojtech Kral <vojtech@kral.hk> | 2018-06-19 12:16:56 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2018-06-19 19:46:37 +0300 |
commit | 635bb1e484e319b1d403faac39170cc4d0dfa6f7 (patch) | |
tree | d62d33834b85b66e6779b8fc6bcc3fa5b68d8394 /xs/src/avrdude | |
parent | 15f943938b622a3f32bbb8847809acb53782df2a (diff) |
Firmware updater: Add support for l10n firmware images
Diffstat (limited to 'xs/src/avrdude')
-rw-r--r-- | xs/src/avrdude/avrdude-slic3r.cpp | 35 | ||||
-rw-r--r-- | xs/src/avrdude/avrdude-slic3r.hpp | 19 | ||||
-rw-r--r-- | xs/src/avrdude/main.c | 2 |
3 files changed, 35 insertions, 21 deletions
diff --git a/xs/src/avrdude/avrdude-slic3r.cpp b/xs/src/avrdude/avrdude-slic3r.cpp index cf4380fdb..030353413 100644 --- a/xs/src/avrdude/avrdude-slic3r.cpp +++ b/xs/src/avrdude/avrdude-slic3r.cpp @@ -1,5 +1,6 @@ #include "avrdude-slic3r.hpp" +#include <deque> #include <thread> extern "C" { @@ -33,7 +34,8 @@ static void avrdude_progress_handler_closure(const char *task, unsigned progress struct AvrDude::priv { std::string sys_config; - std::vector<std::string> args; + std::deque<std::vector<std::string>> args; + size_t current_args_set = 0; RunFn run_fn; MessageFn message_fn; ProgressFn progress_fn; @@ -41,10 +43,13 @@ struct AvrDude::priv std::thread avrdude_thread; + priv(std::string &&sys_config) : sys_config(sys_config) {} + + int run_one(const std::vector<std::string> &args); int run(); }; -int AvrDude::priv::run() { +int AvrDude::priv::run_one(const std::vector<std::string> &args) { std::vector<char*> c_args {{ const_cast<char*>(PACKAGE_NAME) }}; for (const auto &arg : args) { c_args.push_back(const_cast<char*>(arg.data())); @@ -69,10 +74,22 @@ int AvrDude::priv::run() { return res; } +int AvrDude::priv::run() { + for (; args.size() > 0; current_args_set++) { + int res = run_one(args.front()); + args.pop_front(); + if (res != 0) { + return res; + } + } + + return 0; +} + // Public -AvrDude::AvrDude() : p(new priv()) {} +AvrDude::AvrDude(std::string sys_config) : p(new priv(std::move(sys_config))) {} AvrDude::AvrDude(AvrDude &&other) : p(std::move(other.p)) {} @@ -83,15 +100,9 @@ AvrDude::~AvrDude() } } -AvrDude& AvrDude::sys_config(std::string sys_config) -{ - if (p) { p->sys_config = std::move(sys_config); } - return *this; -} - -AvrDude& AvrDude::args(std::vector<std::string> args) +AvrDude& AvrDude::push_args(std::vector<std::string> args) { - if (p) { p->args = std::move(args); } + if (p) { p->args.push_back(std::move(args)); } return *this; } @@ -137,7 +148,7 @@ AvrDude::Ptr AvrDude::run() auto res = self->p->run(); if (self->p->complete_fn) { - self->p->complete_fn(res); + self->p->complete_fn(res, self->p->current_args_set); } }); diff --git a/xs/src/avrdude/avrdude-slic3r.hpp b/xs/src/avrdude/avrdude-slic3r.hpp index 29d96f72d..273aa2378 100644 --- a/xs/src/avrdude/avrdude-slic3r.hpp +++ b/xs/src/avrdude/avrdude-slic3r.hpp @@ -15,20 +15,20 @@ public: typedef std::function<void()> RunFn; typedef std::function<void(const char * /* msg */, unsigned /* size */)> MessageFn; typedef std::function<void(const char * /* task */, unsigned /* progress */)> ProgressFn; - typedef std::function<void(int /* exit status */)> CompleteFn; + typedef std::function<void(int /* exit status */, size_t /* args_id */)> CompleteFn; - AvrDude(); + // Main c-tor, sys_config is the location of avrdude's main configuration file + AvrDude(std::string sys_config); AvrDude(AvrDude &&); AvrDude(const AvrDude &) = delete; AvrDude &operator=(AvrDude &&) = delete; AvrDude &operator=(const AvrDude &) = delete; ~AvrDude(); - // Set location of avrdude's main configuration file - AvrDude& sys_config(std::string sys_config); - - // Set avrdude cli arguments - AvrDude& args(std::vector<std::string> args); + // Push a set of avrdude cli arguments + // Each set makes one avrdude invocation - use this method multiple times to push + // more than one avrdude invocations. + AvrDude& push_args(std::vector<std::string> args); // Set a callback to be called just after run() before avrdude is ran // This can be used to perform any needed setup tasks from the background thread. @@ -42,7 +42,10 @@ public: // Progress is reported per each task (reading / writing) in percents. AvrDude& on_progress(ProgressFn fn); - // Called when avrdude's main function finishes + // Called when the last avrdude invocation finishes with the exit status of zero, + // or earlier, if one of the invocations return a non-zero status. + // The second argument contains the sequential id of the last avrdude invocation argument set. + // This has no effect when using run_sync(). AvrDude& on_complete(CompleteFn fn); int run_sync(); diff --git a/xs/src/avrdude/main.c b/xs/src/avrdude/main.c index 91f2fc827..d4c34fe44 100644 --- a/xs/src/avrdude/main.c +++ b/xs/src/avrdude/main.c @@ -374,7 +374,7 @@ static void list_parts(FILE * f, const char *prefix, LISTID avrparts) static int cleanup_main(int status) { - if (pgm_setup && pgm->teardown) { + if (pgm_setup && pgm != NULL && pgm->teardown) { pgm->teardown(pgm); } |