Move Hook `operator<' to BotInterp.C (cleaner source...)
[clinton/bobotpp.git] / source / BotInterp.H
CommitLineData
cb21075d 1// BotInterp.H -*- C++ -*-
2// Copyright (c) 1998 Etienne BERNARD
3c37f9a8 3// Copyright (C) 2002,2005,2008 Clinton Ebadi
cb21075d 4
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
528799bd 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18// 02110-1301, USA.
cb21075d 19
20#ifndef BOTINTERP_H
21#define BOTINTERP_H
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#ifdef USESCRIPTS
28
29#include <ctime>
3c37f9a8 30#include <map>
31#include <list>
32#include <functional>
33
cb21075d 34#include <libguile.h>
3c37f9a8 35
36#include "BotThreading.H"
cb21075d 37#include "String.H"
3c37f9a8 38#include "Utils.H"
cb21075d 39
40class Bot;
41
42struct Hook {
43 int type;
44 int priority;
45 bool fallthru;
46
47 String regex_str;
fd7440f1 48 String name;
cb21075d 49 SCM regex;
50 SCM function;
51
fd7440f1 52 Hook(int t, String rs, SCM r, SCM f, int p, bool ft, String n="DEFAULT")
31433d27 53 : type(t), priority (p), fallthru (ft), regex_str(rs),
fd7440f1 54 name (n), regex(r), function(f) { }
cb21075d 55
2d3af8a4 56 bool operator< (const Hook & h) const;
cb21075d 57
58 enum {
59 ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY,
ae97d6ec 60 DISCONNECT, FLOOD, INVITE, JOIN, KICK, MODE,
61 MESSAGE, NAMES, NOTICE, PART, PUBLIC,
fed59248 62 PUBLIC_NOTICE, RAW, TIMER, TOPIC,
63 // send hooks
6530edbf 64 SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE,
528799bd 65 SEND_WHO, SEND_WHOIS,
6530edbf 66 // DCC hooks
133eff7a 67 DCC_CHAT_BEGIN, DCC_CHAT_END, DCC_CHAT_MESSAGE
cb21075d 68 };
69};
70
71struct Timer {
72 int count;
73 std::time_t when;
74 SCM function;
75
76 Timer(int c, std::time_t t, SCM f)
77 : count(c), when(t), function(f) { }
3c37f9a8 78
79 bool operator< (const Timer & other) const
80 { return when < other.when; }
cb21075d 81};
82
83class BotInterp {
3c37f9a8 84 typedef std::list<Timer *> TimerList;
85
cb21075d 86 Bot * bot;
87 SCM logPort;
88 std::map<int, std::list<Hook *>, std::less<int> > hooksMap;
3c37f9a8 89 TimerList timers;
90 Utils::IndirectPred<Timer, std::less<Timer> > timer_sort_p;
cb21075d 91 int counter;
3c37f9a8 92 BotMutex hook_mutex;
93 BotMutex timer_mutex; // NOTE: recursive lock
cb21075d 94
95public:
96 BotInterp(Bot *, String);
97
d56bdd22 98 SCM ScriptLog();
cb21075d 99
100 void Execute(String);
101 void LoadScript(String);
102
fd7440f1 103 bool AddHook(int, SCM, SCM, int, bool, String);
cb21075d 104 bool RunHooks(int, String, SCM);
105
106 SCM AddTimer(int, SCM);
107 bool DelTimer(SCM);
108 bool RunTimers(int);
109
110 friend class Interp;
111 friend class ScriptCommands;
112};
113
114#endif
115#endif