1 #ifndef slic3r_PrintHost_hpp_
2 #define slic3r_PrintHost_hpp_
3 
4 #include <memory>
5 #include <string>
6 #include <functional>
7 #include <boost/filesystem/path.hpp>
8 
9 #include <wx/string.h>
10 
11 #include "Http.hpp"
12 
13 class wxArrayString;
14 
15 namespace Slic3r {
16 
17 class DynamicPrintConfig;
18 
19 
20 struct PrintHostUpload
21 {
22     boost::filesystem::path source_path;
23     boost::filesystem::path upload_path;
24 
25     std::string group;
26 
27     bool start_print = false;
28 };
29 
30 
31 class PrintHost
32 {
33 public:
34     virtual ~PrintHost();
35 
36     typedef Http::ProgressFn ProgressFn;
37     typedef std::function<void(wxString /* error */)> ErrorFn;
38 
39     virtual const char* get_name() const = 0;
40 
41     virtual bool test(wxString &curl_msg) const = 0;
42     virtual wxString get_test_ok_msg () const = 0;
43     virtual wxString get_test_failed_msg (wxString &msg) const = 0;
44     virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const = 0;
45     virtual bool has_auto_discovery() const = 0;
46     virtual bool can_test() const = 0;
47     virtual bool can_start_print() const = 0;
48     // A print host usually does not support multiple printers, with the exception of Repetier server.
supports_multiple_printers() const49     virtual bool supports_multiple_printers() const { return false; }
50     virtual std::string get_host() const = 0;
51 
52     // Support for Repetier server multiple groups & printers. Not supported by other print hosts.
53     // Returns false if not supported. May throw HostNetworkError.
get_groups(wxArrayString &) const54     virtual bool get_groups(wxArrayString & /* groups */) const { return false; }
get_printers(wxArrayString &) const55     virtual bool get_printers(wxArrayString & /* printers */) const { return false; }
56 
57     static PrintHost* get_print_host(DynamicPrintConfig *config);
58 
59 protected:
60     virtual wxString format_error(const std::string &body, const std::string &error, unsigned status) const;
61 };
62 
63 
64 struct PrintHostJob
65 {
66     PrintHostUpload upload_data;
67     std::unique_ptr<PrintHost> printhost;
68     bool cancelled = false;
69 
PrintHostJobSlic3r::PrintHostJob70     PrintHostJob() {}
71     PrintHostJob(const PrintHostJob&) = delete;
PrintHostJobSlic3r::PrintHostJob72     PrintHostJob(PrintHostJob &&other)
73         : upload_data(std::move(other.upload_data))
74         , printhost(std::move(other.printhost))
75         , cancelled(other.cancelled)
76     {}
77 
PrintHostJobSlic3r::PrintHostJob78     PrintHostJob(DynamicPrintConfig *config)
79         : printhost(PrintHost::get_print_host(config))
80     {}
81 
82     PrintHostJob& operator=(const PrintHostJob&) = delete;
operator =Slic3r::PrintHostJob83     PrintHostJob& operator=(PrintHostJob &&other)
84     {
85         upload_data = std::move(other.upload_data);
86         printhost = std::move(other.printhost);
87         cancelled = other.cancelled;
88         return *this;
89     }
90 
emptySlic3r::PrintHostJob91     bool empty() const { return !printhost; }
operator boolSlic3r::PrintHostJob92     operator bool() const { return !!printhost; }
93 };
94 
95 
96 namespace GUI { class PrintHostQueueDialog; }
97 
98 class PrintHostJobQueue
99 {
100 public:
101     PrintHostJobQueue(GUI::PrintHostQueueDialog *queue_dialog);
102     PrintHostJobQueue(const PrintHostJobQueue &) = delete;
103     PrintHostJobQueue(PrintHostJobQueue &&other) = delete;
104     ~PrintHostJobQueue();
105 
106     PrintHostJobQueue& operator=(const PrintHostJobQueue &) = delete;
107     PrintHostJobQueue& operator=(PrintHostJobQueue &&other) = delete;
108 
109     void enqueue(PrintHostJob job);
110     void cancel(size_t id);
111 
112 private:
113     struct priv;
114     std::shared_ptr<priv> p;
115 };
116 
117 
118 
119 }
120 
121 #endif
122