本文整理汇总了Golang中github.com/google/cups-connector/privet.Privet类的典型用法代码示例。如果您正苦于以下问题:Golang Privet类的具体用法?Golang Privet怎么用?Golang Privet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Privet类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: connector
//.........这里部分代码省略.........
g, err = gcp.NewGoogleCloudPrint(config.GCPBaseURL, config.RobotRefreshToken,
config.UserRefreshToken, config.ProxyName, config.GCPOAuthClientID,
config.GCPOAuthClientSecret, config.GCPOAuthAuthURL, config.GCPOAuthTokenURL,
config.GCPMaxConcurrentDownloads, jobs)
if err != nil {
log.Error(err)
return 1
}
x, err = xmpp.NewXMPP(config.XMPPJID, config.ProxyName, config.XMPPServer, config.XMPPPort,
xmppPingTimeout, xmppPingInterval, g.GetRobotAccessToken, xmppNotifications)
if err != nil {
log.Error(err)
return 1
}
defer x.Quit()
}
cupsConnectTimeout, err := time.ParseDuration(config.CUPSConnectTimeout)
if err != nil {
log.Fatalf("Failed to parse CUPS connect timeout: %s", err)
return 1
}
c, err := cups.NewCUPS(config.CopyPrinterInfoToDisplayName, config.PrefixJobIDToJobTitle,
config.DisplayNamePrefix, config.CUPSPrinterAttributes, config.CUPSMaxConnections,
cupsConnectTimeout)
if err != nil {
log.Fatal(err)
return 1
}
defer c.Quit()
var s *snmp.SNMPManager
if config.SNMPEnable {
log.Info("SNMP enabled")
s, err = snmp.NewSNMPManager(config.SNMPCommunity, config.SNMPMaxConnections)
if err != nil {
log.Error(err)
return 1
}
defer s.Quit()
}
var priv *privet.Privet
if config.LocalPrintingEnable {
if g == nil {
priv, err = privet.NewPrivet(jobs, config.GCPBaseURL, nil)
} else {
priv, err = privet.NewPrivet(jobs, config.GCPBaseURL, g.ProximityToken)
}
if err != nil {
log.Error(err)
return 1
}
defer priv.Quit()
}
cupsPrinterPollInterval, err := time.ParseDuration(config.CUPSPrinterPollInterval)
if err != nil {
log.Fatalf("Failed to parse CUPS printer poll interval: %s", err)
return 1
}
pm, err := manager.NewPrinterManager(c, g, priv, s, cupsPrinterPollInterval,
config.CUPSJobQueueSize, config.CUPSJobFullUsername, config.CUPSIgnoreRawPrinters,
config.ShareScope, jobs, xmppNotifications)
if err != nil {
log.Error(err)
return 1
}
defer pm.Quit()
m, err := monitor.NewMonitor(c, g, priv, pm, config.MonitorSocketFilename)
if err != nil {
log.Error(err)
return 1
}
defer m.Quit()
if config.CloudPrintingEnable {
if config.LocalPrintingEnable {
log.Errorf("Ready to rock as proxy '%s' and in local mode", config.ProxyName)
fmt.Printf("Ready to rock as proxy '%s' and in local mode\n", config.ProxyName)
} else {
log.Errorf("Ready to rock as proxy '%s'", config.ProxyName)
fmt.Printf("Ready to rock as proxy '%s'\n", config.ProxyName)
}
} else {
log.Error("Ready to rock in local-only mode")
fmt.Println("Ready to rock in local-only mode")
}
waitIndefinitely()
log.Error("Shutting down")
fmt.Println("")
fmt.Println("Shutting down")
return 0
}
开发者ID:jacobmarble,项目名称:cc-deb-pkg,代码行数:101,代码来源:gcp-cups-connector.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
示例3: main
func main() {
flag.Parse()
defer glog.Flush()
glog.Error(lib.FullName)
fmt.Println(lib.FullName)
config, err := lib.ConfigFromFile()
if err != nil {
glog.Fatal(err)
}
if _, err := os.Stat(config.MonitorSocketFilename); !os.IsNotExist(err) {
if err != nil {
glog.Fatal(err)
}
glog.Fatalf(
"A connector is already running, or the monitoring socket %s wasn't cleaned up properly",
config.MonitorSocketFilename)
}
cupsConnectTimeout, err := time.ParseDuration(config.CUPSConnectTimeout)
if err != nil {
glog.Fatalf("Failed to parse cups connect timeout: %s", err)
}
gcpXMPPPingTimeout, err := time.ParseDuration(config.XMPPPingTimeout)
if err != nil {
glog.Fatalf("Failed to parse xmpp ping timeout: %s", err)
}
gcpXMPPPingIntervalDefault, err := time.ParseDuration(config.XMPPPingIntervalDefault)
if err != nil {
glog.Fatalf("Failed to parse xmpp ping interval default: %s", err)
}
gcp, err := gcp.NewGoogleCloudPrint(config.GCPBaseURL, config.RobotRefreshToken, config.UserRefreshToken,
config.ProxyName, config.GCPOAuthClientID, config.GCPOAuthClientSecret,
config.GCPOAuthAuthURL, config.GCPOAuthTokenURL, gcpXMPPPingIntervalDefault)
if err != nil {
glog.Fatal(err)
}
xmpp, err := xmpp.NewXMPP(config.XMPPJID, config.ProxyName, config.XMPPServer, config.XMPPPort, gcpXMPPPingTimeout, gcpXMPPPingIntervalDefault, gcp.GetRobotAccessToken)
if err != nil {
glog.Fatal(err)
}
defer xmpp.Quit()
createTempFile := cups.CreateTempFile
cups, err := cups.NewCUPS(config.CopyPrinterInfoToDisplayName, config.CUPSPrinterAttributes,
config.CUPSMaxConnections, cupsConnectTimeout, gcp.Translate)
if err != nil {
glog.Fatal(err)
}
defer cups.Quit()
var snmpManager *snmp.SNMPManager
if config.SNMPEnable {
glog.Info("SNMP enabled")
snmpManager, err = snmp.NewSNMPManager(config.SNMPCommunity, config.SNMPMaxConnections)
if err != nil {
glog.Fatal(err)
}
defer snmpManager.Quit()
}
var priv *privet.Privet
if config.LocalPrintingEnable {
priv, err = privet.NewPrivet(config.GCPBaseURL, gcp.ProximityToken, createTempFile)
if err != nil {
glog.Fatal(err)
}
defer priv.Quit()
}
pm, err := manager.NewPrinterManager(cups, gcp, xmpp, priv, snmpManager, config.CUPSPrinterPollInterval,
config.GCPMaxConcurrentDownloads, config.CUPSJobQueueSize, config.CUPSJobFullUsername,
config.CUPSIgnoreRawPrinters, config.ShareScope)
if err != nil {
glog.Fatal(err)
}
defer pm.Quit()
m, err := monitor.NewMonitor(cups, gcp, pm, config.MonitorSocketFilename)
if err != nil {
glog.Fatal(err)
}
defer m.Quit()
glog.Errorf("Ready to rock as proxy '%s'\n", config.ProxyName)
fmt.Printf("Ready to rock as proxy '%s'\n", config.ProxyName)
waitIndefinitely()
glog.Error("Shutting down")
fmt.Println("")
fmt.Println("Shutting down")
}
开发者ID:rufil75,项目名称:cups-connector,代码行数:98,代码来源:connector.go
示例4: main
func main() {
flag.Parse()
defer glog.Flush()
glog.Error(lib.FullName)
fmt.Println(lib.FullName)
var config *lib.Config
if lib.ConfigFileExists() {
var err error
config, err = lib.ConfigFromFile()
if err != nil {
glog.Fatal(err)
}
} else {
config = &lib.DefaultConfig
glog.Info("No config file was found, so using defaults")
}
if !config.CloudPrintingEnable && !config.LocalPrintingEnable {
glog.Fatal("Cannot run connector with both local_printing_enable and cloud_printing_enable set to false")
}
if _, err := os.Stat(config.MonitorSocketFilename); !os.IsNotExist(err) {
if err != nil {
glog.Fatal(err)
}
glog.Fatalf(
"A connector is already running, or the monitoring socket %s wasn't cleaned up properly",
config.MonitorSocketFilename)
}
cupsConnectTimeout, err := time.ParseDuration(config.CUPSConnectTimeout)
if err != nil {
glog.Fatalf("Failed to parse cups connect timeout: %s", err)
}
gcpXMPPPingTimeout, err := time.ParseDuration(config.XMPPPingTimeout)
if err != nil {
glog.Fatalf("Failed to parse xmpp ping timeout: %s", err)
}
gcpXMPPPingIntervalDefault, err := time.ParseDuration(config.XMPPPingIntervalDefault)
if err != nil {
glog.Fatalf("Failed to parse xmpp ping interval default: %s", err)
}
jobs := make(chan *lib.Job, 10)
xmppNotifications := make(chan xmpp.PrinterNotification, 5)
var g *gcp.GoogleCloudPrint
var x *xmpp.XMPP
if config.CloudPrintingEnable {
g, err = gcp.NewGoogleCloudPrint(config.GCPBaseURL, config.RobotRefreshToken,
config.UserRefreshToken, config.ProxyName, config.GCPOAuthClientID,
config.GCPOAuthClientSecret, config.GCPOAuthAuthURL, config.GCPOAuthTokenURL,
gcpXMPPPingIntervalDefault, config.GCPMaxConcurrentDownloads, jobs)
if err != nil {
glog.Fatal(err)
}
x, err = xmpp.NewXMPP(config.XMPPJID, config.ProxyName, config.XMPPServer, config.XMPPPort,
gcpXMPPPingTimeout, gcpXMPPPingIntervalDefault, g.GetRobotAccessToken, xmppNotifications)
if err != nil {
glog.Fatal(err)
}
defer x.Quit()
}
c, err := cups.NewCUPS(config.CopyPrinterInfoToDisplayName, config.CUPSPrinterAttributes,
config.CUPSMaxConnections, cupsConnectTimeout)
if err != nil {
glog.Fatal(err)
}
defer c.Quit()
var s *snmp.SNMPManager
if config.SNMPEnable {
glog.Info("SNMP enabled")
s, err = snmp.NewSNMPManager(config.SNMPCommunity, config.SNMPMaxConnections)
if err != nil {
glog.Fatal(err)
}
defer s.Quit()
}
var priv *privet.Privet
if config.LocalPrintingEnable {
if g == nil {
priv, err = privet.NewPrivet(jobs, config.GCPBaseURL, nil)
} else {
priv, err = privet.NewPrivet(jobs, config.GCPBaseURL, g.ProximityToken)
}
if err != nil {
glog.Fatal(err)
}
defer priv.Quit()
}
pm, err := manager.NewPrinterManager(c, g, priv, s, config.CUPSPrinterPollInterval,
config.CUPSJobQueueSize, config.CUPSJobFullUsername, config.CUPSIgnoreRawPrinters,
config.ShareScope, jobs, xmppNotifications)
//.........这里部分代码省略.........
开发者ID:kleopatra999,项目名称:cups-connector,代码行数:101,代码来源:connector.go
示例5: NewPrinterManager
func NewPrinterManager(cups *cups.CUPS, gcp *gcp.GoogleCloudPrint, xmpp *xmpp.XMPP, privet *privet.Privet, snmp *snmp.SNMPManager, printerPollInterval string, gcpMaxConcurrentDownload, cupsQueueSize uint, jobFullUsername, ignoreRawPrinters bool, shareScope string) (*PrinterManager, error) {
// Get the GCP printer list.
gcpPrinters, queuedJobsCount, err := allGCPPrinters(gcp)
if err != nil {
return nil, err
}
// Organize the GCP printers into a map.
for i := range gcpPrinters {
gcpPrinters[i].CUPSJobSemaphore = lib.NewSemaphore(cupsQueueSize)
}
gcpPrintersByGCPID := lib.NewConcurrentPrinterMap(gcpPrinters)
// Construct.
pm := PrinterManager{
cups: cups,
gcp: gcp,
xmpp: xmpp,
privet: privet,
snmp: snmp,
gcpPrintersByGCPID: gcpPrintersByGCPID,
downloadSemaphore: lib.NewSemaphore(gcpMaxConcurrentDownload),
jobStatsMutex: sync.Mutex{},
jobsDone: 0,
jobsError: 0,
gcpJobsInFlightMutex: sync.Mutex{},
gcpJobsInFlight: 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.gcpPrintersByGCPID.GetAll() {
getPrinter := func() (lib.Printer, bool) { return pm.gcpPrintersByGCPID.Get(printer.GCPID) }
err := privet.AddPrinter(printer, getPrinter)
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)
if privet == nil {
pm.listenNotifications(xmpp.Notifications(), make(chan *lib.Job))
} else {
pm.listenNotifications(xmpp.Notifications(), privet.Jobs())
}
for gcpID := range queuedJobsCount {
go pm.handleNewGCPJobs(gcpID)
}
return &pm, nil
}
开发者ID:rufil75,项目名称:cups-connector,代码行数:75,代码来源:printermanager.go
注:本文中的github.com/google/cups-connector/privet.Privet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论