plamoni / SiriProxy

A (tampering) proxy server for Apple's Siri
GNU General Public License v3.0
2.12k stars 343 forks source link

Allow plugins to initialize at server startup #453

Closed kylethedude closed 11 years ago

kylethedude commented 11 years ago

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. This is an optional feature, so existing plugins won't break.

Usage

  1. Plugin defines a function called "plugin_init" to be called once when the server is started.
def plugin_init
  init_data = Hash.new

   # dynamically collect info into "init_data" 

   return init_data
end
  1. Function "plugin_init" should return initialization data to be used on future connections.
  2. In plugin "initialize" (constructor) function, plugin can access saved initialization data from passed "config" hash.
def initialize(config)
    if (config.has_key?("init"))
        # plugin has been initialized, use config['init'] to access "init_data"
    else
        # plugin is being called on server start
    end
end

Usefulness

elvisimprsntr commented 11 years ago

+1 on this.

elvisimprsntr commented 11 years ago

This will help reduce init times of my redeye plugin which has to pull in 100s of variables.

kylethedude commented 11 years ago

I agree that duplicating code is sloppy, so I've revised my approach.

plamoni commented 11 years ago

Looks good!