Enhance threadsafety of Hooks and improve generally
[clinton/bobotpp.git] / source / BotInterp.H
index f63a7b1..4329ee4 100644 (file)
 #ifdef USESCRIPTS
 
 #include <ctime>
-#include <map>
-#include <list>
 #include <functional>
+#include <list>
+#include <map>
+#include <string>
 
 #include <libguile.h>
 
@@ -44,12 +45,12 @@ struct Hook {
   int priority;
   bool fallthru;
 
-  String regex_str;
-  String name;
+  std::string regex_str;
+  std::string name;
   SCM regex;
   SCM function;
 
-  Hook(int t, String rs, SCM r, SCM f, int p, bool ft, String n="DEFAULT")
+  Hook(int t, std::string rs, SCM r, SCM f, int p, bool ft, std::string n="DEFAULT")
     : type(t), priority (p), fallthru (ft), regex_str(rs), 
       name (n), regex(r), function(f)  { }
 
@@ -82,13 +83,19 @@ struct Timer {
 
 class BotInterp {
   typedef std::list<Timer *> TimerList;
+  typedef std::list<Hook *> HookList;
+  typedef std::map<int, HookList, std::less<int> > HookMap;
   
   Bot * bot;
   SCM logPort;
-  std::map<int, std::list<Hook *>, std::less<int> > hooksMap;
+  int counter;
+
+  HookMap hooks;
   TimerList timers;
+
   Utils::IndirectPred<Timer, std::less<Timer> > timer_sort_p;
-  int counter;
+  Utils::IndirectPred<Hook, std::less<Hook> > hook_sort_p;
+
   BotMutex hook_mutex;
   BotMutex timer_mutex; // NOTE: recursive lock
 
@@ -100,8 +107,8 @@ public:
   void Execute(String);
   void LoadScript(String);
 
-  bool AddHook(int, SCM, SCM, int, bool, String);
-  bool RunHooks(int, String, SCM);
+  bool AddHook(int, SCM, SCM, int, bool, std::string);
+  bool RunHooks(int, std::string, SCM);
 
   SCM AddTimer(int, SCM);
   bool DelTimer(SCM);