本文整理汇总了Golang中github.com/google/cups-connector/gcp.GoogleCloudPrint类的典型用法代码示例。如果您正苦于以下问题:Golang GoogleCloudPrint类的具体用法?Golang GoogleCloudPrint怎么用?Golang GoogleCloudPrint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GoogleCloudPrint类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: allGCPPrinters
// allGCPPrinters calls gcp.List, then calls gcp.Printer, one goroutine per
// printer. This is a fast way to fetch all printers with corresponding CDD
// info, which the List API does not provide.
//
// The second return value is a map of GCPID -> queued print job quantity.
func allGCPPrinters(gcp *gcp.GoogleCloudPrint) ([]lib.Printer, map[string]uint, error) {
ids, err := gcp.List()
if err != nil {
return nil, nil, err
}
type response struct {
printer *lib.Printer
queuedJobsCount uint
err error
}
ch := make(chan response)
for id := range ids {
go func(id string) {
printer, queuedJobsCount, err := gcp.Printer(id)
ch <- response{printer, queuedJobsCount, err}
}(id)
}
errs := make([]error, 0)
printers := make([]lib.Printer, 0, len(ids))
queuedJobsCount := make(map[string]uint)
for _ = range ids {
r := <-ch
if r.err != nil {
errs = append(errs, r.err)
continue
}
printers = append(printers, *r.printer)
if r.queuedJobsCount > 0 {
queuedJobsCount[r.printer.GCPID] = r.queuedJobsCount
}
}
if len(errs) == 0 {
return printers, queuedJobsCount, nil
} else if len(errs) == 1 {
return nil, nil, errs[0]
} else {
// Return an error that is somewhat human-readable.
b := bytes.NewBufferString(fmt.Sprintf("%d errors: ", len(errs)))
for i, err := range errs {
if i > 0 {
b.WriteString(", ")
}
b.WriteString(err.Error())
}
return nil, nil, errors.New(b.String())
}
}
开发者ID:nooyoo11,项目名称:cups-connector,代码行数:55,代码来源:printermanager.go
示例2: 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
}
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:80,代码来源:printermanager.go
注:本文中的github.com/google/cups-connector/gcp.GoogleCloudPrint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论