Esempio n. 1
0
func main() {
	flag.Parse()
	timer := time.NewTicker(2 * time.Second)
	timer_two := time.NewTicker(5 * time.Second)

	fmt.Println(C.GoString(C.cupsUser()))

	fmt.Println(C.GoString(C.cupsGetDefault()))

	var options *C.cups_option_t

	num_options := C.int(0)

	num_options = C.cupsAddOption(C.CString("PageSize"), C.CString("Postcard"), C.int(num_options), &options)
	num_options = C.cupsAddOption(C.CString("MediaSize"), C.CString("A4"), C.int(num_options), &options)
	num_options = C.cupsAddOption(C.CString("MediaSize1"), C.CString("A5"), C.int(num_options), &options)

	dest := C.CString("Test")
	file := C.CString("/Users/ZhouYT/Downloads/follow.png")
	title := C.CString("Test Print")

	job_id, err := C.cupsPrintFile(dest, file, title, num_options, options)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(job_id)

	defer C.cupsFreeOptions(num_options, options)

	fmt.Println(C.GoString(options.name))

	for {
		select {
		case <-timer.C:

			go func() {
				fmt.Println("test2")
				glog.Info("test")
			}()

		case <-timer_two.C:

			go func() {
				fmt.Println("test5")
				glog.Info("test5")
			}()
		}
	}

	defer glog.Flush()
}
Esempio n. 2
0
// Print sends a new print job to the specified printer. The job ID
// is returned.
func (c *CUPS) Print(printername, filename, title, user string, ticket cdd.CloudJobTicket) (uint32, error) {
	pn := C.CString(printername)
	defer C.free(unsafe.Pointer(pn))
	fn := C.CString(filename)
	defer C.free(unsafe.Pointer(fn))
	t := C.CString(title)
	defer C.free(unsafe.Pointer(t))

	options := ticketToOptions(ticket)
	numOptions := C.int(0)
	var o *C.cups_option_t = nil
	for key, value := range options {
		k, v := C.CString(key), C.CString(value)
		numOptions = C.cupsAddOption(k, v, numOptions, &o)
		C.free(unsafe.Pointer(k))
		C.free(unsafe.Pointer(v))
	}
	defer C.cupsFreeOptions(numOptions, o)

	u := C.CString(user)
	defer C.free(unsafe.Pointer(u))

	jobID, err := c.cc.printFile(u, pn, fn, t, numOptions, o)
	if err != nil {
		return 0, err
	}

	return uint32(jobID), nil
}
Esempio n. 3
0
// Print sends a new print job to the specified printer. The job ID
// is returned.
func (c *CUPS) Print(printer *lib.Printer, filename, title, user, gcpJobID string, ticket *cdd.CloudJobTicket) (uint32, error) {
	printer.CUPSJobSemaphore.Acquire()
	defer printer.CUPSJobSemaphore.Release()

	pn := C.CString(printer.Name)
	defer C.free(unsafe.Pointer(pn))
	fn := C.CString(filename)
	defer C.free(unsafe.Pointer(fn))
	var t *C.char

	if c.prefixJobIDToJobTitle {
		title = fmt.Sprintf("gcp:%s %s", gcpJobID, title)
	}
	if len(title) > 255 {
		t = C.CString(title[:255])
	} else {
		t = C.CString(title)
	}
	defer C.free(unsafe.Pointer(t))

	options, err := translateTicket(printer, ticket)
	if err != nil {
		return 0, err
	}
	numOptions := C.int(0)
	var o *C.cups_option_t = nil
	for key, value := range options {
		k, v := C.CString(key), C.CString(value)
		numOptions = C.cupsAddOption(k, v, numOptions, &o)
		C.free(unsafe.Pointer(k))
		C.free(unsafe.Pointer(v))
	}
	defer C.cupsFreeOptions(numOptions, o)

	u := C.CString(user)
	defer C.free(unsafe.Pointer(u))

	cupsJobID, err := c.cc.printFile(u, pn, fn, t, numOptions, o)
	if err != nil {
		return 0, err
	}

	return uint32(cupsJobID), nil
}