コード例 #1
0
// translateAttrs extracts a PrinterDescriptionSection, PrinterStateSection, name, default diplay name, UUID, and tags from maps of tags (CUPS attributes)
func translateAttrs(printerTags map[string][]string) (*cdd.PrinterDescriptionSection, *cdd.PrinterStateSection, string, string, string, map[string]string) {
	var name, info string
	if n, ok := printerTags[attrPrinterName]; ok && len(n) > 0 {
		name = n[0]
	}
	if i, ok := printerTags[attrPrinterInfo]; ok && len(i) > 0 {
		info = i[0]
	}
	uuid := getUUID(printerTags)

	var desc = cdd.PrinterDescriptionSection{VendorCapability: &[]cdd.VendorCapability{}}
	var state cdd.PrinterStateSection

	desc.SupportedContentType = convertSupportedContentType(printerTags)
	desc.Marker, state.MarkerState = convertMarkers(printerTags)
	desc.PageOrientation = convertPageOrientation(printerTags)
	desc.Copies = convertCopies(printerTags)
	desc.Color = convertColorAttrs(printerTags)
	if vc := convertPagesPerSheet(printerTags); vc != nil {
		*desc.VendorCapability = append(*desc.VendorCapability, *vc)
	}

	state.State = getState(printerTags)
	state.VendorState = getVendorState(printerTags)

	tags := make(map[string]string, len(printerTags))
	for k, v := range printerTags {
		tags[k] = strings.Join(v, ",")
	}

	return &desc, &state, name, info, uuid, tags
}
コード例 #2
0
func convertPrinterState(wsStatus uint32, wsAttributes uint32) *cdd.PrinterStateSection {
	state := cdd.PrinterStateSection{
		State:       cdd.CloudDeviceStateIdle,
		VendorState: &cdd.VendorState{},
	}

	if wsStatus&(PRINTER_STATUS_PRINTING|PRINTER_STATUS_PROCESSING) != 0 {
		state.State = cdd.CloudDeviceStateProcessing
	}

	if wsStatus&PRINTER_STATUS_PAUSED != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateWarning,
			DescriptionLocalized: cdd.NewLocalizedString("printer paused"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_ERROR != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("printer error"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_PENDING_DELETION != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("printer is being deleted"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_PAPER_JAM != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("paper jam"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_PAPER_OUT != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("paper out"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_MANUAL_FEED != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("manual feed mode"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_PAPER_PROBLEM != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("paper problem"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}

	// If PRINTER_ATTRIBUTE_WORK_OFFLINE is set
	// spooler won't despool any jobs to the printer.
	// At least for some USB printers, this flag is controlled
	// automatically by the system depending on the state of physical connection.
	if wsStatus&PRINTER_STATUS_OFFLINE != 0 || wsAttributes&PRINTER_ATTRIBUTE_WORK_OFFLINE != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("printer is offline"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_IO_ACTIVE != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("active I/O state"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_BUSY != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("busy"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_OUTPUT_BIN_FULL != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("output bin is full"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_NOT_AVAILABLE != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("printer not available"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_WAITING != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("waiting"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_INITIALIZING != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("intitializing"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_WARMING_UP != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("warming up"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_TONER_LOW != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateWarning,
			DescriptionLocalized: cdd.NewLocalizedString("toner low"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_NO_TONER != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("no toner"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_PAGE_PUNT != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("cannot print the current page"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_USER_INTERVENTION != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("user intervention required"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_OUT_OF_MEMORY != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("out of memory"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_DOOR_OPEN != 0 {
		state.State = cdd.CloudDeviceStateStopped
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("door open"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_SERVER_UNKNOWN != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateError,
			DescriptionLocalized: cdd.NewLocalizedString("printer status unknown"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}
	if wsStatus&PRINTER_STATUS_POWER_SAVE != 0 {
		vs := cdd.VendorStateItem{
			State:                cdd.VendorStateInfo,
			DescriptionLocalized: cdd.NewLocalizedString("power save mode"),
		}
		state.VendorState.Item = append(state.VendorState.Item, vs)
	}

	if len(state.VendorState.Item) == 0 {
		state.VendorState = nil
	}

	return &state
}