|
@@ -41,9 +41,14 @@ type plugins struct {
|
|
|
plugins map[string]*Plugin
|
|
|
}
|
|
|
|
|
|
+type extpointHandlers struct {
|
|
|
+ sync.RWMutex
|
|
|
+ extpointHandlers map[string][]func(string, *Client)
|
|
|
+}
|
|
|
+
|
|
|
var (
|
|
|
- storage = plugins{plugins: make(map[string]*Plugin)}
|
|
|
- extpointHandlers = make(map[string][]func(string, *Client))
|
|
|
+ storage = plugins{plugins: make(map[string]*Plugin)}
|
|
|
+ handlers = extpointHandlers{extpointHandlers: make(map[string][]func(string, *Client))}
|
|
|
)
|
|
|
|
|
|
// Manifest lists what a plugin implements.
|
|
@@ -128,15 +133,17 @@ func (p *Plugin) activateWithLock() error {
|
|
|
|
|
|
p.Manifest = m
|
|
|
|
|
|
+ handlers.RLock()
|
|
|
for _, iface := range m.Implements {
|
|
|
- handlers, handled := extpointHandlers[iface]
|
|
|
+ hdlrs, handled := handlers.extpointHandlers[iface]
|
|
|
if !handled {
|
|
|
continue
|
|
|
}
|
|
|
- for _, handler := range handlers {
|
|
|
+ for _, handler := range hdlrs {
|
|
|
handler(p.name, p.client)
|
|
|
}
|
|
|
}
|
|
|
+ handlers.RUnlock()
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -228,16 +235,18 @@ func Get(name, imp string) (*Plugin, error) {
|
|
|
|
|
|
// Handle adds the specified function to the extpointHandlers.
|
|
|
func Handle(iface string, fn func(string, *Client)) {
|
|
|
- handlers, ok := extpointHandlers[iface]
|
|
|
+ handlers.Lock()
|
|
|
+ hdlrs, ok := handlers.extpointHandlers[iface]
|
|
|
if !ok {
|
|
|
- handlers = []func(string, *Client){}
|
|
|
+ hdlrs = []func(string, *Client){}
|
|
|
}
|
|
|
|
|
|
- handlers = append(handlers, fn)
|
|
|
- extpointHandlers[iface] = handlers
|
|
|
+ hdlrs = append(hdlrs, fn)
|
|
|
+ handlers.extpointHandlers[iface] = hdlrs
|
|
|
for _, p := range storage.plugins {
|
|
|
p.activated = false
|
|
|
}
|
|
|
+ handlers.Unlock()
|
|
|
}
|
|
|
|
|
|
// GetAll returns all the plugins for the specified implementation
|