diff options
author | Julien Dessaux | 2010-02-04 23:34:15 +0100 |
---|---|---|
committer | Julien Dessaux | 2010-02-04 23:34:15 +0100 |
commit | 416460886da9f8d835200ca46c9062a4ebd78fe7 (patch) | |
tree | f76663fd592d13031f494674c8c602e624f1d03d /Hsbot/Plugin.hs | |
parent | Began a complete rewrite of command and plugin management. (diff) | |
download | hsbot-416460886da9f8d835200ca46c9062a4ebd78fe7.tar.gz hsbot-416460886da9f8d835200ca46c9062a4ebd78fe7.tar.bz2 hsbot-416460886da9f8d835200ca46c9062a4ebd78fe7.zip |
Continue rewriting, found a problem in the way I kill plugins.
Diffstat (limited to 'Hsbot/Plugin.hs')
-rw-r--r-- | Hsbot/Plugin.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Hsbot/Plugin.hs b/Hsbot/Plugin.hs index e6f425a..d75fe8e 100644 --- a/Hsbot/Plugin.hs +++ b/Hsbot/Plugin.hs @@ -1,10 +1,13 @@ module Hsbot.Plugin ( loadPlugin , sendToPlugin + , reloadPlugin + , unloadPlugin ) where import Control.Concurrent import Control.Concurrent.Chan +import Control.Exception.Extensible import Control.Monad.State import qualified Data.Map as M import System.IO @@ -53,6 +56,12 @@ effectivelyLoadPlugin name serverChan = do return Nothing return plugin +-- | Reloads a plugin +reloadPlugin :: String -> IrcBot () +reloadPlugin name = do + unloadPlugin name + loadPlugin name + -- | Unloads a plugin unloadPlugin :: String -> IrcBot () unloadPlugin name = do @@ -61,17 +70,12 @@ unloadPlugin name = do case M.lookup name oldPlugins of Just plugin -> do let newPlugins = M.delete name oldPlugins - liftIO $ killPlugin plugin -- TODO : forkIO to get this asynchronous and non blocking - -- or let's see if closing one's chan kills him. - unloadAll $ pluginModule $ M.lookup name oldPlugins + liftIO $ throwTo (pluginThreadId plugin) UserInterrupt -- TODO : fix this! + --sendToPlugin (InternalCmd $ IntCmd "STOP" "CORE" name "") plugin + liftIO $ unloadAll $ pluginModule plugin put $ bot { botPlugins = newPlugins } Nothing -> return () --- | stop a plugin -killPlugin :: Plugin -> IO () -killPlugin plugin = do - -- TODO : send stop, sleep and kill thread (if necessary) and remove its commands - -- | Sends a msg to a plugin sendToPlugin :: BotMsg -> Plugin -> IrcBot () sendToPlugin msg plugin = do |