58
58
class EventObserverList;
62
typedef std::vector<EventObserver *> EventObserverVector;
63
typedef EventObserver* EventObserverPtr;
62
65
class EventObserver : public Plugin
68
EventObserver(const EventObserver &);
69
EventObserver& operator=(const EventObserver &);
71
explicit EventObserver(std::string name_arg)
72
: Plugin(name_arg, "EventObserver")
74
virtual ~EventObserver() {}
78
BEFORE_CREATE_DATABASE, AFTER_CREATE_DATABASE,
79
BEFORE_DROP_DATABASE, AFTER_DROP_DATABASE,
86
BEFORE_DROP_TABLE, AFTER_DROP_TABLE,
87
BEFORE_RENAME_TABLE, AFTER_RENAME_TABLE,
90
BEFORE_INSERT_RECORD, AFTER_INSERT_RECORD,
91
BEFORE_UPDATE_RECORD, AFTER_UPDATE_RECORD,
92
BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD,
94
/* The max event ID marker. */
98
static const char *eventName(EventType event)
65
EventObserver(const EventObserver &);
66
EventObserver& operator=(const EventObserver &);
68
explicit EventObserver(std::string name_arg)
69
: Plugin(name_arg, "EventObserver")
71
virtual ~EventObserver() {}
75
BEFORE_CREATE_DATABASE, AFTER_CREATE_DATABASE,
76
BEFORE_DROP_DATABASE, AFTER_DROP_DATABASE,
83
BEFORE_DROP_TABLE, AFTER_DROP_TABLE,
84
BEFORE_RENAME_TABLE, AFTER_RENAME_TABLE,
87
BEFORE_INSERT_RECORD, AFTER_INSERT_RECORD,
88
BEFORE_UPDATE_RECORD, AFTER_UPDATE_RECORD,
89
BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD,
91
/* The max event ID marker. */
95
static const char *eventName(EventType event)
99
case BEFORE_DROP_TABLE:
100
return "BEFORE_DROP_TABLE";
102
case AFTER_DROP_TABLE:
103
return "AFTER_DROP_TABLE";
105
case BEFORE_RENAME_TABLE:
106
return "BEFORE_RENAME_TABLE";
108
case AFTER_RENAME_TABLE:
109
return "AFTER_RENAME_TABLE";
111
case BEFORE_INSERT_RECORD:
112
return "BEFORE_INSERT_RECORD";
114
case AFTER_INSERT_RECORD:
115
return "AFTER_INSERT_RECORD";
117
case BEFORE_UPDATE_RECORD:
118
return "BEFORE_UPDATE_RECORD";
120
case AFTER_UPDATE_RECORD:
121
return "AFTER_UPDATE_RECORD";
123
case BEFORE_DELETE_RECORD:
124
return "BEFORE_DELETE_RECORD";
126
case AFTER_DELETE_RECORD:
127
return "AFTER_DELETE_RECORD";
129
case BEFORE_CREATE_DATABASE:
130
return "BEFORE_CREATE_DATABASE";
132
case AFTER_CREATE_DATABASE:
133
return "AFTER_CREATE_DATABASE";
135
case BEFORE_DROP_DATABASE:
136
return "BEFORE_DROP_DATABASE";
138
case AFTER_DROP_DATABASE:
139
return "AFTER_DROP_DATABASE";
141
case CONNECT_SESSION:
142
return "CONNECT_SESSION";
144
case DISCONNECT_SESSION:
145
return "DISCONNECT_SESSION";
147
case AFTER_STATEMENT:
148
return "AFTER_STATEMENT";
150
case BEFORE_STATEMENT:
151
return "BEFORE_STATEMENT";
153
case MAX_EVENT_COUNT:
102
case BEFORE_DROP_TABLE:
103
return "BEFORE_DROP_TABLE";
105
case AFTER_DROP_TABLE:
106
return "AFTER_DROP_TABLE";
108
case BEFORE_RENAME_TABLE:
109
return "BEFORE_RENAME_TABLE";
111
case AFTER_RENAME_TABLE:
112
return "AFTER_RENAME_TABLE";
114
case BEFORE_INSERT_RECORD:
115
return "BEFORE_INSERT_RECORD";
117
case AFTER_INSERT_RECORD:
118
return "AFTER_INSERT_RECORD";
120
case BEFORE_UPDATE_RECORD:
121
return "BEFORE_UPDATE_RECORD";
123
case AFTER_UPDATE_RECORD:
124
return "AFTER_UPDATE_RECORD";
126
case BEFORE_DELETE_RECORD:
127
return "BEFORE_DELETE_RECORD";
129
case AFTER_DELETE_RECORD:
130
return "AFTER_DELETE_RECORD";
132
case BEFORE_CREATE_DATABASE:
133
return "BEFORE_CREATE_DATABASE";
135
case AFTER_CREATE_DATABASE:
136
return "AFTER_CREATE_DATABASE";
138
case BEFORE_DROP_DATABASE:
139
return "BEFORE_DROP_DATABASE";
141
case AFTER_DROP_DATABASE:
142
return "AFTER_DROP_DATABASE";
144
case CONNECT_SESSION:
145
return "CONNECT_SESSION";
147
case DISCONNECT_SESSION:
148
return "DISCONNECT_SESSION";
150
case AFTER_STATEMENT:
151
return "AFTER_STATEMENT";
153
case BEFORE_STATEMENT:
154
return "BEFORE_STATEMENT";
156
case MAX_EVENT_COUNT:
160
/*==========================================================*/
161
/* registerEvents() must be implemented to allow the plugin to
162
* register which events it is interested in.
164
virtual void registerTableEventsDo(TableShare &, EventObserverList &){}
165
virtual void registerSchemaEventsDo(const std::string &/*db*/, EventObserverList &) {}
166
virtual void registerSessionEventsDo(Session &, EventObserverList &) {}
168
virtual bool observeEventDo(EventData &)= 0;
170
/*==========================================================*/
171
/* Static access methods called by drizzle: */
172
static bool addPlugin(EventObserver *handler);
173
static void removePlugin(EventObserver *handler);
175
/*==========================================================*/
176
/* Register an event of interest for this plugin.
177
* This is called from with in the plugin when registering itself.
179
* The position field is used to indicate the order the event observer is to be
180
* called. If the event observer must be called before any other observer then
181
* the position must be set to 1. If it must be called last then the position must be
182
* set to -1. A position of 0 indicated the position doesn't matter.
184
* If 2 plugins require the same position then which is called first in not guarenteed.
185
* In this case a warrning will be logged but execution will continue.
187
* It is good practice that if the event position matters not to hard code the position
188
* but supply a systen variable so that it can be set at runtime so that the user can
189
* decide which event should be called first.
191
void registerEvent(EventObserverList &observers, EventType event, int32_t position= 0);
193
/*==========================================================*/
194
/* Called from drizzle to register all events for all event plugins
195
* interested in this table.
197
static void registerTableEvents(TableShare &table_share);
198
static void deregisterTableEvents(TableShare &table_share);
200
/*==========================================================*/
201
/* Called from drizzle to register all events for all event plugins
202
* interested in this database.
204
static void registerSchemaEvents(Session &session, const std::string &db);
205
static void deregisterSchemaEvents(Session &session, const std::string &db);
207
/*==========================================================*/
208
/* Called from drizzle to register all events for all event plugins
209
* interested in this session.
211
static void registerSessionEvents(Session &session);
212
static void deregisterSessionEvents(Session &session);
215
/*==========================================================*/
216
/* Static meathods called by drizzle to notify interested plugins
217
* of a schema an event,
219
static bool beforeDropTable(Session &session, const drizzled::TableIdentifier &table);
220
static bool afterDropTable(Session &session, const drizzled::TableIdentifier &table, int err);
221
static bool beforeRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
222
static bool afterRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to, int err);
223
static bool connectSession(Session &session);
224
static bool disconnectSession(Session &session);
225
static bool beforeStatement(Session &session);
226
static bool afterStatement(Session &session);
228
/*==========================================================*/
229
/* Static meathods called by drizzle to notify interested plugins
230
* of a table an event,
232
static bool beforeInsertRecord(Table &table, unsigned char *buf);
233
static bool afterInsertRecord(Table &table, const unsigned char *buf, int err);
234
static bool beforeDeleteRecord(Table &table, const unsigned char *buf);
235
static bool afterDeleteRecord(Table &table, const unsigned char *buf, int err);
236
static bool beforeUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data);
237
static bool afterUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data, int err);
239
/*==========================================================*/
240
/* Static meathods called by drizzle to notify interested plugins
241
* of a table an event,
243
static bool beforeCreateDatabase(Session &session, const std::string &db);
244
static bool afterCreateDatabase(Session &session, const std::string &db, int err);
245
static bool beforeDropDatabase(Session &session, const std::string &db);
246
static bool afterDropDatabase(Session &session, const std::string &db, int err);
163
/*==========================================================*/
164
/* registerEvents() must be implemented to allow the plugin to
165
* register which events it is interested in.
167
virtual void registerTableEventsDo(TableShare &, EventObserverList &){}
168
virtual void registerSchemaEventsDo(const std::string &/*db*/, EventObserverList &) {}
169
virtual void registerSessionEventsDo(Session &, EventObserverList &) {}
171
virtual bool observeEventDo(EventData &)= 0;
173
/*==========================================================*/
174
/* Static access methods called by drizzle: */
175
static bool addPlugin(EventObserver *handler);
176
static void removePlugin(EventObserver *handler);
178
/*==========================================================*/
179
/* Register an event of interest for this plugin.
180
* This is called from with in the plugin when registering itself.
182
* The position field is used to indicate the order the event observer is to be
183
* called. If the event observer must be called before any other observer then
184
* the position must be set to 1. If it must be called last then the position must be
185
* set to -1. A position of 0 indicated the position doesn't matter.
187
* If 2 plugins require the same position then which is called first in not guarenteed.
188
* In this case a warrning will be logged but execution will continue.
190
* It is good practice that if the event position matters not to hard code the position
191
* but supply a systen variable so that it can be set at runtime so that the user can
192
* decide which event should be called first.
194
void registerEvent(EventObserverList &observers, EventType event, int32_t position= 0);
196
/*==========================================================*/
197
/* Called from drizzle to register all events for all event plugins
198
* interested in this table.
200
static void registerTableEvents(TableShare &table_share);
201
static void deregisterTableEvents(TableShare &table_share);
203
/*==========================================================*/
204
/* Called from drizzle to register all events for all event plugins
205
* interested in this database.
207
static void registerSchemaEvents(Session &session, const std::string &db);
208
static void deregisterSchemaEvents(Session &session, const std::string &db);
210
/*==========================================================*/
211
/* Called from drizzle to register all events for all event plugins
212
* interested in this session.
214
static void registerSessionEvents(Session &session);
215
static void deregisterSessionEvents(Session &session);
218
/*==========================================================*/
219
/* Static meathods called by drizzle to notify interested plugins
220
* of a schema an event,
222
static bool beforeDropTable(Session &session, const drizzled::TableIdentifier &table);
223
static bool afterDropTable(Session &session, const drizzled::TableIdentifier &table, int err);
224
static bool beforeRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
225
static bool afterRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to, int err);
226
static bool connectSession(Session &session);
227
static bool disconnectSession(Session &session);
228
static bool beforeStatement(Session &session);
229
static bool afterStatement(Session &session);
231
/*==========================================================*/
232
/* Static meathods called by drizzle to notify interested plugins
233
* of a table an event,
235
static bool beforeInsertRecord(Table &table, unsigned char *buf);
236
static bool afterInsertRecord(Table &table, const unsigned char *buf, int err);
237
static bool beforeDeleteRecord(Table &table, const unsigned char *buf);
238
static bool afterDeleteRecord(Table &table, const unsigned char *buf, int err);
239
static bool beforeUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data);
240
static bool afterUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data, int err);
242
/*==========================================================*/
243
/* Static meathods called by drizzle to notify interested plugins
244
* of a table an event,
246
static bool beforeCreateDatabase(Session &session, const std::string &db);
247
static bool afterCreateDatabase(Session &session, const std::string &db, int err);
248
static bool beforeDropDatabase(Session &session, const std::string &db);
249
static bool afterDropDatabase(Session &session, const std::string &db, int err);
251
static const EventObserverVector &getEventObservers(void);
251
258
/* EventObserver data classes: */