ruby-binlog 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/ruby_binlog.h ADDED
@@ -0,0 +1,33 @@
1
+ #ifndef __RUBY_BINLOG_H__
2
+ #define __RUBY_BINLOG_H__
3
+
4
+ #include <string>
5
+ #include <binlog_api.h>
6
+ #include <ruby.h>
7
+ #include <rubysig.h>
8
+
9
+ #include "ruby_binlog_event.h"
10
+
11
+ #ifndef RSTRING_PTR
12
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
13
+ #endif
14
+ #ifndef RSTRING_LEN
15
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
16
+ #endif
17
+
18
+ #ifdef _WIN32
19
+ #define __F(f) (reinterpret_cast<VALUE (__cdecl *)(...)>(f))
20
+ #else
21
+ #define __F(f) (reinterpret_cast<VALUE (*)(...)>(f))
22
+ #endif
23
+
24
+ extern VALUE rb_mBinlog;
25
+
26
+ extern "C" {
27
+ #ifdef _WIN32
28
+ __declspec(dllexport)
29
+ #endif
30
+ void Init_binlog();
31
+ }
32
+
33
+ #endif // __RUBY_BINLOG_H__
data/ext/ruby_binlog.o ADDED
Binary file
@@ -0,0 +1,67 @@
1
+ #include "ruby_binlog.h"
2
+
3
+ namespace ruby {
4
+ namespace binlog {
5
+
6
+ VALUE Event::get_marker(VALUE self) {
7
+ Event *p;
8
+ Data_Get_Struct(self, Event, p);
9
+ return UINT2NUM(p->m_event_header->marker);
10
+ }
11
+
12
+ VALUE Event::get_timestamp(VALUE self) {
13
+ Event *p;
14
+ Data_Get_Struct(self, Event, p);
15
+ return ULONG2NUM(p->m_event_header->timestamp);
16
+ }
17
+
18
+ VALUE Event::get_type_code(VALUE self) {
19
+ Event *p;
20
+ Data_Get_Struct(self, Event, p);
21
+ return UINT2NUM(p->m_event_header->type_code);
22
+ }
23
+
24
+ VALUE Event::get_server_id(VALUE self) {
25
+ Event *p;
26
+ Data_Get_Struct(self, Event, p);
27
+ return ULONG2NUM(p->m_event_header->server_id);
28
+ }
29
+
30
+ VALUE Event::get_event_length(VALUE self) {
31
+ Event *p;
32
+ Data_Get_Struct(self, Event, p);
33
+ return ULONG2NUM(p->m_event_header->event_length);
34
+ }
35
+
36
+ VALUE Event::get_next_position(VALUE self) {
37
+ Event *p;
38
+ Data_Get_Struct(self, Event, p);
39
+ return ULONG2NUM(p->m_event_header->next_position);
40
+ }
41
+
42
+ VALUE Event::get_flags(VALUE self) {
43
+ Event *p;
44
+ Data_Get_Struct(self, Event, p);
45
+ return UINT2NUM(p->m_event_header->flags);
46
+ }
47
+
48
+ VALUE Event::get_event_type(VALUE self) {
49
+ Event *p;
50
+ Data_Get_Struct(self, Event, p);
51
+ return rb_str_new2(
52
+ mysql::system::get_event_type_str(static_cast<enum Log_event_type>(p->m_event_header->type_code)));
53
+ }
54
+
55
+ void Event::init(VALUE clazz) {
56
+ rb_define_method(clazz, "marker", __F(&get_marker), 0);
57
+ rb_define_method(clazz, "timestamp", __F(&get_timestamp), 0);
58
+ rb_define_method(clazz, "type_code", __F(&get_type_code), 0);
59
+ rb_define_method(clazz, "server_id", __F(&get_server_id), 0);
60
+ rb_define_method(clazz, "event_length", __F(&get_event_length), 0);
61
+ rb_define_method(clazz, "next_position", __F(&get_next_position), 0);
62
+ rb_define_method(clazz, "flags", __F(&get_flags), 0);
63
+ rb_define_method(clazz, "event_type", __F(&get_event_type), 0);
64
+ }
65
+
66
+ } // namespace binlog
67
+ } // namespace ruby
@@ -0,0 +1,163 @@
1
+ #ifndef __RUBY_BINLOG_EVENT_H__
2
+ #define __RUBY_BINLOG_EVENT_H__
3
+
4
+ #include "ruby_binlog.h"
5
+
6
+ extern VALUE rb_cBinlogEvent;
7
+
8
+ namespace ruby {
9
+ namespace binlog {
10
+
11
+ struct Event {
12
+ mysql::Log_event_header *m_event_header;
13
+
14
+ static VALUE get_marker(VALUE self);
15
+ static VALUE get_timestamp(VALUE self);
16
+ static VALUE get_type_code(VALUE self);
17
+ static VALUE get_server_id(VALUE self);
18
+ static VALUE get_event_length(VALUE self);
19
+ static VALUE get_next_position(VALUE self);
20
+ static VALUE get_flags(VALUE self);
21
+ static VALUE get_event_type(VALUE self);
22
+ static void init(VALUE clazz);
23
+ };
24
+
25
+ struct QueryEvent : public Event {
26
+ mysql::Query_event *m_event;
27
+
28
+ static void free(QueryEvent *p);
29
+ static VALUE alloc(VALUE klass);
30
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
31
+ static void init();
32
+
33
+ static VALUE get_thread_id(VALUE self);
34
+ static VALUE get_exec_time(VALUE self);
35
+ static VALUE get_error_code(VALUE self);
36
+ static VALUE get_variables(VALUE self);
37
+ static VALUE get_db_name(VALUE self);
38
+ static VALUE get_query(VALUE self);
39
+ };
40
+
41
+ struct RotateEvent : public Event {
42
+ mysql::Rotate_event *m_event;
43
+
44
+ static void free(RotateEvent *p);
45
+ static VALUE alloc(VALUE klass);
46
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
47
+ static void init();
48
+
49
+ static VALUE get_binlog_file(VALUE self);
50
+ static VALUE get_binlog_pos(VALUE self);
51
+ };
52
+
53
+ struct FormatEvent : public Event {
54
+ mysql::Format_event *m_event;
55
+
56
+ static void free(FormatEvent *p);
57
+ static VALUE alloc(VALUE klass);
58
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
59
+ static void init();
60
+
61
+ static VALUE get_binlog_version(VALUE self);
62
+ static VALUE get_master_version(VALUE self);
63
+ static VALUE get_created_ts(VALUE self);
64
+ static VALUE get_log_header_len(VALUE self);
65
+ };
66
+
67
+ struct UserVarEvent : public Event {
68
+ mysql::User_var_event *m_event;
69
+
70
+ static void free(UserVarEvent *p);
71
+ static VALUE alloc(VALUE klass);
72
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
73
+ static void init();
74
+
75
+ static VALUE get_name(VALUE self);
76
+ static VALUE get_is_null(VALUE self);
77
+ static VALUE get_type(VALUE self);
78
+ static VALUE get_charset(VALUE self);
79
+ static VALUE get_value(VALUE self);
80
+ };
81
+
82
+ struct TableMapEvent : public Event {
83
+ mysql::Table_map_event *m_event;
84
+
85
+ static void free(TableMapEvent *p);
86
+ static VALUE alloc(VALUE klass);
87
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
88
+ static void init();
89
+
90
+ static VALUE get_table_id(VALUE self);
91
+ static VALUE get_flags(VALUE self);
92
+ static VALUE get_db_name(VALUE self);
93
+ static VALUE get_table_name(VALUE self);
94
+ static VALUE get_columns(VALUE self);
95
+ static VALUE get_metadata(VALUE self);
96
+ static VALUE get_null_bits(VALUE self);
97
+ };
98
+
99
+ struct RowEvent : public Event {
100
+ mysql::Row_event *m_event;
101
+
102
+ static void free(RowEvent *p);
103
+ static VALUE alloc(VALUE klass);
104
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
105
+ static void init();
106
+
107
+ static VALUE get_table_id(VALUE self);
108
+ static VALUE get_flags(VALUE self);
109
+ static VALUE get_columns_len(VALUE self);
110
+ static VALUE get_null_bits_len(VALUE self);
111
+ static VALUE get_columns_before_image(VALUE self);
112
+ static VALUE get_used_columns(VALUE self);
113
+ static VALUE get_row(VALUE self);
114
+ };
115
+
116
+ struct IntVarEvent : public Event {
117
+ mysql::Int_var_event *m_event;
118
+
119
+ static void free(IntVarEvent *p);
120
+ static VALUE alloc(VALUE klass);
121
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
122
+ static void init();
123
+
124
+ static VALUE get_type(VALUE self);
125
+ static VALUE get_value(VALUE self);
126
+ };
127
+
128
+ struct IncidentEvent : public Event {
129
+ mysql::Incident_event *m_event;
130
+
131
+ static void free(IncidentEvent *p);
132
+ static VALUE alloc(VALUE klass);
133
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
134
+ static void init();
135
+
136
+ static VALUE get_type(VALUE self);
137
+ static VALUE get_message(VALUE self);
138
+ };
139
+
140
+ struct XidEvent : public Event {
141
+ mysql::Xid *m_event;
142
+
143
+ static void free(XidEvent *p);
144
+ static VALUE alloc(VALUE klass);
145
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
146
+ static void init();
147
+
148
+ static VALUE get_xid_id(VALUE self);
149
+ };
150
+
151
+ struct UnimplementedEvent : public Event {
152
+ mysql::Binary_log_event *m_event;
153
+
154
+ static void free(QueryEvent *p);
155
+ static VALUE alloc(VALUE klass);
156
+ static void set_event(VALUE self, mysql::Binary_log_event *event);
157
+ static void init();
158
+ };
159
+
160
+ } // namespace binlog
161
+ } // namespace ruby
162
+
163
+ #endif // __RUBY_BINLOG_EVENT_H__
Binary file
@@ -0,0 +1,74 @@
1
+ #include "ruby_binlog.h"
2
+
3
+ VALUE rb_cBinlogFormatEvent;
4
+
5
+ namespace ruby {
6
+ namespace binlog {
7
+
8
+ void FormatEvent::free(FormatEvent *p) {
9
+ if (p->m_event) {
10
+ delete p->m_event;
11
+ p->m_event = 0;
12
+ p->m_event_header = 0;
13
+ }
14
+
15
+ delete p;
16
+ }
17
+
18
+ VALUE FormatEvent::alloc(VALUE klass) {
19
+ FormatEvent *p;
20
+
21
+ p = new FormatEvent();
22
+ p->m_event = 0;
23
+ p->m_event_header = 0;
24
+
25
+ return Data_Wrap_Struct(klass, 0, &free, p);
26
+ }
27
+
28
+ void FormatEvent::set_event(VALUE self, mysql::Binary_log_event *event) {
29
+ FormatEvent *p;
30
+
31
+ Data_Get_Struct(self, FormatEvent, p);
32
+ p->m_event = static_cast<Format_event*>(event);
33
+ p->m_event_header = event->header();
34
+ }
35
+
36
+ void FormatEvent::init() {
37
+ rb_cBinlogFormatEvent = rb_define_class_under(rb_mBinlog, "FormatEvent", rb_cBinlogEvent);
38
+ rb_define_alloc_func(rb_cBinlogFormatEvent, &alloc);
39
+
40
+ Event::init(rb_cBinlogFormatEvent);
41
+
42
+ rb_define_method(rb_cBinlogFormatEvent, "binlog_version", __F(&get_binlog_version), 0);
43
+ // XXX: [BUG] Segmentation fault
44
+ //rb_define_method(rb_cBinlogFormatEvent, "master_version", __F(&get_master_version), 0);
45
+ rb_define_method(rb_cBinlogFormatEvent, "created_ts", __F(&get_created_ts), 0);
46
+ rb_define_method(rb_cBinlogFormatEvent, "log_header_len", __F(&get_log_header_len), 0);
47
+ }
48
+
49
+ VALUE FormatEvent::get_binlog_version(VALUE self) {
50
+ FormatEvent *p;
51
+ Data_Get_Struct(self, FormatEvent, p);
52
+ return UINT2NUM(p->m_event->binlog_version);
53
+ }
54
+
55
+ VALUE FormatEvent::get_master_version(VALUE self) {
56
+ FormatEvent *p;
57
+ Data_Get_Struct(self, FormatEvent, p);
58
+ return rb_str_new2(p->m_event->master_version.c_str());
59
+ }
60
+
61
+ VALUE FormatEvent::get_created_ts(VALUE self) {
62
+ FormatEvent *p;
63
+ Data_Get_Struct(self, FormatEvent, p);
64
+ return ULONG2NUM(p->m_event->created_ts);
65
+ }
66
+
67
+ VALUE FormatEvent::get_log_header_len(VALUE self) {
68
+ FormatEvent *p;
69
+ Data_Get_Struct(self, FormatEvent, p);
70
+ return UINT2NUM(p->m_event->log_header_len);
71
+ }
72
+
73
+ } // namespace binlog
74
+ } // namespace ruby
Binary file
@@ -0,0 +1,59 @@
1
+ #include "ruby_binlog.h"
2
+
3
+ VALUE rb_cBinlogIncidentEvent;
4
+
5
+ namespace ruby {
6
+ namespace binlog {
7
+
8
+ void IncidentEvent::free(IncidentEvent *p) {
9
+ if (p->m_event) {
10
+ delete p->m_event;
11
+ p->m_event = 0;
12
+ p->m_event_header = 0;
13
+ }
14
+
15
+ delete p;
16
+ }
17
+
18
+ VALUE IncidentEvent::alloc(VALUE klass) {
19
+ IncidentEvent *p;
20
+
21
+ p = new IncidentEvent();
22
+ p->m_event = 0;
23
+ p->m_event_header = 0;
24
+
25
+ return Data_Wrap_Struct(klass, 0, &free, p);
26
+ }
27
+
28
+ void IncidentEvent::set_event(VALUE self, mysql::Binary_log_event *event) {
29
+ IncidentEvent *p;
30
+
31
+ Data_Get_Struct(self, IncidentEvent, p);
32
+ p->m_event = static_cast<Incident_event*>(event);
33
+ p->m_event_header = event->header();
34
+ }
35
+
36
+ void IncidentEvent::init() {
37
+ rb_cBinlogIncidentEvent = rb_define_class_under(rb_mBinlog, "IncidentEvent", rb_cBinlogEvent);
38
+ rb_define_alloc_func(rb_cBinlogIncidentEvent, &alloc);
39
+
40
+ Event::init(rb_cBinlogIncidentEvent);
41
+
42
+ rb_define_method(rb_cBinlogIncidentEvent, "incident_type", __F(&get_type), 0);
43
+ rb_define_method(rb_cBinlogIncidentEvent, "message", __F(&get_message), 0);
44
+ }
45
+
46
+ VALUE IncidentEvent::get_type(VALUE self) {
47
+ IncidentEvent *p;
48
+ Data_Get_Struct(self, IncidentEvent, p);
49
+ return UINT2NUM(p->m_event->type);
50
+ }
51
+
52
+ VALUE IncidentEvent::get_message(VALUE self) {
53
+ IncidentEvent *p;
54
+ Data_Get_Struct(self, IncidentEvent, p);
55
+ return rb_str_new2(p->m_event->message.c_str());
56
+ }
57
+
58
+ } // namespace binlog
59
+ } // namespace ruby
Binary file
@@ -0,0 +1,59 @@
1
+ #include "ruby_binlog.h"
2
+
3
+ VALUE rb_cBinlogIntVarEvent;
4
+
5
+ namespace ruby {
6
+ namespace binlog {
7
+
8
+ void IntVarEvent::free(IntVarEvent *p) {
9
+ if (p->m_event) {
10
+ delete p->m_event;
11
+ p->m_event = 0;
12
+ p->m_event_header = 0;
13
+ }
14
+
15
+ delete p;
16
+ }
17
+
18
+ VALUE IntVarEvent::alloc(VALUE klass) {
19
+ IntVarEvent *p;
20
+
21
+ p = new IntVarEvent();
22
+ p->m_event = 0;
23
+ p->m_event_header = 0;
24
+
25
+ return Data_Wrap_Struct(klass, 0, &free, p);
26
+ }
27
+
28
+ void IntVarEvent::set_event(VALUE self, mysql::Binary_log_event *event) {
29
+ IntVarEvent *p;
30
+
31
+ Data_Get_Struct(self, IntVarEvent, p);
32
+ p->m_event = static_cast<Int_var_event*>(event);
33
+ p->m_event_header = event->header();
34
+ }
35
+
36
+ void IntVarEvent::init() {
37
+ rb_cBinlogIntVarEvent = rb_define_class_under(rb_mBinlog, "IntVarEvent", rb_cBinlogEvent);
38
+ rb_define_alloc_func(rb_cBinlogIntVarEvent, &alloc);
39
+
40
+ Event::init(rb_cBinlogIntVarEvent);
41
+
42
+ rb_define_method(rb_cBinlogIntVarEvent, "var_type", __F(&get_type), 0);
43
+ rb_define_method(rb_cBinlogIntVarEvent, "value", __F(&get_value), 0);
44
+ }
45
+
46
+ VALUE IntVarEvent::get_type(VALUE self) {
47
+ IntVarEvent *p;
48
+ Data_Get_Struct(self, IntVarEvent, p);
49
+ return UINT2NUM(p->m_event->type);
50
+ }
51
+
52
+ VALUE IntVarEvent::get_value(VALUE self) {
53
+ IntVarEvent *p;
54
+ Data_Get_Struct(self, IntVarEvent, p);
55
+ return ULL2NUM(p->m_event->value);
56
+ }
57
+
58
+ } // namespace binlog
59
+ } // namespace ruby