mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
some progress but still doesn't work
This commit is contained in:
parent
894cbe76a1
commit
b243e67828
4 changed files with 168 additions and 32 deletions
|
@ -39,21 +39,29 @@ func (e Event) Label() string {
|
|||
type EventPool struct {
|
||||
sync.Mutex
|
||||
|
||||
NewEvents chan Event
|
||||
debug bool
|
||||
silent bool
|
||||
events []Event
|
||||
listeners []chan Event
|
||||
}
|
||||
|
||||
func NewEventPool(debug bool, silent bool) *EventPool {
|
||||
return &EventPool{
|
||||
NewEvents: make(chan Event, 0xff),
|
||||
debug: debug,
|
||||
silent: silent,
|
||||
events: make([]Event, 0),
|
||||
listeners: make([]chan Event, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EventPool) Listen() <-chan Event {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
l := make(chan Event)
|
||||
p.listeners = append(p.listeners, l)
|
||||
return l
|
||||
}
|
||||
|
||||
func (p *EventPool) SetSilent(s bool) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
@ -71,7 +79,11 @@ func (p *EventPool) Add(tag string, data interface{}) {
|
|||
defer p.Unlock()
|
||||
e := NewEvent(tag, data)
|
||||
p.events = append([]Event{e}, p.events...)
|
||||
p.NewEvents <- e
|
||||
|
||||
// broadcast the event to every listener
|
||||
for _, l := range p.listeners {
|
||||
l <- e
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EventPool) Log(level int, format string, args ...interface{}) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue