Plugins

Note

One of the main concept of Ockle’s design is that everything that could be a plugin, should be.

Ockle allows to add major features by the use of plugins. Each plugin is python class instance that gets executed in its own thread, allowing the developer to add new logic and behavior. You should be able to write a plugin without modifying Ockle’s core. But should be able to access any method within it. Many core functions in Ockle are plugins themselves including the Automatic server control and the communication to the web-based GUI.

In order to write a plugin, you should know that there are many pre-built tools that would help you in building one. Including a way to place your configuration variables in the GUI via simple Plugin ini template files

A general description of the tools available for the plugin would look like this:

Plugin Framework Diagram

What a plugin 'sees'

Every plugin is supplied with a pointer to the Main Daemon singletron, allowing access to services such as the server tree data-structure (to change the state of the servers) and the communication handler (which lets you add more commands to the communication with the webserver or any other external client). The plugin also gets access to all the functions defined in the plugin template class, such as special functions that arrange the configuration variable storage.

The Template plugin Class

To use this plugin framework simple extend the plugins.ModuleTemplate.ModuleTemplate . You may either extend the __init__ function to do things with Ockle starts, or the run method that will run your code in a seprate thread with access to Ockle’s functionality. You can also use the __init__ function to register new commends to send to Ockle as done in plugins.CoreCommunicationCommands.CoreCommunicationCommands.

class plugins.ModuleTemplate.ModuleTemplate(MainDaemon)[source]

The basic plugin that that all other plugins must extend

debug(message)[source]

Debug message for a module

Parameters:message – debug message
getConfigInt(value)[source]

Get a value from the config ini for a plugin

Parameters:value – The value you want to load
Returns:the value from config.ini
getConfigVar(value)[source]

Get a value from the config ini for a plugin

:param value - the value you want :return: the value from config.ini

run()[source]

To be implamented by the plugin, The main thread of the damon, this function runs in its own thread

stop()[source]

Called to request the thread to terminate

Example

Here is a simple plugin example, this plugin simply sends to debug “I am a test plugin” message every X seconds, as defined in its config var.

Plugin ini template files

If you want the configuration variable to be changeable at the webserver GUI, you must provide a template ini file in the src/config/plugins folder. The files should have the name of the plugin class proceeded with the .ini ending.

The section should be named plugins.<plugin name> .

These template files follow Ockle’s INI Template file format .

Example

Lets look at our TimerPluginExample example from before. We will need it to have a src/config/plugins/TimerPluginExample.ini. This file should contain the following text:

With those two files in place Ockle takes it from here and the plugin would be available to the user in the config sections.

Project Versions

Table Of Contents

Previous topic

Communication Handler

Next topic

Webserver - Ockle’s GUI

This Page