本文整理汇总了Golang中github.com/google/cups-connector/gcp.GoogleCloudPrint.ListPrinters方法的典型用法代码示例。如果您正苦于以下问题:Golang GoogleCloudPrint.ListPrinters方法的具体用法?Golang GoogleCloudPrint.ListPrinters怎么用?Golang GoogleCloudPrint.ListPrinters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/cups-connector/gcp.GoogleCloudPrint
的用法示例。
在下文中一共展示了GoogleCloudPrint.ListPrinters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewPrinterManager
func NewPrinterManager(cups *cups.CUPS, gcp *gcp.GoogleCloudPrint, privet *privet.Privet, snmp *snmp.SNMPManager, printerPollInterval string, cupsQueueSize uint, jobFullUsername, ignoreRawPrinters bool, shareScope string, jobs <-chan *lib.Job, xmppNotifications <-chan xmpp.PrinterNotification) (*PrinterManager, error) {
var printers *lib.ConcurrentPrinterMap
var queuedJobsCount map[string]uint
var err error
if gcp != nil {
// Get all GCP printers.
var gcpPrinters []lib.Printer
gcpPrinters, queuedJobsCount, err = gcp.ListPrinters()
if err != nil {
return nil, err
}
// Organize the GCP printers into a map.
for i := range gcpPrinters {
gcpPrinters[i].CUPSJobSemaphore = lib.NewSemaphore(cupsQueueSize)
}
printers = lib.NewConcurrentPrinterMap(gcpPrinters)
} else {
printers = lib.NewConcurrentPrinterMap(nil)
}
// Construct.
pm := PrinterManager{
cups: cups,
gcp: gcp,
privet: privet,
snmp: snmp,
printers: printers,
jobStatsMutex: sync.Mutex{},
jobsDone: 0,
jobsError: 0,
jobsInFlightMutex: sync.Mutex{},
jobsInFlight: make(map[string]struct{}),
cupsQueueSize: cupsQueueSize,
jobFullUsername: jobFullUsername,
ignoreRawPrinters: ignoreRawPrinters,
shareScope: shareScope,
quit: make(chan struct{}),
}
// Sync once before returning, to make sure things are working.
// Ignore privet updates this first time because Privet always starts
// with zero printers.
if err = pm.syncPrinters(true); err != nil {
return nil, err
}
// Initialize Privet printers.
if privet != nil {
for _, printer := range pm.printers.GetAll() {
err := privet.AddPrinter(printer, pm.printers.GetByCUPSName)
if err != nil {
glog.Warningf("Failed to register %s locally: %s", printer.Name, err)
} else {
glog.Infof("Registered %s locally", printer.Name)
}
}
}
ppi, err := time.ParseDuration(printerPollInterval)
if err != nil {
return nil, err
}
pm.syncPrintersPeriodically(ppi)
pm.listenNotifications(jobs, xmppNotifications)
if gcp != nil {
for gcpPrinterID := range queuedJobsCount {
p, _ := printers.GetByGCPID(gcpPrinterID)
go gcp.HandleJobs(&p, func() { pm.incrementJobsProcessed(false) })
}
}
return &pm, nil
}