energy/cef/global-work-scheduler.go

129 lines
3.4 KiB
Go
Raw Normal View History

2023-06-12 13:01:51 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
2023-06-20 22:41:33 +08:00
"github.com/energye/energy/v2/consts"
2023-06-12 13:01:51 +08:00
"github.com/energye/golcl/lcl"
2023-06-20 22:41:33 +08:00
"github.com/energye/golcl/lcl/api"
2023-06-12 13:01:51 +08:00
"unsafe"
)
2023-06-20 22:41:33 +08:00
var GlobalWorkScheduler *TCEFWorkScheduler
2023-06-12 13:01:51 +08:00
type TCEFWorkScheduler struct {
instance unsafe.Pointer
}
// Instance 实例
func (m *TCEFWorkScheduler) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
func (m *TCEFWorkScheduler) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
2023-06-21 08:39:51 +08:00
2023-06-12 13:01:51 +08:00
func GlobalWorkSchedulerCreate(owner lcl.IComponent) *TCEFWorkScheduler {
2023-06-20 22:41:33 +08:00
if GlobalWorkScheduler != nil {
return GlobalWorkScheduler
}
2023-06-12 13:01:51 +08:00
var aOwner uintptr
if owner != nil {
aOwner = owner.Instance()
}
var result uintptr
imports.Proc(def.CEFWorkScheduler_Create).Call(aOwner, uintptr(unsafe.Pointer(&result)))
if result != 0 {
2023-06-20 22:41:33 +08:00
GlobalWorkScheduler = &TCEFWorkScheduler{instance: unsafe.Pointer(result)}
2023-06-12 13:01:51 +08:00
}
2023-06-20 22:41:33 +08:00
return GlobalWorkScheduler
2023-06-12 13:01:51 +08:00
}
2023-06-21 08:39:51 +08:00
func GlobalWorkSchedulerCreateDelayed() *TCEFWorkScheduler {
if GlobalWorkScheduler != nil {
return GlobalWorkScheduler
}
2023-06-12 22:24:03 +08:00
var result uintptr
imports.Proc(def.CEFWorkScheduler_CreateDelayed).Call(uintptr(unsafe.Pointer(&result)))
if result != 0 {
2023-06-21 08:39:51 +08:00
GlobalWorkScheduler = &TCEFWorkScheduler{instance: unsafe.Pointer(result)}
2023-06-12 22:24:03 +08:00
}
2023-06-21 08:39:51 +08:00
return GlobalWorkScheduler
}
func (m *TCEFWorkScheduler) StopScheduler() {
imports.Proc(def.CEFWorkScheduler_StopScheduler).Call()
2023-06-12 22:24:03 +08:00
}
2023-06-21 08:39:51 +08:00
func (m *TCEFWorkScheduler) CreateThread() {
2023-06-12 22:24:03 +08:00
imports.Proc(def.CEFWorkScheduler_CreateThread).Call()
}
2023-06-21 08:39:51 +08:00
func (m *TCEFWorkScheduler) Destroy() {
2023-06-12 13:01:51 +08:00
imports.Proc(def.CEFWorkScheduler_Destroy).Call()
}
2023-06-20 22:41:33 +08:00
// GetPriority Windows
func (m *TCEFWorkScheduler) GetPriority() consts.TThreadPriority {
r := imports.SysCallN(def.CEFWorkScheduler_GetPriority)
return consts.TThreadPriority(r)
}
// GetPriority Windows
func (m *TCEFWorkScheduler) SetPriority(value consts.TThreadPriority) {
imports.SysCallN(def.CEFWorkScheduler_SetPriority, uintptr(value))
}
func (m *TCEFWorkScheduler) GetDefaultInterval() int32 {
r := imports.SysCallN(def.CEFWorkScheduler_GetDefaultInterval)
return int32(r)
}
func (m *TCEFWorkScheduler) GetDepleteWorkCycles() uint32 {
r := imports.SysCallN(def.CEFWorkScheduler_GetDepleteWorkCycles)
return uint32(r)
}
func (m *TCEFWorkScheduler) GetDepleteWorkDelay() uint32 {
r := imports.SysCallN(def.CEFWorkScheduler_GetDepleteWorkDelay)
return uint32(r)
}
func (m *TCEFWorkScheduler) GetUseQueueThread() bool {
r := imports.SysCallN(def.CEFWorkScheduler_GetUseQueueThread)
return api.GoBool(r)
}
func (m *TCEFWorkScheduler) SetDefaultInterval(value int32) {
imports.SysCallN(def.CEFWorkScheduler_SetDefaultInterval, uintptr(value))
}
func (m *TCEFWorkScheduler) SetDepleteWorkCycles(value uint32) {
imports.SysCallN(def.CEFWorkScheduler_SetDepleteWorkCycles, uintptr(value))
}
func (m *TCEFWorkScheduler) SetDepleteWorkDelay(value uint32) {
imports.SysCallN(def.CEFWorkScheduler_SetDepleteWorkDelay, uintptr(value))
}
func (m *TCEFWorkScheduler) SetUseQueueThread(value bool) {
imports.SysCallN(def.CEFWorkScheduler_SetUseQueueThread, api.PascalBool(value))
}