ruby-binlog 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +28 -0
- data/ext/Makefile +157 -0
- data/ext/binlog.so +0 -0
- data/ext/extconf.rb +5 -0
- data/ext/mkmf.log +24 -0
- data/ext/ruby_binlog.cpp +276 -0
- data/ext/ruby_binlog.h +33 -0
- data/ext/ruby_binlog.o +0 -0
- data/ext/ruby_binlog_event.cpp +67 -0
- data/ext/ruby_binlog_event.h +163 -0
- data/ext/ruby_binlog_event.o +0 -0
- data/ext/ruby_binlog_format_event.cpp +74 -0
- data/ext/ruby_binlog_format_event.o +0 -0
- data/ext/ruby_binlog_incident_event.cpp +59 -0
- data/ext/ruby_binlog_incident_event.o +0 -0
- data/ext/ruby_binlog_int_var_event.cpp +59 -0
- data/ext/ruby_binlog_int_var_event.o +0 -0
- data/ext/ruby_binlog_query_event.cpp +95 -0
- data/ext/ruby_binlog_query_event.o +0 -0
- data/ext/ruby_binlog_rotate_event.cpp +59 -0
- data/ext/ruby_binlog_rotate_event.o +0 -0
- data/ext/ruby_binlog_row_event.cpp +118 -0
- data/ext/ruby_binlog_row_event.o +0 -0
- data/ext/ruby_binlog_table_map_event.cpp +118 -0
- data/ext/ruby_binlog_table_map_event.o +0 -0
- data/ext/ruby_binlog_unimplemented_event.cpp +44 -0
- data/ext/ruby_binlog_unimplemented_event.o +0 -0
- data/ext/ruby_binlog_user_var_event.cpp +80 -0
- data/ext/ruby_binlog_user_var_event.o +0 -0
- data/ext/ruby_binlog_xid_event.cpp +52 -0
- data/ext/ruby_binlog_xid_event.o +0 -0
- metadata +96 -0
data/README
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= ruby-binlog
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
ruby-binlog is Ruby binding for MySQL Binary log API.
|
6
|
+
|
7
|
+
see http://www.oscon.com/oscon2011/public/schedule/detail/18785
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
gem install ruby-binlog
|
12
|
+
|
13
|
+
== Example
|
14
|
+
|
15
|
+
require "binlog"
|
16
|
+
|
17
|
+
client = Binlog::Client.new("mysql://repl:repl@nyarlathotep")
|
18
|
+
client.connect
|
19
|
+
client.position = 4
|
20
|
+
|
21
|
+
while event = client.wait_for_next_event
|
22
|
+
case event
|
23
|
+
when Binlog::QueryEvent
|
24
|
+
puts event.query
|
25
|
+
else
|
26
|
+
puts "(#{event.event_type})"
|
27
|
+
end
|
28
|
+
end
|
data/ext/Makefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /usr/lib64/ruby/1.8/x86_64-linux
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/usr
|
11
|
+
exec_prefix = $(DESTDIR)/usr
|
12
|
+
vendorarchdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
|
13
|
+
vendordir = $(DESTDIR)/usr/lib/ruby
|
14
|
+
sitearchdir = $(libdir)/ruby/site_ruby/$(ruby_version)/$(sitearch)
|
15
|
+
localedir = $(datarootdir)/locale
|
16
|
+
dvidir = $(docdir)
|
17
|
+
datadir = $(DESTDIR)/usr/share
|
18
|
+
rubylibdir = $(vendordir)/$(ruby_version)
|
19
|
+
bindir = $(DESTDIR)/usr/bin
|
20
|
+
sharedstatedir = $(DESTDIR)/var/lib
|
21
|
+
libexecdir = $(DESTDIR)/usr/libexec
|
22
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
23
|
+
oldincludedir = $(DESTDIR)/usr/include
|
24
|
+
sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby
|
25
|
+
mandir = $(DESTDIR)/usr/share/man
|
26
|
+
datarootdir = $(prefix)/share
|
27
|
+
htmldir = $(docdir)
|
28
|
+
pdfdir = $(docdir)
|
29
|
+
localstatedir = $(DESTDIR)/var
|
30
|
+
includedir = $(DESTDIR)/usr/include
|
31
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
32
|
+
sysconfdir = $(DESTDIR)/etc
|
33
|
+
psdir = $(docdir)
|
34
|
+
libdir = $(DESTDIR)/usr/lib64
|
35
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
36
|
+
archdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
|
37
|
+
infodir = $(DESTDIR)/usr/share/info
|
38
|
+
sbindir = $(DESTDIR)/usr/sbin
|
39
|
+
|
40
|
+
CC = gcc
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fno-stack-protector -fPIC $(cflags)
|
48
|
+
INCFLAGS = -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.
|
49
|
+
DEFS =
|
50
|
+
CPPFLAGS =
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L. -rdynamic -Wl,-export-dynamic
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = $(CC) -shared
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby
|
61
|
+
RUBY_SO_NAME = ruby
|
62
|
+
arch = x86_64-linux
|
63
|
+
sitearch = x86_64-linux
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /usr/bin/ruby
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lreplication -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc
|
90
|
+
SRCS = ruby_binlog_xid_event.cpp ruby_binlog_rotate_event.cpp ruby_binlog_format_event.cpp ruby_binlog_user_var_event.cpp ruby_binlog.cpp ruby_binlog_table_map_event.cpp ruby_binlog_row_event.cpp ruby_binlog_event.cpp ruby_binlog_query_event.cpp ruby_binlog_unimplemented_event.cpp ruby_binlog_int_var_event.cpp ruby_binlog_incident_event.cpp
|
91
|
+
OBJS = ruby_binlog_xid_event.o ruby_binlog_rotate_event.o ruby_binlog_format_event.o ruby_binlog_user_var_event.o ruby_binlog.o ruby_binlog_table_map_event.o ruby_binlog_row_event.o ruby_binlog_event.o ruby_binlog_query_event.o ruby_binlog_unimplemented_event.o ruby_binlog_int_var_event.o ruby_binlog_incident_event.o
|
92
|
+
TARGET = binlog
|
93
|
+
DLLIB = $(TARGET).so
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS) Makefile
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/ext/binlog.so
ADDED
Binary file
|
data/ext/extconf.rb
ADDED
data/ext/mkmf.log
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
have_library: checking for main() in -lstdc++... -------------------- yes
|
2
|
+
|
3
|
+
"gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fno-stack-protector -fPIC conftest.c -L. -L/usr/lib64 -L. -rdynamic -Wl,-export-dynamic -lruby -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc"
|
4
|
+
checked program was:
|
5
|
+
/* begin */
|
6
|
+
1: /*top*/
|
7
|
+
2: int main() { return 0; }
|
8
|
+
3: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
9
|
+
/* end */
|
10
|
+
|
11
|
+
--------------------
|
12
|
+
|
13
|
+
have_library: checking for main() in -lreplication... -------------------- yes
|
14
|
+
|
15
|
+
"gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fno-stack-protector -fPIC conftest.c -L. -L/usr/lib64 -L. -rdynamic -Wl,-export-dynamic -lstdc++ -lruby -lreplication -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc"
|
16
|
+
checked program was:
|
17
|
+
/* begin */
|
18
|
+
1: /*top*/
|
19
|
+
2: int main() { return 0; }
|
20
|
+
3: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
21
|
+
/* end */
|
22
|
+
|
23
|
+
--------------------
|
24
|
+
|
data/ext/ruby_binlog.cpp
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
#include "ruby_binlog.h"
|
2
|
+
|
3
|
+
extern VALUE rb_cBinlogQueryEvent;
|
4
|
+
extern VALUE rb_cBinlogRotateEvent;
|
5
|
+
extern VALUE rb_cBinlogFormatEvent;
|
6
|
+
extern VALUE rb_cBinlogUserVarEvent;
|
7
|
+
extern VALUE rb_cBinlogTableMapEvent;
|
8
|
+
extern VALUE rb_cBinlogRowEvent;
|
9
|
+
extern VALUE rb_cBinlogIntVarEvent;
|
10
|
+
extern VALUE rb_cBinlogIncidentEvent;
|
11
|
+
extern VALUE rb_cBinlogXid;
|
12
|
+
extern VALUE rb_cBinlogUnimplementedEvent;
|
13
|
+
|
14
|
+
namespace ruby {
|
15
|
+
namespace binlog {
|
16
|
+
|
17
|
+
struct Client {
|
18
|
+
Binary_log *m_binlog;
|
19
|
+
|
20
|
+
static void free(Client *p) {
|
21
|
+
if (p->m_binlog) {
|
22
|
+
delete p->m_binlog;
|
23
|
+
p->m_binlog = 0;
|
24
|
+
}
|
25
|
+
|
26
|
+
delete p;
|
27
|
+
}
|
28
|
+
|
29
|
+
static VALUE alloc(VALUE klass) {
|
30
|
+
Client *p = new Client();
|
31
|
+
return Data_Wrap_Struct(klass, 0, &free, p);
|
32
|
+
}
|
33
|
+
|
34
|
+
static VALUE initialize(VALUE self, VALUE uri) {
|
35
|
+
Client *p;
|
36
|
+
|
37
|
+
Check_Type(uri, T_STRING);
|
38
|
+
Data_Get_Struct(self, Client, p);
|
39
|
+
p->m_binlog = new mysql::Binary_log(
|
40
|
+
mysql::system::create_transport(StringValuePtr(uri)));
|
41
|
+
|
42
|
+
return Qnil;
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE connect(VALUE self) {
|
46
|
+
Client *p;
|
47
|
+
int result;
|
48
|
+
|
49
|
+
Data_Get_Struct(self, Client, p);
|
50
|
+
result = p->m_binlog->connect();
|
51
|
+
|
52
|
+
return (result == 0) ? Qtrue : Qfalse;
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE wait_for_next_event(VALUE self) {
|
56
|
+
Client *p;
|
57
|
+
Binary_log_event *event;
|
58
|
+
int result;
|
59
|
+
VALUE retval = Qnil;
|
60
|
+
|
61
|
+
Data_Get_Struct(self, Client, p);
|
62
|
+
|
63
|
+
TRAP_BEG;
|
64
|
+
result = p->m_binlog->wait_for_next_event(&event);
|
65
|
+
TRAP_END;
|
66
|
+
|
67
|
+
if (result == ERR_EOF) {
|
68
|
+
return Qfalse;
|
69
|
+
}
|
70
|
+
|
71
|
+
switch (event->get_event_type()) {
|
72
|
+
case QUERY_EVENT:
|
73
|
+
retval = rb_funcall(rb_cBinlogQueryEvent, rb_intern("new"), 0);
|
74
|
+
QueryEvent::set_event(retval, event);
|
75
|
+
break;
|
76
|
+
|
77
|
+
case ROTATE_EVENT:
|
78
|
+
retval = rb_funcall(rb_cBinlogRotateEvent, rb_intern("new"), 0);
|
79
|
+
RotateEvent::set_event(retval, event);
|
80
|
+
break;
|
81
|
+
|
82
|
+
case FORMAT_DESCRIPTION_EVENT: // XXX: Is it right?
|
83
|
+
retval = rb_funcall(rb_cBinlogFormatEvent, rb_intern("new"), 0);
|
84
|
+
FormatEvent::set_event(retval, event);
|
85
|
+
break;
|
86
|
+
|
87
|
+
case USER_VAR_EVENT:
|
88
|
+
retval = rb_funcall(rb_cBinlogUserVarEvent, rb_intern("new"), 0);
|
89
|
+
UserVarEvent::set_event(retval, event);
|
90
|
+
break;
|
91
|
+
|
92
|
+
case TABLE_MAP_EVENT:
|
93
|
+
retval = rb_funcall(rb_cBinlogTableMapEvent, rb_intern("new"), 0);
|
94
|
+
TableMapEvent::set_event(retval, event);
|
95
|
+
break;
|
96
|
+
|
97
|
+
// XXX: Is it right?
|
98
|
+
case PRE_GA_WRITE_ROWS_EVENT:
|
99
|
+
case PRE_GA_UPDATE_ROWS_EVENT:
|
100
|
+
case PRE_GA_DELETE_ROWS_EVENT:
|
101
|
+
case WRITE_ROWS_EVENT:
|
102
|
+
case UPDATE_ROWS_EVENT:
|
103
|
+
case DELETE_ROWS_EVENT:
|
104
|
+
retval = rb_funcall(rb_cBinlogRowEvent, rb_intern("new"), 0);
|
105
|
+
RowEvent::set_event(retval, event);
|
106
|
+
break;
|
107
|
+
|
108
|
+
case INTVAR_EVENT:
|
109
|
+
retval = rb_funcall(rb_cBinlogIntVarEvent, rb_intern("new"), 0);
|
110
|
+
IntVarEvent::set_event(retval, event);
|
111
|
+
break;
|
112
|
+
|
113
|
+
case INCIDENT_EVENT:
|
114
|
+
retval = rb_funcall(rb_cBinlogIncidentEvent, rb_intern("new"), 0);
|
115
|
+
IncidentEvent::set_event(retval, event);
|
116
|
+
break;
|
117
|
+
|
118
|
+
case XID_EVENT:
|
119
|
+
retval = rb_funcall(rb_cBinlogXid, rb_intern("new"), 0);
|
120
|
+
XidEvent::set_event(retval, event);
|
121
|
+
break;
|
122
|
+
|
123
|
+
default:
|
124
|
+
retval = rb_funcall(rb_cBinlogUnimplementedEvent, rb_intern("new"), 0);
|
125
|
+
UnimplementedEvent::set_event(retval, event);
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
|
129
|
+
return retval;
|
130
|
+
}
|
131
|
+
|
132
|
+
static VALUE set_position(int argc, VALUE *argv, VALUE self) {
|
133
|
+
Client *p;
|
134
|
+
VALUE filename, position, retval = Qnil;
|
135
|
+
int result;
|
136
|
+
|
137
|
+
Data_Get_Struct(self, Client, p);
|
138
|
+
rb_scan_args(argc, argv, "11", &filename, &position);
|
139
|
+
|
140
|
+
if (NIL_P(position)) {
|
141
|
+
unsigned long i_position;
|
142
|
+
i_position = NUM2ULONG(filename);
|
143
|
+
result = p->m_binlog->set_position(i_position);
|
144
|
+
} else {
|
145
|
+
unsigned long i_position;
|
146
|
+
Check_Type(filename, T_STRING);
|
147
|
+
i_position = NUM2ULONG(position);
|
148
|
+
std::string s_filename(StringValuePtr(filename));
|
149
|
+
result = p->m_binlog->set_position(s_filename, i_position);
|
150
|
+
}
|
151
|
+
|
152
|
+
switch (result) {
|
153
|
+
case ERR_OK:
|
154
|
+
retval = Qtrue;
|
155
|
+
break;
|
156
|
+
case ERR_EOF:
|
157
|
+
retval = Qfalse;
|
158
|
+
default:
|
159
|
+
rb_raise(rb_eRuntimeError, "An unspecified error occurred (%d)", result);
|
160
|
+
break;
|
161
|
+
}
|
162
|
+
|
163
|
+
return retval;
|
164
|
+
}
|
165
|
+
|
166
|
+
static VALUE set_position2(VALUE self, VALUE position) {
|
167
|
+
Client *p;
|
168
|
+
VALUE retval = Qnil;
|
169
|
+
int result;
|
170
|
+
|
171
|
+
Data_Get_Struct(self, Client, p);
|
172
|
+
result = p->m_binlog->set_position(NUM2ULONG(position));
|
173
|
+
|
174
|
+
switch (result) {
|
175
|
+
case ERR_OK:
|
176
|
+
retval = Qtrue;
|
177
|
+
break;
|
178
|
+
case ERR_EOF:
|
179
|
+
retval = Qfalse;
|
180
|
+
default:
|
181
|
+
rb_raise(rb_eRuntimeError, "An unspecified error occurred (%d)", result);
|
182
|
+
break;
|
183
|
+
}
|
184
|
+
|
185
|
+
return retval;
|
186
|
+
}
|
187
|
+
|
188
|
+
static VALUE get_position(int argc, VALUE *argv, VALUE self) {
|
189
|
+
Client *p;
|
190
|
+
VALUE filename;
|
191
|
+
unsigned long position;
|
192
|
+
|
193
|
+
Data_Get_Struct(self, Client, p);
|
194
|
+
rb_scan_args(argc, argv, "01", &filename);
|
195
|
+
|
196
|
+
if (NIL_P(filename)) {
|
197
|
+
position = p->m_binlog->get_position();
|
198
|
+
} else {
|
199
|
+
Check_Type(filename, T_STRING);
|
200
|
+
std::string s_filename(StringValuePtr(filename));
|
201
|
+
position = p->m_binlog->get_position(s_filename);
|
202
|
+
}
|
203
|
+
|
204
|
+
return ULONG2NUM(position);
|
205
|
+
}
|
206
|
+
|
207
|
+
static VALUE get_position2(VALUE self) {
|
208
|
+
Client *p;
|
209
|
+
Data_Get_Struct(self, Client, p);
|
210
|
+
return ULONG2NUM(p->m_binlog->get_position());
|
211
|
+
}
|
212
|
+
|
213
|
+
static void init() {
|
214
|
+
VALUE rb_cBinlogClient = rb_define_class_under(rb_mBinlog, "Client", rb_cObject);
|
215
|
+
rb_define_alloc_func(rb_cBinlogClient, &alloc);
|
216
|
+
rb_define_private_method(rb_cBinlogClient, "initialize", __F(&initialize), 1);
|
217
|
+
rb_define_method(rb_cBinlogClient, "connect", __F(&connect), 0);
|
218
|
+
rb_define_method(rb_cBinlogClient, "wait_for_next_event", __F(&wait_for_next_event), 0);
|
219
|
+
rb_define_method(rb_cBinlogClient, "set_position", __F(&set_position), -1);
|
220
|
+
rb_define_method(rb_cBinlogClient, "position=", __F(&set_position2), 1);
|
221
|
+
rb_define_method(rb_cBinlogClient, "get_position", __F(&get_position), -1);
|
222
|
+
rb_define_method(rb_cBinlogClient, "position", __F(&get_position2), 0);
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
} // namespace binlog
|
227
|
+
} // namespace ruby
|
228
|
+
|
229
|
+
VALUE rb_mBinlog;
|
230
|
+
VALUE rb_cBinlogEvent;
|
231
|
+
|
232
|
+
void Init_binlog() {
|
233
|
+
rb_mBinlog = rb_define_module("Binlog");
|
234
|
+
rb_cBinlogEvent = rb_define_class_under(rb_mBinlog, "Event", rb_cObject);
|
235
|
+
|
236
|
+
rb_define_const(rb_cBinlogEvent, "UNKNOWN_EVENT", INT2NUM(0));
|
237
|
+
rb_define_const(rb_cBinlogEvent, "START_EVENT_V3", INT2NUM(1));
|
238
|
+
rb_define_const(rb_cBinlogEvent, "QUERY_EVENT", INT2NUM(2));
|
239
|
+
rb_define_const(rb_cBinlogEvent, "STOP_EVENT", INT2NUM(3));
|
240
|
+
rb_define_const(rb_cBinlogEvent, "ROTATE_EVENT", INT2NUM(4));
|
241
|
+
rb_define_const(rb_cBinlogEvent, "INTVAR_EVENT", INT2NUM(5));
|
242
|
+
rb_define_const(rb_cBinlogEvent, "LOAD_EVENT", INT2NUM(6));
|
243
|
+
rb_define_const(rb_cBinlogEvent, "SLAVE_EVENT", INT2NUM(7));
|
244
|
+
rb_define_const(rb_cBinlogEvent, "CREATE_FILE_EVENT", INT2NUM(8));
|
245
|
+
rb_define_const(rb_cBinlogEvent, "APPEND_BLOCK_EVENT", INT2NUM(9));
|
246
|
+
rb_define_const(rb_cBinlogEvent, "EXEC_LOAD_EVENT", INT2NUM(10));
|
247
|
+
rb_define_const(rb_cBinlogEvent, "DELETE_FILE_EVENT", INT2NUM(11));
|
248
|
+
rb_define_const(rb_cBinlogEvent, "NEW_LOAD_EVENT", INT2NUM(12));
|
249
|
+
rb_define_const(rb_cBinlogEvent, "RAND_EVENT", INT2NUM(13));
|
250
|
+
rb_define_const(rb_cBinlogEvent, "USER_VAR_EVENT", INT2NUM(14));
|
251
|
+
rb_define_const(rb_cBinlogEvent, "FORMAT_DESCRIPTION_EVENT", INT2NUM(15));
|
252
|
+
rb_define_const(rb_cBinlogEvent, "XID_EVENT", INT2NUM(16));
|
253
|
+
rb_define_const(rb_cBinlogEvent, "BEGIN_LOAD_QUERY_EVENT", INT2NUM(17));
|
254
|
+
rb_define_const(rb_cBinlogEvent, "EXECUTE_LOAD_QUERY_EVENT", INT2NUM(18));
|
255
|
+
rb_define_const(rb_cBinlogEvent, "TABLE_MAP_EVENT", INT2NUM(19));
|
256
|
+
rb_define_const(rb_cBinlogEvent, "PRE_GA_WRITE_ROWS_EVENT", INT2NUM(20));
|
257
|
+
rb_define_const(rb_cBinlogEvent, "PRE_GA_UPDATE_ROWS_EVENT", INT2NUM(21));
|
258
|
+
rb_define_const(rb_cBinlogEvent, "PRE_GA_DELETE_ROWS_EVENT", INT2NUM(22));
|
259
|
+
rb_define_const(rb_cBinlogEvent, "WRITE_ROWS_EVENT", INT2NUM(23));
|
260
|
+
rb_define_const(rb_cBinlogEvent, "UPDATE_ROWS_EVENT", INT2NUM(24));
|
261
|
+
rb_define_const(rb_cBinlogEvent, "DELETE_ROWS_EVENT", INT2NUM(25));
|
262
|
+
rb_define_const(rb_cBinlogEvent, "INCIDENT_EVENT", INT2NUM(26));
|
263
|
+
rb_define_const(rb_cBinlogEvent, "USER_DEFINED", INT2NUM(27));
|
264
|
+
|
265
|
+
ruby::binlog::Client::init();
|
266
|
+
ruby::binlog::QueryEvent::init();
|
267
|
+
ruby::binlog::RotateEvent::init();
|
268
|
+
ruby::binlog::FormatEvent::init();
|
269
|
+
ruby::binlog::UserVarEvent::init();
|
270
|
+
ruby::binlog::TableMapEvent::init();
|
271
|
+
ruby::binlog::RowEvent::init();
|
272
|
+
ruby::binlog::IntVarEvent::init();
|
273
|
+
ruby::binlog::IncidentEvent::init();
|
274
|
+
ruby::binlog::XidEvent::init();
|
275
|
+
ruby::binlog::UnimplementedEvent::init();
|
276
|
+
}
|