Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/cmd/usb/print/print.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 * usb/print - usb printer file server
3
 * BUG: Assumes the printer will be always connected and
4
 * not hot-plugged. (Otherwise should stay running and
5
 * listen to errors to keep the device there as long as it has
6
 * not failed). Also, this is untested and done ad-hoc to
7
 * replace the print script.
8
 */
9
#include <u.h>
10
#include <libc.h>
11
#include <thread.h>
12
#include "usb.h"
13
 
14
enum
15
{
16
	Qdir = 0,
17
	Qctl,
18
	Qraw,
19
	Qdata,
20
	Qmax,
21
};
22
 
23
int
24
findendpoints(Dev *dev, int devid)
25
{
26
	Ep *ep;
27
	Dev *d;
28
	Usbdev *ud;
29
	int i, epout;
30
 
31
	epout = -1;
32
	ud = dev->usb;
33
	for(i = 0; i < nelem(ud->ep); i++){
34
		if((ep = ud->ep[i]) == nil)
35
			break;
36
		if(ep->iface->csp != 0x020107)
37
			continue;
38
		if(ep->type == Ebulk && (ep->dir == Eboth || ep->dir == Eout))
39
			if(epout == -1)
40
				epout = ep->id;
41
	}
42
	dprint(2, "print: ep ids: out %d\n", epout);
43
	if(epout == -1)
44
		return -1;
45
	d = openep(dev, epout);
46
	if(d == nil){
47
		fprint(2, "print: openep %d: %r\n", epout);
48
		return -1;
49
	}
50
	opendevdata(d, OWRITE);
51
	if(d->dfd < 0){
52
		fprint(2, "print: open i/o ep data: %r\n");
53
		closedev(d);
54
		return -1;
55
	}
56
	dprint(2, "print: ep out %s\n", d->dir);
57
	if(usbdebug > 1)
58
		devctl(d, "debug 1");
59
	devctl(d, "name lp%d", devid);
60
	return 0;
61
}
62
 
63
static int
64
usage(void)
65
{
66
	werrstr("usage: usb/print [-N id]");
67
	return -1;
68
}
69
 
70
int
71
printmain(Dev *dev, int argc, char **argv)
72
{
73
	int devid;
74
 
75
	devid = dev->id;
76
	ARGBEGIN{
77
	case 'N':
78
		devid = atoi(EARGF(usage()));
79
		break;
80
	default:
81
		return usage();
82
	}ARGEND
83
	if(argc != 0)
84
		return usage();
85
 
86
	if(findendpoints(dev, devid) < 0){
87
		werrstr("print: endpoints not found");
88
		return -1;
89
	}
90
	return 0;
91
}