Esempio n. 1
0
int do_printer_reset(int dev_path)
{
	int error;
#ifdef SOFT_RESET
	char *buf;
	char reset_com[] = {0x1b,0x5b,0x4b,0x04,0x00,0x00,0x0f,0x00,0x00};
	char ret_emu[] = {0x1b,0x40};
#else
	if(device_type == DEVICE_TYPE_USB || device_type == DEVICE_TYPE_1394)
		return 0;
#endif

	get_printer_sem(sem_id);

#ifdef SOFT_RESET
	if(device_type == DEVICE_TYPE_USB || device_type == DEVICE_TYPE_1394){
		buf = malloc(RESET_NULL_SIZE);
		if(buf == NULL){
			/* no RAM error */
			release_printer_sem(sem_id);
			return -1;
		}
		memset((void *)buf, 0, RESET_NULL_SIZE);
		error = write_printer_command(dev_path, buf, RESET_NULL_SIZE);
		if(!error)
			error = write_printer_command(dev_path, reset_com, 9);
		if(!error)
			error = write_printer_command(dev_path, ret_emu, 2);

		free(buf);
	}
	else
#endif
		error = p_dvacs->ptdev_ioctl(dev_path, LPRESET, 0);

	release_printer_sem(sem_id);

	return error;
}
Esempio n. 2
0
static unsigned int data_output_main(int sm_sock_fd, int fix_size)
{
	int sig = 0;
	int r_size;
	int w_size;
	int dev_path = PRNT_PATH;
	unsigned int total = 0; /* total data size (wrote size) */
	char *buf;
	char *ptr;

	/* read buffer get */
	buf = (char *)malloc(MAX_DATA);
	if(!buf)
		exit(0); /* no ram */

	/* print data read(from stdin) and write(to stdout) */
	while((r_size = read_data(buf)) > 0){
		ptr = buf;
		/* data print(output) loop */
		for(;r_size > 0;r_size -= w_size){
			int __attribute__ ((unused)) err;

			signal_block(sigmask);   /* signal block */
			get_printer_sem(sem_id); /* printer lock */

			w_size = p_dvacs->ptdev_write(dev_path, ptr, r_size); /* data write -> printer */
			err = errno;
#ifdef DATA_LOG
                        if(log_hand >=0 && w_size > 0)
                                write(log_hand, ptr, w_size);
#endif

			/* write() error check (power off??) */
			if(w_size <= 0){
				w_size = 0;
				if(check_power(sm_sock_fd, dev_path) == LM_PRN_POWOFF){
#ifdef DEBUG
					write_log("LM(P) into wait_restart()\n");
#endif
					release_printer_sem(sem_id);
					signal_unblock(sigmask);

					/* wait BSCC SUCCESS */
					if(wait_restart() == DETECT_END)
						goto dataout_exit;
					else
						continue;
				}
#ifdef DEBUG
				fprintf(log_path, "LM(P) write error. normal=%x\n",err);
				fflush(log_path);
#endif
				sleep(1);
			}
			else
				total += w_size; /* total write size save */

			/* write() is normal end */
			release_printer_sem(sem_id);
			signal_unblock(sigmask);

			if((sig = check_signals()) != 0){
			/* signal detect */
				if(signal_end(sig)){
					goto dataout_exit; /* SIGTERM */
					}

					/* other signal ignore */
					start_signal = 0;
					last_signal  = 0;
			}
			ptr += w_size;
		}

		/* written data size == request data size ?*/
		if(fix_size && (total >= fix_size) )
			break;
	}
dataout_exit:
	free(buf);

	return total;
}
Esempio n. 3
0
static int lm_main_lpr(int sm_sock_fd)
{
	int error = 0;
	int prn_end = 0;
	lmsm_socket sm_data;
	int first_start = 0;

#ifdef DEBUG
	write_log("into lm_main_lpr\n");
#endif

	sleep(1); /* wait child process setup */

	/*
	  LM<->SM socket read loop start.
	  signal-infomation
		SIGTERM ---- program end.
		SIGUSR1 ---- print data end.
		SIGUSR2 ---- status monitor show request.
		SIGINT  ---- program end.
	*/
	while(!prn_end){
		/* socket read */
		error = read(sm_sock_fd, &sm_data, sizeof(sm_data));

		prn_end = check_signal_arrive();

		if(error < 0)
			continue; /* socket read error */

		switch(sm_data.command){
			case LM_PRN_COM:
				/* output printer command */
				get_printer_sem(sem_id);     /* lock printer */
				prn_end = do_prn_com(sm_sock_fd, sm_data, first_start);
				release_printer_sem(sem_id); /* release printer */
#ifdef DEBUG
				write_log("PRN command SUCCESS\n");
#endif
				break;
			case LM_PRN_CANCEL:
				prn_end = do_prn_cancel();
				break;
			case LM_PRN_START:
#ifdef DEBUG
				write_log("SM message LM_PRN_START\n");
#endif
				if(first_start != 0)
					break;

				/* printing start!! */
				kill(data_pid, SIGUSR2); /* message to data_output_process */
				first_start = 1; /* next START is ignore */
				break;
			case LM_PRN_END:
#ifdef DEBUG
				write_log("SM message LM_PRN_END\n");
#endif
				/* end of all job's */
				/* print end(last page ejected from printer) */
				do_cancel = 1;
				prn_end = 1;
				break;
			default:
				break;
		}
	}

	/* print end */

	/* child process end */
	if(data_pid)
		kill(data_pid, SIGTERM);
	if(stat_pid)
		kill(stat_pid, SIGTERM);
	if(stmon_pid)
		kill(stmon_pid, SIGTERM);

	return 0;
}
Esempio n. 4
0
int lm_init(int dev_path)
{
	int error;
	struct stat st;

	/* printer access semapho create */
	error = create_sem(&sem_id);
	if(error)
		return error;

        fstat(dev_path, &st);
        device_type = (st.st_rdev&0x00ff00)>>8;

	switch(device_type){
	case DEVICE_TYPE_LP:
#ifdef DEBUG
		write_log("device type LP\n");
#endif
		/* parport setup */
		p_dvacs->ptdev_read  = read_lp_p;
		p_dvacs->ptdev_write = write_lp_p;
		p_dvacs->ptdev_ioctl = ioctl_lp_p;
		p_dvacs->ptdev_poll  = poll_lp_p;

		get_printer_sem(sem_id);
		/* error abort select */
		p_dvacs->ptdev_ioctl(dev_path, LPABORT, 1);
		/* Non Blocking I/O select */
		fcntl(dev_path, F_SETFL, fcntl(dev_path, F_GETFL, 0) | O_NONBLOCK);
		release_printer_sem(sem_id);
		break;
	case DEVICE_TYPE_USB:
#ifdef DEBUG
		write_log("device type USB\n");
#endif
		/* usb setup */
		p_dvacs->ptdev_read  = read_usb_p;
		p_dvacs->ptdev_write = write_usb_p;
		p_dvacs->ptdev_ioctl = ioctl_usb_p;
		p_dvacs->ptdev_poll  = poll_usb_p;
		break;
	case DEVICE_TYPE_1394:
#ifdef DEBUG
		write_log("device type 1394\n");
#endif
		/* ieee1394 setup */
		p_dvacs->ptdev_read  = read_1394_p;
		p_dvacs->ptdev_write = write_1394_p;
		p_dvacs->ptdev_ioctl = ioctl_1394_p;
		p_dvacs->ptdev_poll  = poll_1394_p;
		break;
	default:
#ifdef DEBUG
		write_log("device type unknown(default use)\n");
#endif
		/* default device = lp */
		p_dvacs->ptdev_read  = read_lp_p;
		p_dvacs->ptdev_write = write_lp_p;
		p_dvacs->ptdev_ioctl = ioctl_lp_p;
		p_dvacs->ptdev_poll  = poll_lp_p;
		break;
	}

	return 0;
}