1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
1 |
/*
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
2 |
* Copyright (C) 2010 PrimeBase Technologies GmbH, Germany
|
3 |
*
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
6 |
* the Free Software Foundation; version 2 of the License.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* along with this program; if not, write to the Free Software
|
|
15 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1502.5.9
by Barry.Leslie at PrimeBase
- Cleaned up some style points. |
16 |
*
|
17 |
* Barry Leslie
|
|
18 |
*
|
|
19 |
* 2010-05-12
|
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
20 |
*/
|
21 |
||
22 |
/**
|
|
23 |
* @details
|
|
24 |
*
|
|
25 |
* This plugin is an example events plugin that just prints some info for
|
|
26 |
* the events that it is tracking.
|
|
27 |
*
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
28 |
set global hello_events1_enable = ON;
|
29 |
set global hello_events1_watch_databases = "x";
|
|
30 |
set global hello_events1_watch_tables = "x,y";
|
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
31 |
|
32 |
*/
|
|
33 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
34 |
#include <config.h> |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
35 |
#include <string> |
1530.5.10
by Monty Taylor
Fixed build errors on FreeBSD. |
36 |
#include <cstdio> |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
37 |
#include <boost/program_options.hpp> |
2234.1.1
by Olaf van der Spek
Refactor includes |
38 |
#include <drizzled/item.h> |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
39 |
#include <drizzled/module/option_map.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
40 |
#include <drizzled/session.h> |
2234.1.1
by Olaf van der Spek
Refactor includes |
41 |
#include <drizzled/table/instance/base.h> |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
42 |
#include "hello_events.h" |
2239.1.6
by Olaf van der Spek
Refactor includes |
43 |
#include <drizzled/plugin.h> |
1964.2.21
by Monty Taylor
hello_events. |
44 |
|
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
45 |
namespace po= boost::program_options; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
46 |
using namespace drizzled; |
47 |
using namespace plugin; |
|
48 |
using namespace std; |
|
49 |
||
1502.5.5
by Barry.Leslie at PrimeBase
Added the ability to position the order in which event observers are called |
50 |
#define PLUGIN_NAME "hello_events1"
|
51 |
||
1964.2.21
by Monty Taylor
hello_events. |
52 |
static bool sysvar_hello_events_enabled; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
53 |
static HelloEvents *hello_events= NULL; |
1964.2.21
by Monty Taylor
hello_events. |
54 |
static string sysvar_db_list; |
55 |
static string sysvar_table_list; |
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
56 |
|
57 |
/*
|
|
58 |
* Event observer positions are used to set the order in which
|
|
59 |
* event observers are called in the case that more than one
|
|
60 |
* plugin is interested in the same event. You should only specify
|
|
61 |
* the order if it really matters because if more than one plugin
|
|
62 |
* request the same calling position only the first one gets it and
|
|
63 |
* the others will not be registered for the event. For this reason
|
|
64 |
* your plugin should always provide a way to reposition the event
|
|
65 |
* observer to resolve such conflicts.
|
|
66 |
*
|
|
67 |
* If position matters you will always initialy ask for the first position (1)
|
|
68 |
* or the last position (-1) in the calling order, for example it makes no sence
|
|
69 |
* to initially ask to be called in position 13.
|
|
70 |
*/
|
|
1964.2.21
by Monty Taylor
hello_events. |
71 |
typedef constrained_check<uint64_t, INT32_MAX-1, 1> position_constraint; |
72 |
typedef constrained_check<int32_t, -1, INT32_MIN+1> post_drop_constraint; |
|
73 |
||
74 |
static position_constraint sysvar_before_write_position; // Call this event observer first. |
|
75 |
static position_constraint sysvar_before_update_position; |
|
76 |
static post_drop_constraint sysvar_post_drop_db_position; // I want my event observer to be called last. No reason, I just do! |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
77 |
|
78 |
||
79 |
//==================================
|
|
80 |
// My table event observers:
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
81 |
static bool observeBeforeInsertRecord(BeforeInsertRecordEventData &data) |
82 |
{
|
|
83 |
||
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
84 |
static int count= 0; |
85 |
count++; |
|
86 |
data.session.setVariable("BEFORE_INSERT_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
87 |
return false; |
88 |
}
|
|
89 |
||
90 |
//---
|
|
91 |
static void observeAfterInsertRecord(AfterInsertRecordEventData &data) |
|
92 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
93 |
static int count= 0; |
94 |
count++; |
|
95 |
data.session.setVariable("AFTER_INSERT_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
96 |
}
|
97 |
||
98 |
//---
|
|
99 |
static bool observeBeforeDeleteRecord(BeforeDeleteRecordEventData &data) |
|
100 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
101 |
static int count= 0; |
102 |
count++; |
|
103 |
data.session.setVariable("AFTER_DELETE_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
104 |
return false; |
105 |
}
|
|
106 |
||
107 |
//---
|
|
108 |
static void observeAfterDeleteRecord(AfterDeleteRecordEventData &data) |
|
109 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
110 |
static int count= 0; |
111 |
count++; |
|
112 |
data.session.setVariable("AFTER_DELETE_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
113 |
}
|
114 |
||
115 |
//---
|
|
116 |
static bool observeBeforeUpdateRecord(BeforeUpdateRecordEventData &data) |
|
117 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
118 |
static int count= 0; |
119 |
count++; |
|
120 |
data.session.setVariable("BEFORE_UPDATE_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
121 |
return false; |
122 |
}
|
|
123 |
||
124 |
//---
|
|
125 |
static void observeAfterUpdateRecord(AfterUpdateRecordEventData &data) |
|
126 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
127 |
static int count= 0; |
128 |
count++; |
|
129 |
data.session.setVariable("AFTER_UPDATE_RECORD", boost::lexical_cast<std::string>(count)); |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
130 |
}
|
131 |
||
132 |
//==================================
|
|
133 |
// My schema event observers:
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
134 |
static void observeAfterDropTable(AfterDropTableEventData &data) |
135 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
136 |
static int count= 0; |
137 |
count++; |
|
138 |
data.session.setVariable("AFTER_DROP_TABLE", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
139 |
}
|
140 |
||
141 |
//---
|
|
142 |
static void observeAfterRenameTable(AfterRenameTableEventData &data) |
|
143 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
144 |
static int count= 0; |
145 |
count++; |
|
146 |
data.session.setVariable("AFTER_RENAME_TABLE", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
147 |
}
|
148 |
||
149 |
//---
|
|
150 |
static void observeAfterCreateDatabase(AfterCreateDatabaseEventData &data) |
|
151 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
152 |
static int count= 0; |
153 |
count++; |
|
154 |
data.session.setVariable("AFTER_CREATE_DATABASE", boost::lexical_cast<std::string>(count)); |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
155 |
}
|
156 |
||
157 |
//---
|
|
158 |
static void observeAfterDropDatabase(AfterDropDatabaseEventData &data) |
|
159 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
160 |
static int count= 0; |
161 |
count++; |
|
162 |
data.session.setVariable("AFTER_DROP_DATABASE", boost::lexical_cast<std::string>(count)); |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
163 |
}
|
164 |
||
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
165 |
//---
|
166 |
static void observeConnectSession(ConnectSessionEventData &data) |
|
167 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
168 |
static int count= 0; |
169 |
count++; |
|
170 |
data.session.setVariable("CONNECT_SESSION", boost::lexical_cast<std::string>(count)); |
|
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
171 |
}
|
172 |
||
173 |
//---
|
|
174 |
static void observeDisconnectSession(DisconnectSessionEventData &data) |
|
175 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
176 |
static int count= 0; |
177 |
count++; |
|
178 |
data.session.setVariable("DISCONNECT_SESSION", boost::lexical_cast<std::string>(count)); |
|
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
179 |
}
|
180 |
||
181 |
//---
|
|
182 |
static void observeBeforeStatement(BeforeStatementEventData &data) |
|
183 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
184 |
static int count= 0; |
185 |
count++; |
|
186 |
data.session.setVariable("BEFORE_STATEMENT", boost::lexical_cast<std::string>(count)); |
|
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
187 |
}
|
188 |
||
189 |
//---
|
|
190 |
static void observeAfterStatement(AfterStatementEventData &data) |
|
191 |
{
|
|
1836.4.1
by Brian Aker
Adding in more test case for events (though these do not really have the |
192 |
static int count= 0; |
193 |
count++; |
|
194 |
data.session.setVariable("AFTER_STATEMENT", boost::lexical_cast<std::string>(count)); |
|
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
195 |
}
|
196 |
||
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
197 |
HelloEvents::~HelloEvents() |
1964.2.21
by Monty Taylor
hello_events. |
198 |
{ } |
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
199 |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
200 |
//==================================
|
201 |
/* This is where I register which table events my pluggin is interested in.*/
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
202 |
void HelloEvents::registerTableEventsDo(TableShare &table_share, EventObserverList &observers) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
203 |
{
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
204 |
if ((is_enabled == false) |
205 |
|| !isTableInteresting(table_share.getTableName()) |
|
206 |
|| !isDatabaseInteresting(table_share.getSchemaName())) |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
207 |
return; |
208 |
||
1964.2.21
by Monty Taylor
hello_events. |
209 |
registerEvent(observers, BEFORE_INSERT_RECORD, sysvar_before_write_position.get()); |
210 |
// I want to be called first if passible
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
211 |
registerEvent(observers, AFTER_INSERT_RECORD); |
1964.2.21
by Monty Taylor
hello_events. |
212 |
registerEvent(observers, BEFORE_UPDATE_RECORD, sysvar_before_update_position.get()); |
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
213 |
registerEvent(observers, AFTER_UPDATE_RECORD); |
214 |
registerEvent(observers, BEFORE_DELETE_RECORD); |
|
215 |
registerEvent(observers, AFTER_DELETE_RECORD); |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
216 |
}
|
217 |
||
218 |
//==================================
|
|
219 |
/* This is where I register which schema events my pluggin is interested in.*/
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
220 |
void HelloEvents::registerSchemaEventsDo(const std::string &db, EventObserverList &observers) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
221 |
{
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
222 |
if ((is_enabled == false) |
223 |
|| !isDatabaseInteresting(db)) |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
224 |
return; |
225 |
||
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
226 |
registerEvent(observers, AFTER_DROP_TABLE); |
227 |
registerEvent(observers, AFTER_RENAME_TABLE); |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
228 |
}
|
229 |
||
230 |
//==================================
|
|
231 |
/* This is where I register which session events my pluggin is interested in.*/
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
232 |
void HelloEvents::registerSessionEventsDo(Session &session, EventObserverList &observers) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
233 |
{
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
234 |
if ((is_enabled == false) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
235 |
|| !isSessionInteresting(session)) |
236 |
return; |
|
237 |
||
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
238 |
registerEvent(observers, AFTER_CREATE_DATABASE); |
1964.2.21
by Monty Taylor
hello_events. |
239 |
registerEvent(observers, AFTER_DROP_DATABASE, sysvar_post_drop_db_position.get()); |
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
240 |
registerEvent(observers, DISCONNECT_SESSION); |
241 |
registerEvent(observers, CONNECT_SESSION); |
|
242 |
registerEvent(observers, BEFORE_STATEMENT); |
|
243 |
registerEvent(observers, AFTER_STATEMENT); |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
244 |
}
|
245 |
||
246 |
||
247 |
//==================================
|
|
248 |
/* The event observer.*/
|
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
249 |
bool HelloEvents::observeEventDo(EventData &data) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
250 |
{
|
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
251 |
switch (data.event) { |
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
252 |
case AFTER_DROP_TABLE: |
253 |
observeAfterDropTable((AfterDropTableEventData &)data); |
|
254 |
break; |
|
255 |
||
256 |
case AFTER_RENAME_TABLE: |
|
257 |
observeAfterRenameTable((AfterRenameTableEventData &)data); |
|
258 |
break; |
|
259 |
||
260 |
case BEFORE_INSERT_RECORD: |
|
2253.1.1
by Andrew Hutchings
Fix Drizzle to compile in GCC 4.6 (which fires warnings and therefore errors if a variable is set and not read) |
261 |
observeBeforeInsertRecord((BeforeInsertRecordEventData &)data); |
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
262 |
break; |
263 |
||
264 |
case AFTER_INSERT_RECORD: |
|
265 |
observeAfterInsertRecord((AfterInsertRecordEventData &)data); |
|
1502.5.6
by Barry.Leslie at PrimeBase
Fixed a compiler error due to an uninitialized variavble and cleaned up some coding standard stuff. |
266 |
break; |
267 |
||
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
268 |
case BEFORE_UPDATE_RECORD: |
2253.1.1
by Andrew Hutchings
Fix Drizzle to compile in GCC 4.6 (which fires warnings and therefore errors if a variable is set and not read) |
269 |
observeBeforeUpdateRecord((BeforeUpdateRecordEventData &)data); |
1502.5.6
by Barry.Leslie at PrimeBase
Fixed a compiler error due to an uninitialized variavble and cleaned up some coding standard stuff. |
270 |
break; |
271 |
||
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
272 |
case AFTER_UPDATE_RECORD: |
273 |
observeAfterUpdateRecord((AfterUpdateRecordEventData &)data); |
|
1502.5.6
by Barry.Leslie at PrimeBase
Fixed a compiler error due to an uninitialized variavble and cleaned up some coding standard stuff. |
274 |
break; |
275 |
||
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
276 |
case BEFORE_DELETE_RECORD: |
2253.1.1
by Andrew Hutchings
Fix Drizzle to compile in GCC 4.6 (which fires warnings and therefore errors if a variable is set and not read) |
277 |
observeBeforeDeleteRecord((BeforeDeleteRecordEventData &)data); |
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
278 |
break; |
279 |
||
280 |
case AFTER_DELETE_RECORD: |
|
281 |
observeAfterDeleteRecord((AfterDeleteRecordEventData &)data); |
|
282 |
break; |
|
283 |
||
284 |
case AFTER_CREATE_DATABASE: |
|
285 |
observeAfterCreateDatabase((AfterCreateDatabaseEventData &)data); |
|
286 |
break; |
|
287 |
||
288 |
case AFTER_DROP_DATABASE: |
|
289 |
observeAfterDropDatabase((AfterDropDatabaseEventData &)data); |
|
1502.5.6
by Barry.Leslie at PrimeBase
Fixed a compiler error due to an uninitialized variavble and cleaned up some coding standard stuff. |
290 |
break; |
291 |
||
1836
by Brian Aker
Added support for pre/post triggers (this removes the need for the current |
292 |
case CONNECT_SESSION: |
293 |
observeConnectSession((ConnectSessionEventData &)data); |
|
294 |
break; |
|
295 |
||
296 |
case DISCONNECT_SESSION: |
|
297 |
observeDisconnectSession((DisconnectSessionEventData &)data); |
|
298 |
break; |
|
299 |
||
300 |
case BEFORE_STATEMENT: |
|
301 |
observeBeforeStatement((BeforeStatementEventData &)data); |
|
302 |
break; |
|
303 |
||
304 |
case AFTER_STATEMENT: |
|
305 |
observeAfterStatement((AfterStatementEventData &)data); |
|
306 |
break; |
|
307 |
||
1502.5.6
by Barry.Leslie at PrimeBase
Fixed a compiler error due to an uninitialized variavble and cleaned up some coding standard stuff. |
308 |
default: |
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
309 |
fprintf(stderr, "HelloEvents: Unexpected event '%s'\n", EventObserver::eventName(data.event)); |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
310 |
|
311 |
}
|
|
312 |
||
313 |
return false; |
|
314 |
}
|
|
315 |
||
316 |
//==================================
|
|
317 |
// Some custom things for my plugin:
|
|
318 |
||
319 |
||
320 |
/* Plugin initialization and system variables */
|
|
1502.5.5
by Barry.Leslie at PrimeBase
Added the ability to position the order in which event observers are called |
321 |
|
1964.2.21
by Monty Taylor
hello_events. |
322 |
static void enable(Session*, sql_var_t) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
323 |
{
|
324 |
if (hello_events) |
|
325 |
{
|
|
1964.2.21
by Monty Taylor
hello_events. |
326 |
if (sysvar_hello_events_enabled) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
327 |
{
|
328 |
hello_events->enable(); |
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
hello_events->disable(); |
|
333 |
}
|
|
334 |
}
|
|
335 |
}
|
|
336 |
||
337 |
||
1964.2.21
by Monty Taylor
hello_events. |
338 |
static int set_db_list(Session *, set_var *var) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
339 |
{
|
1964.2.21
by Monty Taylor
hello_events. |
340 |
const char *db_list= var->value->str_value.ptr(); |
341 |
if (db_list == NULL) |
|
342 |
return 1; |
|
343 |
||
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
344 |
if (hello_events) |
345 |
{
|
|
1964.2.21
by Monty Taylor
hello_events. |
346 |
hello_events->setDatabasesOfInterest(db_list); |
2318.7.23
by Olaf van der Spek
Use operator= |
347 |
sysvar_db_list= db_list; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
348 |
}
|
1964.2.21
by Monty Taylor
hello_events. |
349 |
return 0; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
350 |
}
|
351 |
||
1964.2.21
by Monty Taylor
hello_events. |
352 |
static int set_table_list(Session *, set_var *var) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
353 |
{
|
1964.2.21
by Monty Taylor
hello_events. |
354 |
const char *table_list= var->value->str_value.ptr(); |
355 |
if (table_list == NULL) |
|
356 |
return 1; |
|
357 |
||
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
358 |
if (hello_events) |
359 |
{
|
|
1964.2.21
by Monty Taylor
hello_events. |
360 |
hello_events->setTablesOfInterest(table_list); |
2318.7.23
by Olaf van der Spek
Use operator= |
361 |
sysvar_table_list= table_list; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
362 |
}
|
1964.2.21
by Monty Taylor
hello_events. |
363 |
return 0; |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
364 |
}
|
365 |
||
366 |
||
1530.4.2
by Monty Taylor
Merged up with event work. |
367 |
static int init(module::Context &context) |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
368 |
{
|
1502.5.5
by Barry.Leslie at PrimeBase
Added the ability to position the order in which event observers are called |
369 |
hello_events= new HelloEvents(PLUGIN_NAME); |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
370 |
|
371 |
context.add(hello_events); |
|
372 |
||
373 |
if (sysvar_hello_events_enabled) |
|
374 |
{
|
|
375 |
hello_events->enable(); |
|
376 |
}
|
|
377 |
||
1964.2.21
by Monty Taylor
hello_events. |
378 |
context.registerVariable(new sys_var_bool_ptr("enable", |
379 |
&sysvar_hello_events_enabled, |
|
380 |
enable)); |
|
381 |
context.registerVariable(new sys_var_std_string("watch_databases", |
|
382 |
sysvar_db_list, |
|
383 |
set_db_list)); |
|
384 |
context.registerVariable(new sys_var_std_string("watch_tables", |
|
385 |
sysvar_table_list, |
|
386 |
set_table_list)); |
|
387 |
context.registerVariable(new sys_var_constrained_value<uint64_t>("before_write_position", |
|
388 |
sysvar_before_write_position)); |
|
389 |
context.registerVariable(new sys_var_constrained_value<uint64_t>("before_update_position", |
|
390 |
sysvar_before_update_position)); |
|
391 |
context.registerVariable(new sys_var_constrained_value<int32_t>("post_drop_position", |
|
392 |
sysvar_post_drop_db_position)); |
|
393 |
||
394 |
||
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
395 |
return 0; |
396 |
}
|
|
397 |
||
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
398 |
static void init_options(drizzled::module::option_context &context) |
399 |
{
|
|
400 |
context("enable", |
|
401 |
po::value<bool>(&sysvar_hello_events_enabled)->default_value(false)->zero_tokens(), |
|
402 |
N_("Enable Example Events Plugin")); |
|
1964.2.21
by Monty Taylor
hello_events. |
403 |
context("watch-databases", |
404 |
po::value<string>(&sysvar_db_list)->default_value(""), |
|
405 |
N_("A comma delimited list of databases to watch")); |
|
406 |
context("watch-tables", |
|
407 |
po::value<string>(&sysvar_table_list)->default_value(""), |
|
408 |
N_("A comma delimited list of databases to watch")); |
|
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
409 |
context("before-write-position", |
1964.2.21
by Monty Taylor
hello_events. |
410 |
po::value<position_constraint>(&sysvar_before_write_position)->default_value(1), |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
411 |
N_("Before write row event observer call position")); |
412 |
context("before-update-position", |
|
1964.2.21
by Monty Taylor
hello_events. |
413 |
po::value<position_constraint>(&sysvar_before_update_position)->default_value(1), |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
414 |
N_("Before update row event observer call position")); |
415 |
context("post-drop-db-position", |
|
1964.2.21
by Monty Taylor
hello_events. |
416 |
po::value<post_drop_constraint>(&sysvar_post_drop_db_position)->default_value(-1), |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
417 |
N_("After drop database event observer call position")); |
418 |
}
|
|
419 |
||
1964.2.21
by Monty Taylor
hello_events. |
420 |
|
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
421 |
|
422 |
DRIZZLE_DECLARE_PLUGIN
|
|
423 |
{
|
|
424 |
DRIZZLE_VERSION_ID, |
|
1502.5.5
by Barry.Leslie at PrimeBase
Added the ability to position the order in which event observers are called |
425 |
PLUGIN_NAME, |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
426 |
"0.1", |
427 |
"Barry Leslie", |
|
428 |
N_("An example events Plugin"), |
|
429 |
PLUGIN_LICENSE_BSD, |
|
430 |
init, /* Plugin Init */ |
|
2095.3.1
by Monty Taylor
Re-purpose the old plugin sysvar slot in the struct to be a depends list. |
431 |
NULL, /* depends */ |
1660.4.1
by Vijay Samuel
Merge refactored commandline for hello_events using boost::program_options |
432 |
init_options /* config options */ |
1502.5.4
by Barry.Leslie at PrimeBase
Added a demo plugin based on the the events plugin API. |
433 |
}
|
434 |
DRIZZLE_DECLARE_PLUGIN_END; |