57
class EventObserverList;
58
class EventObserverList;
61
62
class EventObserver : public Plugin
64
EventObserver(const EventObserver &);
65
EventObserver& operator=(const EventObserver &);
67
explicit EventObserver(std::string name_arg)
68
: Plugin(name_arg, "EventObserver")
70
virtual ~EventObserver() {}
65
EventObserver(const EventObserver &);
66
EventObserver& operator=(const EventObserver &);
68
explicit EventObserver(std::string name_arg)
69
: Plugin(name_arg, "EventObserver")
71
virtual ~EventObserver() {}
73
74
/* Session events: */
74
75
BEFORE_CREATE_DATABASE, AFTER_CREATE_DATABASE,
75
76
BEFORE_DROP_DATABASE, AFTER_DROP_DATABASE,
77
78
/* Schema events: */
78
79
BEFORE_DROP_TABLE, AFTER_DROP_TABLE,
79
80
BEFORE_RENAME_TABLE, AFTER_RENAME_TABLE,
81
82
/* Table events: */
82
83
BEFORE_INSERT_RECORD, AFTER_INSERT_RECORD,
83
84
BEFORE_UPDATE_RECORD, AFTER_UPDATE_RECORD,
84
85
BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD,
86
87
/* The max event ID marker. */
90
static const char *eventName(EventType event)
91
static const char *eventName(EventType event)
94
case BEFORE_DROP_TABLE:
95
return "BEFORE_DROP_TABLE";
97
case AFTER_DROP_TABLE:
98
return "AFTER_DROP_TABLE";
100
case BEFORE_RENAME_TABLE:
101
return "BEFORE_RENAME_TABLE";
103
case AFTER_RENAME_TABLE:
104
return "AFTER_RENAME_TABLE";
106
case BEFORE_INSERT_RECORD:
107
return "BEFORE_INSERT_RECORD";
109
case AFTER_INSERT_RECORD:
110
return "AFTER_INSERT_RECORD";
112
case BEFORE_UPDATE_RECORD:
113
return "BEFORE_UPDATE_RECORD";
115
case AFTER_UPDATE_RECORD:
116
return "AFTER_UPDATE_RECORD";
118
case BEFORE_DELETE_RECORD:
119
return "BEFORE_DELETE_RECORD";
121
case AFTER_DELETE_RECORD:
122
return "AFTER_DELETE_RECORD";
124
case BEFORE_CREATE_DATABASE:
125
return "BEFORE_CREATE_DATABASE";
127
case AFTER_CREATE_DATABASE:
128
return "AFTER_CREATE_DATABASE";
130
case BEFORE_DROP_DATABASE:
131
return "BEFORE_DROP_DATABASE";
133
case AFTER_DROP_DATABASE:
134
return "AFTER_DROP_DATABASE";
136
case MAX_EVENT_COUNT:
143
/*==========================================================*/
144
/* registerEvents() must be implemented to allow the plugin to
145
* register which events it is interested in.
147
virtual void registerTableEventsDo(TableShare &, EventObserverList &){}
148
virtual void registerSchemaEventsDo(const std::string &/*db*/, EventObserverList &) {}
149
virtual void registerSessionEventsDo(Session &, EventObserverList &) {}
151
virtual bool observeEventDo(EventData &)= 0;
153
/*==========================================================*/
154
/* Static access methods called by drizzle: */
155
static bool addPlugin(EventObserver *handler);
156
static void removePlugin(EventObserver *handler);
158
/*==========================================================*/
159
/* Register an event of interest for this plugin.
160
* This is called from with in the plugin when registering itself.
162
* The position field is used to indicate the order the event observer is to be
163
* called. If the event observer must be called before any other observer then
164
* the position must be set to 1. If it must be called last then the position must be
165
* set to -1. A position of 0 indicated the position doesn't matter.
167
* If 2 plugins require the same position then which is called first in not guarenteed.
168
* In this case a warrning will be logged but execution will continue.
170
* It is good practice that if the event position matters not to hard code the position
171
* but supply a systen variable so that it can be set at runtime so that the user can
172
* decide which event should be called first.
174
void registerEvent(EventObserverList &observers, EventType event, int32_t position= 0);
176
/*==========================================================*/
177
/* Called from drizzle to register all events for all event plugins
178
* interested in this table.
180
static void registerTableEvents(TableShare &table_share);
181
static void deregisterTableEvents(TableShare &table_share);
183
/*==========================================================*/
184
/* Called from drizzle to register all events for all event plugins
185
* interested in this database.
187
static void registerSchemaEvents(Session &session, const std::string &db);
188
static void deregisterSchemaEvents(Session &session, const std::string &db);
190
/*==========================================================*/
191
/* Called from drizzle to register all events for all event plugins
192
* interested in this session.
194
static void registerSessionEvents(Session &session);
195
static void deregisterSessionEvents(Session &session);
198
/*==========================================================*/
199
/* Static meathods called by drizzle to notify interested plugins
200
* of a schema an event,
202
static bool beforeDropTable(Session &session, TableIdentifier &table);
203
static bool afterDropTable(Session &session, TableIdentifier &table, int err);
204
static bool beforeRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to);
205
static bool afterRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to, int err);
207
/*==========================================================*/
208
/* Static meathods called by drizzle to notify interested plugins
209
* of a table an event,
211
static bool beforeInsertRecord(Session &session, TableShare &table_share, unsigned char *buf);
212
static bool afterInsertRecord(Session &session, TableShare &table_share, const unsigned char *buf, int err);
213
static bool beforeDeleteRecord(Session &session, TableShare &table_share, const unsigned char *buf);
214
static bool afterDeleteRecord(Session &session, TableShare &table_share, const unsigned char *buf, int err);
215
static bool beforeUpdateRecord(Session &session, TableShare &table_share, const unsigned char *old_data, unsigned char *new_data);
216
static bool afterUpdateRecord(Session &session, TableShare &table_share, const unsigned char *old_data, unsigned char *new_data, int err);
218
/*==========================================================*/
219
/* Static meathods called by drizzle to notify interested plugins
220
* of a table an event,
222
static bool beforeCreateDatabase(Session &session, const std::string &db);
223
static bool afterCreateDatabase(Session &session, const std::string &db, int err);
224
static bool beforeDropDatabase(Session &session, const std::string &db);
225
static bool afterDropDatabase(Session &session, const std::string &db, int err);
95
case BEFORE_DROP_TABLE:
96
return "BEFORE_DROP_TABLE";
98
case AFTER_DROP_TABLE:
99
return "AFTER_DROP_TABLE";
101
case BEFORE_RENAME_TABLE:
102
return "BEFORE_RENAME_TABLE";
104
case AFTER_RENAME_TABLE:
105
return "AFTER_RENAME_TABLE";
107
case BEFORE_INSERT_RECORD:
108
return "BEFORE_INSERT_RECORD";
110
case AFTER_INSERT_RECORD:
111
return "AFTER_INSERT_RECORD";
113
case BEFORE_UPDATE_RECORD:
114
return "BEFORE_UPDATE_RECORD";
116
case AFTER_UPDATE_RECORD:
117
return "AFTER_UPDATE_RECORD";
119
case BEFORE_DELETE_RECORD:
120
return "BEFORE_DELETE_RECORD";
122
case AFTER_DELETE_RECORD:
123
return "AFTER_DELETE_RECORD";
125
case BEFORE_CREATE_DATABASE:
126
return "BEFORE_CREATE_DATABASE";
128
case AFTER_CREATE_DATABASE:
129
return "AFTER_CREATE_DATABASE";
131
case BEFORE_DROP_DATABASE:
132
return "BEFORE_DROP_DATABASE";
134
case AFTER_DROP_DATABASE:
135
return "AFTER_DROP_DATABASE";
137
case MAX_EVENT_COUNT:
144
/*==========================================================*/
145
/* registerEvents() must be implemented to allow the plugin to
146
* register which events it is interested in.
148
virtual void registerTableEventsDo(TableShare &, EventObserverList &){}
149
virtual void registerSchemaEventsDo(const std::string &/*db*/, EventObserverList &) {}
150
virtual void registerSessionEventsDo(Session &, EventObserverList &) {}
152
virtual bool observeEventDo(EventData &)= 0;
154
/*==========================================================*/
155
/* Static access methods called by drizzle: */
156
static bool addPlugin(EventObserver *handler);
157
static void removePlugin(EventObserver *handler);
159
/*==========================================================*/
160
/* Register an event of interest for this plugin.
161
* This is called from with in the plugin when registering itself.
163
* The position field is used to indicate the order the event observer is to be
164
* called. If the event observer must be called before any other observer then
165
* the position must be set to 1. If it must be called last then the position must be
166
* set to -1. A position of 0 indicated the position doesn't matter.
168
* If 2 plugins require the same position then which is called first in not guarenteed.
169
* In this case a warrning will be logged but execution will continue.
171
* It is good practice that if the event position matters not to hard code the position
172
* but supply a systen variable so that it can be set at runtime so that the user can
173
* decide which event should be called first.
175
void registerEvent(EventObserverList &observers, EventType event, int32_t position= 0);
177
/*==========================================================*/
178
/* Called from drizzle to register all events for all event plugins
179
* interested in this table.
181
static void registerTableEvents(TableShare &table_share);
182
static void deregisterTableEvents(TableShare &table_share);
184
/*==========================================================*/
185
/* Called from drizzle to register all events for all event plugins
186
* interested in this database.
188
static void registerSchemaEvents(Session &session, const std::string &db);
189
static void deregisterSchemaEvents(Session &session, const std::string &db);
191
/*==========================================================*/
192
/* Called from drizzle to register all events for all event plugins
193
* interested in this session.
195
static void registerSessionEvents(Session &session);
196
static void deregisterSessionEvents(Session &session);
199
/*==========================================================*/
200
/* Static meathods called by drizzle to notify interested plugins
201
* of a schema an event,
203
static bool beforeDropTable(Session &session, TableIdentifier &table);
204
static bool afterDropTable(Session &session, TableIdentifier &table, int err);
205
static bool beforeRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to);
206
static bool afterRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to, int err);
208
/*==========================================================*/
209
/* Static meathods called by drizzle to notify interested plugins
210
* of a table an event,
212
static bool beforeInsertRecord(Table &table, unsigned char *buf);
213
static bool afterInsertRecord(Table &table, const unsigned char *buf, int err);
214
static bool beforeDeleteRecord(Table &table, const unsigned char *buf);
215
static bool afterDeleteRecord(Table &table, const unsigned char *buf, int err);
216
static bool beforeUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data);
217
static bool afterUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data, int err);
219
/*==========================================================*/
220
/* Static meathods called by drizzle to notify interested plugins
221
* of a table an event,
223
static bool beforeCreateDatabase(Session &session, const std::string &db);
224
static bool afterCreateDatabase(Session &session, const std::string &db, int err);
225
static bool beforeDropDatabase(Session &session, const std::string &db);
226
static bool afterDropDatabase(Session &session, const std::string &db, int err);
230
231
/* EventObserver data classes: */