Difference between revisions of "Plugin"

From Navit's Wiki
Jump to: navigation, search
m (Moving away from automaker)
(Update link from sourceforge to github)
Line 27: Line 27:
 
</source>
 
</source>
  
The [https://sourceforge.net/p/navit/code/HEAD/tree/trunk/navit/navit/plugin/j1850/j1850.c j1850 plugin] is quite simple and can be a good start if you want to write your own plugin.
+
The [https://github.com/navit-gps/navit/blob/trunk/navit/plugin/j1850/j1850.c j1850 plugin] is quite simple and can be a good start if you want to write your own plugin.
 
It demonstrates how to use event callbacks ( using a timeout during the plugin init, or using the idle loop during the regular use), how to add a custom OSD for your plugin, and how to send commands to another plugin (look at the spotify controls).
 
It demonstrates how to use event callbacks ( using a timeout during the plugin init, or using the idle loop during the regular use), how to add a custom OSD for your plugin, and how to send commands to another plugin (look at the spotify controls).
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 00:23, 10 October 2017

Nearly everything in navit is a plugin. A plugin is a shared library which needs to contain a function

void plugin_init(void)

This function is called when the plugin gets loaded. Usually it should call an appropriate

void plugin_init(void) {
	dbg(0, "Enter\n");
	plugin_register_something_type();
	dbg(0, "Exit\n");
}

function.

Unless you know better, start by creating a new folder under /plugin.

Then add Makefile.am and CMakeLists.txt to you plugin directory, so your plugin is built as a module (e.g. libmyplugin.so).

Finally, add a module definition to /CmakeLists.txt, to have it built at all.

add_module(plugin/myplugin "Default" TRUE)

To have the plugin loaded, you need to add it to the <plugins> Object in navit.xml:

	<plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libmyplugin.so" active="yes"/>

The j1850 plugin is quite simple and can be a good start if you want to write your own plugin. It demonstrates how to use event callbacks ( using a timeout during the plugin init, or using the idle loop during the regular use), how to add a custom OSD for your plugin, and how to send commands to another plugin (look at the spotify controls).