xref: /haiku/headers/libs/print/libprint/Transport.h (revision 08d759feae5967ad75d0f0d4ee33c21c72ae6db8)
1 /*
2  * Transport.h
3  * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4  */
5 
6 #ifndef __TRANSPORT_H
7 #define __TRANSPORT_H
8 
9 #include <image.h>
10 #include <string>
11 
12 class BDataIO;
13 class PrinterData;
14 
15 
16 using namespace std;
17 
18 
19 extern "C" {
20 	typedef BDataIO *(*PFN_init_transport)(BMessage *);
21 	typedef void (*PFN_exit_transport)(void);
22 }
23 
24 class TransportException {
25 private:
26 	string fWhat;
27 public:
28 	TransportException(const string &what_arg) : fWhat(what_arg) {}
29 	const char *what() const { return fWhat.c_str(); }
30 };
31 
32 class Transport {
33 public:
34 	Transport(const PrinterData *printer_data);
35 	~Transport();
36 	void write(const void *buffer, size_t size) throw(TransportException);
37 	bool check_abort() const;
38 	bool is_print_to_file_canceled() const;
39 	const string &last_error() const;
40 
41 protected:
42 	void set_last_error(const char *e);
43 	Transport(const Transport &);
44 	Transport &operator = (const Transport &);
45 
46 private:
47 	image_id           fImage;
48 	PFN_init_transport fInitTransport;
49 	PFN_exit_transport fExitTransport;
50 	BDataIO            *fDataStream;
51 	bool               fAbort;
52 	string             fLastErrorString;
53 };
54 
55 #endif	// __TRANSPORT_H
56