|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * simple printer object test.
26: */
27:
28: #import <Printer/printer.h>
29: #import <remote/NXConnection.h>
30: #import <remote/NXProxy.h>
31: #import <objc/error.h>
32: #import <sys/printf.h>
33:
34: static void usage(char **argv)
35: {
36: printf("usage: %s action [n=printername] [l(oop)]\n", argv[0]);
37: printf("action:\n");
38: printf(" p power on\n");
39: printf(" P power off\n");
40: printf(" s get status\n");
41: exit(1);
42: }
43:
44: int main(int argc, char **argv)
45: {
46: id printer;
47: char *printername = "np0";
48: char action;
49: IOReturn rtn;
50: npStatus status;
51: int arg;
52: int loop = 0;
53:
54: if(argc < 2) {
55: usage(argv);
56: }
57: for(arg=2; arg<argc; arg++) {
58: switch(argv[arg][0]) {
59: case 'n':
60: printername = &argv[arg][2];
61: break;
62: case 'l':
63: loop = 1;
64: break;
65: default:
66: usage(argv);
67: }
68: }
69: action = argv[1][0];
70: NX_DURING {
71: printer = [NXConnection connectToName:printername];
72: } NX_HANDLER {
73: printf("connectToName raised %d\n", NXLocalHandler.code);
74: NX_VALRETURN(1);
75: } NX_ENDHANDLER;
76:
77: if(printer == nil) {
78: printf("connectToName returned nil\n");
79: exit(1);
80: }
81:
82: /*
83: * Set a long timeout for printer's (an NXProxy) NXConnection.
84: * FIXME - isn't there a more straightforward was of doing this?
85: */
86: [[printer connectionForProxy] setInTimeout:0x7fffffff];
87: [[printer connectionForProxy] setOutTimeout:0x7fffffff];
88:
89: NX_DURING {
90: do {
91: switch(action) {
92: case 'p':
93: rtn = [printer powerOn];
94: break;
95: case 'P':
96: rtn = [printer powerOff];
97: break;
98: case 's':
99: rtn = [printer getStatus:&status];
100: if(rtn == IO_R_SUCCESS) {
101: printf("status.flags = 0x%x\n",
102: status.flags);
103: printf("status.retrans = %d\n",
104: status.retrans);
105: }
106: break;
107:
108: default:
109: usage(argv);
110: }
111: } while ((rtn == IO_R_SUCCESS) && loop);
112: } NX_HANDLER {
113: printf("I/O raised %d\n", NXLocalHandler.code);
114: NX_VALRETURN(1);
115: } NX_ENDHANDLER;
116:
117: if(rtn) {
118: printf("...cmd returned %d\n", rtn);
119: exit(1);
120: }
121: else {
122: printf("...complete\n");
123: }
124: exit(0);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.