Welcome to mirror list, hosted at ThFree Co, Russian Federation.

avrdude-slic3r.hpp « avrdude « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 754e1e34592b6ca4396f5ac7537401f38202eb0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef slic3r_avrdude_slic3r_hpp_
#define slic3r_avrdude_slic3r_hpp_

#include <memory>
#include <vector>
#include <string>
#include <functional>

namespace Slic3r {

class AvrDude
{
public:
	enum {
		EXIT_SUCCEESS   = 0,
		EXIT_EXCEPTION  = -1000,
	};

	typedef std::shared_ptr<AvrDude> Ptr;
	typedef std::function<void(Ptr /* avrdude */)> 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()> CompleteFn;

	// 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();

	// 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,
	// and, optionally, to cancel by writing true to the `cancel` argument.
	// This has no effect when using run_sync().
	AvrDude& on_run(RunFn fn);

	// Set message output callback
	AvrDude& on_message(MessageFn fn);

	// Set progress report callback
	// Progress is reported per each task (reading / writing) in percents.
	AvrDude& on_progress(ProgressFn fn);

	// 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);

	// Perform AvrDude invocation(s) synchronously on the current thread
	int run_sync();

	// Perform AvrDude invocation(s) on a background thread.
	// Current instance is moved into a shared_ptr which is returned (and also passed in on_run, if any).
	Ptr run();

	// Cancel current operation
	void cancel();

	// If there is a background thread and it is joinable, join() it,
	// that is, wait for it to finish.
	void join();

	bool cancelled();          // Whether avrdude run was cancelled
	int exit_code();           // The exit code of the last invocation
	size_t last_args_set();    // Index of the last argument set that was processsed
private:
	struct priv;
	std::unique_ptr<priv> p;
};


}

#endif