Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Add plugin initialization at server start
Browse files Browse the repository at this point in the history
Added the ability for a plugin to specify an initialization routine that
is only executed when the SiriProxy server is started. This provides the
plugin a mechanism to perform a task that is not required to be
performed upon every connection.
  • Loading branch information
Kyle committed Feb 17, 2013
1 parent 5785998 commit 4452d33
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/siriproxy/command_line.rb
Expand Up @@ -82,6 +82,7 @@ def run_bundle(subcommand='')

def run_server(subcommand='start')
load_code
init_plugins
start_server
# @todo: support for forking server into bg and start/stop/restart
# subcommand ||= 'start'
Expand Down Expand Up @@ -188,4 +189,26 @@ def load_code
require 'siriproxy/plugin'
require 'siriproxy/plugin_manager'
end

def init_plugins
if $APP_CONFIG.plugins
$APP_CONFIG.plugins.each_with_index do |pluginConfig, i|
if pluginConfig.is_a? String
className = pluginConfig
requireName = "siriproxy-#{className.downcase}"
else
className = pluginConfig['name']
requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
end
require requireName
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)

if plugin.respond_to?('plugin_init')
$APP_CONFIG.plugins[i]['init'] = plugin.plugin_init
end

plugin = nil
end
end
end
end

0 comments on commit 4452d33

Please sign in to comment.