summaryrefslogtreecommitdiff
path: root/plugin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-23 16:00:38 -0500
committerJeff Carr <[email protected]>2023-04-23 16:00:38 -0500
commitfbe943540106f1c12971932fd92f9395bbe214b3 (patch)
treef5b84a3bd09e230beb23e3e60947cf4fa91f870a /plugin.go
parentb3cd70c9a609cd00622a0df948d8f39b27f153af (diff)
start cleanup of the .so search code
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'plugin.go')
-rw-r--r--plugin.go112
1 files changed, 51 insertions, 61 deletions
diff --git a/plugin.go b/plugin.go
index addab32..5443bb0 100644
--- a/plugin.go
+++ b/plugin.go
@@ -63,40 +63,7 @@ func initPlugin(name string) *aplug {
}
}
- var newPlug *aplug
- newPlug = new(aplug)
- newPlug.InitOk = false
-
- // locate the shared library file
- filename := name + ".so"
- loadPlugin(newPlug, filename)
- if (newPlug.plug == nil) {
- log(true, "attempt to find plugin", filename, "failed")
- return nil
- }
- // newPlug.Ok = true
- newPlug.name = name
-
- // this tells the toolkit plugin how to send user events back to us
- // for things like: the user clicked on the 'Check IPv6'
- newPlug.Callback = sendCallback(newPlug, "Callback")
-
- // this let's us know where to send requests to the toolkit
- // for things like: add a new button called 'Check IPv6'
- newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
-
- allPlugins = append(allPlugins, newPlug)
-
- log(debugPlugin, "initPlugin() END", newPlug.name, filename)
- // newPlug.Init()
-
- // set the communication to the plugins
- newPlug.pluginChan = newPlug.PluginChannel()
- newPlug.Callback(Config.guiChan)
-
- newPlug.InitOk = true
-
- return newPlug
+ return searchPaths(name)
}
// newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
@@ -139,55 +106,78 @@ func sendCallback(p *aplug, funcName string) func(chan toolkit.Action) {
}
/*
+ TODO: clean this up. use command args?
This searches in the following order for the plugin .so files:
./toolkit/
~/go/src/go.wit.org/gui/toolkit/
/usr/lib/go-gui/
*/
-func loadPlugin(p *aplug, name string) {
+func searchPaths(name string) *aplug {
var filename string
- homeDir, err := os.UserHomeDir()
- if err != nil {
- log(logError, "loadPlugin() error. exiting here?")
- return
- }
-
// attempt to write out the file from the internal resource
- filename = "toolkit/" + name
- p.plug = loadfile(filename)
- if (p.plug != nil) {
- p.filename = filename
- return
+ filename = "toolkit/" + name + ".so"
+ p := tryfile(name, filename)
+ if (p != nil) {
+ return p
}
- filename = homeDir + "/go/src/git.wit.org/wit/gui/toolkit/" + name
- p.plug = loadfile(filename)
- if (p.plug != nil) {
- p.filename = filename
- return
+ homeDir, err := os.UserHomeDir()
+ if err != nil {
+ log(logError, "searchPaths() error. exiting here?")
+ } else {
+ filename = homeDir + "/go/src/git.wit.org/wit/gui/toolkit/" + name + ".so"
+ p = tryfile(name, filename)
+ if (p != nil) {
+ return p
+ }
}
- filename = "/usr/lib/go-gui/" + name
- p.plug = loadfile(filename)
- if (p.plug != nil) {
- p.filename = filename
- return
+ filename = "/usr/lib/go-gui/" + name + ".so"
+ p = tryfile(name, filename)
+ if (p != nil) {
+ return p
}
- return
+ return nil
}
// load module
// 1. open the shared object file to load the symbols
-func loadfile(filename string) *plugin.Plugin {
+func tryfile(name string, filename string) *aplug {
plug, err := plugin.Open(filename)
if err != nil {
log(debugGui, "plugin FAILED =", filename, err)
return nil
}
- log(debugGui, "plugin WORKED =", filename)
- log(true, "loading plugin", filename, "worked")
- return plug
+ log(debugGui, "loading plugin =", filename)
+
+ var newPlug *aplug
+ newPlug = new(aplug)
+ newPlug.InitOk = false
+ newPlug.name = name
+ newPlug.filename = filename
+ newPlug.plug = plug
+
+ // this tells the toolkit plugin how to send user events back to us
+ // for things like: the user clicked on the 'Check IPv6'
+ newPlug.Callback = sendCallback(newPlug, "Callback")
+
+ // this let's us know where to send requests to the toolkit
+ // for things like: add a new button called 'Check IPv6'
+ newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
+
+ allPlugins = append(allPlugins, newPlug)
+
+ log(debugPlugin, "initPlugin() END", newPlug.name, filename)
+ // newPlug.Init()
+
+ // set the communication to the plugins
+ newPlug.pluginChan = newPlug.PluginChannel()
+ newPlug.Callback(Config.guiChan)
+
+ newPlug.InitOk = true
+
+ return newPlug
}
// 2023/04/06 Queue() is also being used and channels are being used. memcopy() only