-
Notifications
You must be signed in to change notification settings - Fork 23
/
task.go
84 lines (73 loc) · 2.29 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License 2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
. "github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
. "github.com/energye/golcl/lcl/api"
"unsafe"
)
// ITask Parent: TCefTask
//
// Implement this interface for asynchronous task execution. If the task is
// posted successfully and if the associated message loop is still running then
// the execute() function will be called on the target thread. If the task
// fails to post then the task object may be destroyed on the source thread
// instead of the target thread. For this reason be cautious when performing
// work in the task object destructor.
// <a cref="uCEFTypes|TCefTask">Implements TCefTask</a>
// <a href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_task_capi.h">CEF source file: /include/capi/cef_task_capi.h (cef_task_t)</a>
type ITask struct {
base TCefBaseRefCounted
instance unsafe.Pointer
executePtr uintptr
}
func NewTask() *ITask {
r1, _, _ := imports.Proc(def.Task_Create).Call()
return &ITask{
instance: unsafe.Pointer(r1),
}
}
func (m *ITask) OnlyPostTask(threadId TCefThreadId) bool {
r1, _, _ := imports.Proc(def.Task_OnlyPostTask).Call(m.Instance(), uintptr(threadId))
return GoBool(r1)
}
func (m *ITask) OnlyPostDelayedTask(threadId TCefThreadId, delay int64) bool {
r1, _, _ := imports.Proc(def.Task_OnlyPostDelayedTask).Call(m.Instance(), uintptr(threadId), uintptr(unsafe.Pointer(&delay)))
return GoBool(r1)
}
func (m *ITask) SetOnExecute(fn TTaskExecute) {
if m.executePtr != 0 {
RemoveEventElement(m.executePtr)
}
m.executePtr = MakeEventDataPtr(fn)
imports.Proc(def.Task_SetOnExecute).Call(m.Instance(), m.executePtr)
}
func (m *ITask) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ITask) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
type TTaskExecute func()
func init() {
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
switch fn.(type) {
case TTaskExecute:
fn.(TTaskExecute)()
default:
return false
}
return true
})
}