/[rdesktop]/sourceforge.net/trunk/rdesktop/parallel.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/parallel.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 570 by stargo, Wed Jan 21 18:02:38 2004 UTC revision 631 by n-ki, Fri Mar 5 06:48:08 2004 UTC
# Line 4  Line 4 
4    
5  #define IOCTL_PAR_QUERY_RAW_DEVICE_ID   0x0c  #define IOCTL_PAR_QUERY_RAW_DEVICE_ID   0x0c
6    
 #define PARALLELDEV0                    "/dev/lp0"  
   
7  #include "rdesktop.h"  #include "rdesktop.h"
8  #include <unistd.h>  #include <unistd.h>
9  #include <fcntl.h>  #include <fcntl.h>
10    #include <sys/ioctl.h>
11    #include <linux/lp.h>
12    #include <errno.h>
13    
14    extern int errno;
15    
16  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
17    
18  PARALLEL_DEVICE * get_parallel_data(HANDLE handle)  PARALLEL_DEVICE *
19    get_parallel_data(HANDLE handle)
20  {  {
21          int index;          int index;
22    
# Line 30  PARALLEL_DEVICE * get_parallel_data(HAND Line 34  PARALLEL_DEVICE * get_parallel_data(HAND
34  /* optarg looks like ':LPT1=/dev/lp0'            */  /* optarg looks like ':LPT1=/dev/lp0'            */
35  /* when it arrives to this function.             */  /* when it arrives to this function.             */
36  int  int
37  parallel_enum_devices(int *id, char *optarg)  parallel_enum_devices(uint32 * id, char *optarg)
38  {  {
         //TODO: Read from configuration file? CUPS?  
39          PARALLEL_DEVICE *ppar_info;          PARALLEL_DEVICE *ppar_info;
40    
41          char *pos = optarg;          char *pos = optarg;
# Line 57  parallel_enum_devices(int *id, char *opt Line 60  parallel_enum_devices(int *id, char *opt
60                  // set device type                  // set device type
61                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
62                  g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;                  g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;
63                    g_rdpdr_device[*id].handle = 0;
64                  count++;                  count++;
65                  (*id)++;                  (*id)++;
66    
# Line 66  parallel_enum_devices(int *id, char *opt Line 70  parallel_enum_devices(int *id, char *opt
70  }  }
71    
72  static NTSTATUS  static NTSTATUS
73  parallel_create(uint32 device_id, HANDLE * handle)  parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
74                    uint32 flags, char *filename, HANDLE * handle)
75  {  {
76          int parallel_fd;          int parallel_fd;
77    
78          parallel_fd = open(PARALLELDEV0, O_WRONLY);          parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR);
79          if (parallel_fd == -1)          if (parallel_fd == -1)
80            {
81                    perror("open");
82                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
83            }
84    
85            /* all read and writes should be non blocking */
86            if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
87                    perror("fcntl");
88    
89            ioctl(parallel_fd, LPABORT, (int) 1);
90    
91            g_rdpdr_device[device_id].handle = parallel_fd;
92    
93          *handle = parallel_fd;          *handle = parallel_fd;
94    
95          return STATUS_SUCCESS;          return STATUS_SUCCESS;
96  }  }
97    
98  static NTSTATUS  static NTSTATUS
99  parallel_close(HANDLE handle)  parallel_close(HANDLE handle)
100  {  {
101            int i = get_device_index(handle);
102            if (i >= 0)
103                    g_rdpdr_device[i].handle = 0;
104          close(handle);          close(handle);
105          return STATUS_SUCCESS;          return STATUS_SUCCESS;
106  }  }
107    
108    NTSTATUS
109    parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
110    {
111            *result = read(handle, data, length);
112            return STATUS_SUCCESS;
113    }
114    
115  static NTSTATUS  static NTSTATUS
116  parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)  parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
117  {  {
118          *result = write(handle, data, length);          int rc = STATUS_SUCCESS;
119          return STATUS_SUCCESS;  
120            int n = write(handle, data, length);
121            if (n < 0)
122            {
123                    int status;
124    
125                    *result = 0;
126                    switch (errno)
127                    {
128                            case EAGAIN:
129                                    rc = STATUS_DEVICE_OFF_LINE;
130                            case ENOSPC:
131                                    rc = STATUS_DEVICE_PAPER_EMPTY;
132                            case EIO:
133                                    rc = STATUS_DEVICE_OFF_LINE;
134                            default:
135                                    rc = STATUS_DEVICE_POWERED_OFF;
136                    }
137                    if (ioctl(handle, LPGETSTATUS, &status) == 0)
138                    {
139                            /* coming soon: take care for the printer status */
140                            printf("parallel_write: status = %d, errno = %d\n", status, errno);
141                    }
142            }
143            *result = n;
144            return rc;
145  }  }
146    
147  static NTSTATUS  static NTSTATUS
# Line 119  parallel_device_control(HANDLE handle, u Line 171  parallel_device_control(HANDLE handle, u
171  DEVICE_FNS parallel_fns = {  DEVICE_FNS parallel_fns = {
172          parallel_create,          parallel_create,
173          parallel_close,          parallel_close,
174          NULL,          parallel_read,
175          parallel_write,          parallel_write,
176          parallel_device_control          parallel_device_control
177  };  };

Legend:
Removed from v.570  
changed lines
  Added in v.631

  ViewVC Help
Powered by ViewVC 1.1.26