gplugin/gplugin

dbb7c8af6b9b
Parents 54627f4294b7
Children 984050b920b3
Use namespaces for all of the vala and genie plugins.

This was discovered when I loaded the vala and native test plugins at the same
time in gplugin query and they both tried to register types with the same
names.

Testing Done:
Ran unit tests and `gplugin-query` with all of the loaders and test plugins queryable.

Reviewed at https://reviews.imfreedom.org/r/984/
--- a/gplugin/reference/genie.md Thu Sep 30 17:03:43 2021 -0500
+++ b/gplugin/reference/genie.md Sat Oct 02 19:29:55 2021 -0500
@@ -8,38 +8,41 @@
### Example Genie Plugin
-Like all plugins in GPlugin, Genie plugins must also implement the
-`gplugin_query`, `gplugin_load`, and `gplugin_unload` functions.
+Due to the way `GPlugin.PluginInfo` info works, you must subclass it and set
+your values in the new constructor. It is recommended that you define this
+class in a namespace to avoid collisions with other plugins.
-Due to the way `GPlugin.PluginInfo` info works, you must subclass it and set
-your values in the new constructor.
+Like all plugins in GPlugin, Genie plugins must also implement the
+`gplugin_query`, `gplugin_load`, and `gplugin_unload` functions. These
+functions must be in the global namespace.
The following is a basic Genie plugin.
```genie
uses GPlugin
-class BasicPluginInfo : GPlugin.PluginInfo
- construct()
- authors : array of string = {"author1"}
+namespace BasicPlugin
+ class Info : GPlugin.PluginInfo
+ construct()
+ authors : array of string = {"author1"}
- Object(
- id: "gplugin/genie-basic-plugin",
- abi_version: 0x01020304,
- name: "basic plugin",
- authors: authors,
- category: "test",
- version: "version",
- license_id: "license",
- summary: "summary",
- website: "website",
- description: "description"
- )
+ Object(
+ id: "gplugin/genie-basic-plugin",
+ abi_version: 0x01020304,
+ name: "basic plugin",
+ authors: authors,
+ category: "test",
+ version: "version",
+ license_id: "license",
+ summary: "summary",
+ website: "website",
+ description: "description"
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new BasicPluginInfo()
+ return new BasicPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = null
--- a/gplugin/reference/vala.md Thu Sep 30 17:03:43 2021 -0500
+++ b/gplugin/reference/vala.md Sat Oct 02 19:29:55 2021 -0500
@@ -8,19 +8,23 @@
### Example Vala Plugin
-Like all plugins in GPlugin, Vala plugins must also implement the
-`gplugin_query`, `gplugin_load`, and `gplugin_unload` functions.
+Due to the way `GPlugin.PluginInfo` info works, you must subclass it and set
+your values in the new constructor. It is recommended that you define this
+class in a namespace to avoid collisions with other plugins.
-Due to the way `GPlugin.PluginInfo` info works, you must subclass it and set
-your values in the new constructor.
+Like all plugins in GPlugin, Vala plugins must also implement the
+`gplugin_query`, `gplugin_load`, and `gplugin_unload` functions. These
+functions must be in the global namespace.
The following is a basic Vala plugin.
```vala
using GPlugin;
-public class BasicPluginInfo : GPlugin.PluginInfo {
- public BasicPluginInfo() {
+namespace BasicPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
string[] authors = {"author1"};
Object(
@@ -38,10 +42,12 @@
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new BasicPluginInfo();
+ return new BasicPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/genie-plugins/basic.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/basic.gs Sat Oct 02 19:29:55 2021 -0500
@@ -16,27 +16,28 @@
*/
uses GPlugin
-class BasicPluginInfo : GPlugin.PluginInfo
- construct()
- authors : array of string = {"author1"}
+namespace GenieBasicPlugin
+ class Info : GPlugin.PluginInfo
+ construct()
+ authors : array of string = {"author1"}
- Object(
- id: "gplugin/genie-basic-plugin",
- abi_version: 0x01020304,
- name: "basic plugin",
- authors: authors,
- category: "test",
- version: "version",
- license_id: "license",
- summary: "summary",
- website: "website",
- description: "description"
- )
+ Object(
+ id: "gplugin/genie-basic-plugin",
+ abi_version: 0x01020304,
+ name: "basic plugin",
+ authors: authors,
+ category: "test",
+ version: "version",
+ license_id: "license",
+ summary: "summary",
+ website: "website",
+ description: "description"
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new BasicPluginInfo()
+ return new GenieBasicPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
if not(plugin isa GPlugin.Plugin)
--- a/vala/tests/genie-plugins/dependent.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/dependent.gs Sat Oct 02 19:29:55 2021 -0500
@@ -16,19 +16,20 @@
*/
uses GPlugin;
-class DependentPluginInfo : GPlugin.PluginInfo
- construct()
- dependencies : array of string = {"dependency1", "dependency2"}
+namespace GenieDependentPlugin
+ class Info : GPlugin.PluginInfo
+ construct()
+ dependencies : array of string = {"dependency1", "dependency2"}
- Object(
- id: "gplugin/genie-dependent-plugin",
- dependencies: dependencies
- )
+ Object(
+ id: "gplugin/genie-dependent-plugin",
+ dependencies: dependencies
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new DependentPluginInfo()
+ return new GenieDependentPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = null
--- a/vala/tests/genie-plugins/load-exception.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/load-exception.gs Sat Oct 02 19:29:55 2021 -0500
@@ -16,16 +16,17 @@
*/
uses GPlugin
-class LoadExceptionPluginInfo : GPlugin.PluginInfo
- construct ()
- Object(
- id: "gplugin/genie-load-exception"
- )
+namespace GenieLoadExceptionPlugin
+ class Info : GPlugin.PluginInfo
+ construct ()
+ Object(
+ id: "gplugin/genie-load-exception"
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new LoadExceptionPluginInfo()
+ return new GenieLoadExceptionPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = new Error(Quark.from_string("gplugin"), 0, "explode")
--- a/vala/tests/genie-plugins/load-failed.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/load-failed.gs Sat Oct 02 19:29:55 2021 -0500
@@ -16,16 +16,17 @@
*/
uses GPlugin
-class LoadFailedPluginInfo : GPlugin.PluginInfo
- construct ()
- Object(
- id: "gplugin/genie-load-failed"
- )
+namespace LoadFailedPlugin
+ class Info : GPlugin.PluginInfo
+ construct ()
+ Object(
+ id: "gplugin/genie-load-failed"
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new LoadFailedPluginInfo()
+ return new LoadFailedPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = null
--- a/vala/tests/genie-plugins/unload-failed.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/unload-failed.gs Sat Oct 02 19:29:55 2021 -0500
@@ -16,16 +16,17 @@
*/
uses GPlugin
-class UnloadFailedPluginInfo : GPlugin.PluginInfo
- construct()
- Object(
- id: "gplugin/genie-unload-failed"
- )
+namespace UnloadFailedPlugin
+ class Info : GPlugin.PluginInfo
+ construct()
+ Object(
+ id: "gplugin/genie-unload-failed"
+ )
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new UnloadFailedPluginInfo()
+ return new UnloadFailedPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = null
--- a/vala/tests/genie-plugins/unload-shutdown.gs Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/genie-plugins/unload-shutdown.gs Sat Oct 02 19:29:55 2021 -0500
@@ -17,11 +17,12 @@
uses GLib
uses GPlugin
-class UnloadShutdownPluginInfo : GPlugin.PluginInfo
- construct()
- Object(
- id: "gplugin/genie-unload-shutdown"
- )
+namespace UnloadShutdownPlugin
+ class Info : GPlugin.PluginInfo
+ construct()
+ Object(
+ id: "gplugin/genie-unload-shutdown"
+ )
exception UnloadError
ShutdownNotSet
@@ -29,7 +30,7 @@
def gplugin_query(out error : Error) : GPlugin.PluginInfo
error = null
- return new UnloadShutdownPluginInfo()
+ return new UnloadShutdownPlugin.Info()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
error = null
--- a/vala/tests/plugins/basic.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/basic.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,8 +16,10 @@
*/
using GPlugin;
-public class BasicPluginInfo : GPlugin.PluginInfo {
- public BasicPluginInfo() {
+namespace ValaBasicPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
string[] authors = {"author1"};
Object(
@@ -35,10 +37,12 @@
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new BasicPluginInfo();
+ return new ValaBasicPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/plugins/dependent.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/dependent.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,8 +16,10 @@
*/
using GPlugin;
-public class DependentPluginInfo : GPlugin.PluginInfo {
- public DependentPluginInfo() {
+namespace ValaDependentPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
string[] dependencies = {"dependency1", "dependency2"};
Object(
@@ -27,10 +29,12 @@
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new DependentPluginInfo();
+ return new ValaDependentPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/plugins/load-exception.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/load-exception.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,18 +16,22 @@
*/
using GPlugin;
-public class LoadExceptionPluginInfo : GPlugin.PluginInfo {
- public LoadExceptionPluginInfo() {
+namespace ValaLoadExceptionPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
Object(
id: "gplugin/vala-load-exception"
);
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new LoadExceptionPluginInfo();
+ return new ValaLoadExceptionPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/plugins/load-failed.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/load-failed.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,18 +16,22 @@
*/
using GPlugin;
-public class LoadFailedPluginInfo : GPlugin.PluginInfo {
- public LoadFailedPluginInfo() {
+namespace ValaLoadFailedPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
Object(
id: "gplugin/vala-load-failed"
);
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new LoadFailedPluginInfo();
+ return new ValaLoadFailedPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/plugins/unload-failed.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/unload-failed.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,18 +16,22 @@
*/
using GPlugin;
-public class UnloadFailedPluginInfo : GPlugin.PluginInfo {
- public UnloadFailedPluginInfo() {
+namespace ValaUnloadFailed {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
Object(
id: "gplugin/vala-unload-failed"
);
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new UnloadFailedPluginInfo();
+ return new ValaUnloadFailed.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
--- a/vala/tests/plugins/unload-shutdown.vala Thu Sep 30 17:03:43 2021 -0500
+++ b/vala/tests/plugins/unload-shutdown.vala Sat Oct 02 19:29:55 2021 -0500
@@ -16,18 +16,22 @@
*/
using GPlugin;
-public class UnloadShutdownPluginInfo : GPlugin.PluginInfo {
- public UnloadShutdownPluginInfo() {
+namespace ValaShutdownPlugin {
+
+public class Info : GPlugin.PluginInfo {
+ public Info() {
Object(
id: "gplugin/vala-unload-shutdown"
);
}
}
+}
+
public GPlugin.PluginInfo gplugin_query(out Error error) {
error = null;
- return new UnloadShutdownPluginInfo();
+ return new ValaShutdownPlugin.Info();
}
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {