60
58
class EventObserverList;
64
typedef std::vector<EventObserver *> EventObserverVector;
65
typedef EventObserver* EventObserverPtr;
67
62
class EventObserver : public Plugin
70
EventObserver(const EventObserver &);
71
EventObserver& operator=(const EventObserver &);
73
explicit EventObserver(std::string name_arg)
74
: Plugin(name_arg, "EventObserver")
76
virtual ~EventObserver() {}
80
BEFORE_CREATE_DATABASE, AFTER_CREATE_DATABASE,
81
BEFORE_DROP_DATABASE, AFTER_DROP_DATABASE,
88
BEFORE_DROP_TABLE, AFTER_DROP_TABLE,
89
BEFORE_RENAME_TABLE, AFTER_RENAME_TABLE,
92
BEFORE_INSERT_RECORD, AFTER_INSERT_RECORD,
93
BEFORE_UPDATE_RECORD, AFTER_UPDATE_RECORD,
94
BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD,
96
/* The max event ID marker. */
100
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,
79
BEFORE_DROP_TABLE, AFTER_DROP_TABLE,
80
BEFORE_RENAME_TABLE, AFTER_RENAME_TABLE,
83
BEFORE_INSERT_RECORD, AFTER_INSERT_RECORD,
84
BEFORE_UPDATE_RECORD, AFTER_UPDATE_RECORD,
85
BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD,
87
/* The max event ID marker. */
91
static const char *eventName(EventType event)
104
case BEFORE_DROP_TABLE:
105
return "BEFORE_DROP_TABLE";
107
case AFTER_DROP_TABLE:
108
return "AFTER_DROP_TABLE";
110
case BEFORE_RENAME_TABLE:
111
return "BEFORE_RENAME_TABLE";
113
case AFTER_RENAME_TABLE:
114
return "AFTER_RENAME_TABLE";
116
case BEFORE_INSERT_RECORD:
117
return "BEFORE_INSERT_RECORD";
119
case AFTER_INSERT_RECORD:
120
return "AFTER_INSERT_RECORD";
122
case BEFORE_UPDATE_RECORD:
123
return "BEFORE_UPDATE_RECORD";
125
case AFTER_UPDATE_RECORD:
126
return "AFTER_UPDATE_RECORD";
128
case BEFORE_DELETE_RECORD:
129
return "BEFORE_DELETE_RECORD";
131
case AFTER_DELETE_RECORD:
132
return "AFTER_DELETE_RECORD";
134
case BEFORE_CREATE_DATABASE:
135
return "BEFORE_CREATE_DATABASE";
137
case AFTER_CREATE_DATABASE:
138
return "AFTER_CREATE_DATABASE";
140
case BEFORE_DROP_DATABASE:
141
return "BEFORE_DROP_DATABASE";
143
case AFTER_DROP_DATABASE:
144
return "AFTER_DROP_DATABASE";
146
case CONNECT_SESSION:
147
return "CONNECT_SESSION";
149
case DISCONNECT_SESSION:
150
return "DISCONNECT_SESSION";
152
case AFTER_STATEMENT:
153
return "AFTER_STATEMENT";
155
case BEFORE_STATEMENT:
156
return "BEFORE_STATEMENT";
158
case MAX_EVENT_COUNT:
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:
165
/*==========================================================*/
166
/* registerEvents() must be implemented to allow the plugin to
167
* register which events it is interested in.
169
virtual void registerTableEventsDo(TableShare &, EventObserverList &){}
170
virtual void registerSchemaEventsDo(const std::string &/*db*/, EventObserverList &) {}
171
virtual void registerSessionEventsDo(Session &, EventObserverList &) {}
173
virtual bool observeEventDo(EventData &)= 0;
175
/*==========================================================*/
176
/* Static access methods called by drizzle: */
177
static bool addPlugin(EventObserver *handler);
178
static void removePlugin(EventObserver *handler);
180
/*==========================================================*/
181
/* Register an event of interest for this plugin.
182
* This is called from with in the plugin when registering itself.
184
* The position field is used to indicate the order the event observer is to be
185
* called. If the event observer must be called before any other observer then
186
* the position must be set to 1. If it must be called last then the position must be
187
* set to -1. A position of 0 indicated the position doesn't matter.
189
* If 2 plugins require the same position then which is called first in not guarenteed.
190
* In this case a warrning will be logged but execution will continue.
192
* It is good practice that if the event position matters not to hard code the position
193
* but supply a systen variable so that it can be set at runtime so that the user can
194
* decide which event should be called first.
196
void registerEvent(EventObserverList &observers, EventType event, int32_t position= 0);
198
/*==========================================================*/
199
/* Called from drizzle to register all events for all event plugins
200
* interested in this table.
202
static void registerTableEvents(TableShare &table_share);
203
static void deregisterTableEvents(TableShare &table_share);
205
/*==========================================================*/
206
/* Called from drizzle to register all events for all event plugins
207
* interested in this database.
209
static void registerSchemaEvents(Session &session, const std::string &db);
210
static void deregisterSchemaEvents(Session &session, const std::string &db);
212
/*==========================================================*/
213
/* Called from drizzle to register all events for all event plugins
214
* interested in this session.
216
static void registerSessionEvents(Session &session);
217
static void deregisterSessionEvents(Session &session);
220
/*==========================================================*/
221
/* Static meathods called by drizzle to notify interested plugins
222
* of a schema an event,
224
static bool beforeDropTable(Session &session, const drizzled::TableIdentifier &table);
225
static bool afterDropTable(Session &session, const drizzled::TableIdentifier &table, int err);
226
static bool beforeRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
227
static bool afterRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to, int err);
228
static bool connectSession(Session &session);
229
static bool disconnectSession(Session &session);
230
static bool beforeStatement(Session &session);
231
static bool afterStatement(Session &session);
233
/*==========================================================*/
234
/* Static meathods called by drizzle to notify interested plugins
235
* of a table an event,
237
static bool beforeInsertRecord(Table &table, unsigned char *buf);
238
static bool afterInsertRecord(Table &table, const unsigned char *buf, int err);
239
static bool beforeDeleteRecord(Table &table, const unsigned char *buf);
240
static bool afterDeleteRecord(Table &table, const unsigned char *buf, int err);
241
static bool beforeUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data);
242
static bool afterUpdateRecord(Table &table, const unsigned char *old_data, unsigned char *new_data, int err);
244
/*==========================================================*/
245
/* Static meathods called by drizzle to notify interested plugins
246
* of a table an event,
248
static bool beforeCreateDatabase(Session &session, const std::string &db);
249
static bool afterCreateDatabase(Session &session, const std::string &db, int err);
250
static bool beforeDropDatabase(Session &session, const std::string &db);
251
static bool afterDropDatabase(Session &session, const std::string &db, int err);
253
static const EventObserverVector &getEventObservers(void);
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, const drizzled::TableIdentifier &table);
204
static bool afterDropTable(Session &session, const drizzled::TableIdentifier &table, int err);
205
static bool beforeRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
206
static bool afterRenameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::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);
260
231
/* EventObserver data classes: */