rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
@@ -0,0 +1,504 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ /* FIXME */
22
+ void grn_log_reopen(grn_ctx *ctx);
23
+ extern const char *grn_log_path;
24
+ extern const char *grn_qlog_path;
25
+
26
+
27
+ /*
28
+ * Document-class: Groonga::Logger
29
+ *
30
+ * groongaから出力されるログを記録するためのクラス。
31
+ *
32
+ */
33
+
34
+ #define RVAL2GRNWRAPPER(object) (rb_grn_logger_info_wrapper_from_ruby_object(object))
35
+ #define RVAL2GRNLOGLEVEL(object) (rb_grn_log_level_from_ruby_object(object))
36
+ #define GRNLOGLEVEL2RVAL(level) (rb_grn_log_level_to_ruby_object(level))
37
+
38
+ VALUE cGrnLogger;
39
+
40
+ typedef struct _rb_grn_logger_info_wrapper
41
+ {
42
+ grn_logger_info *logger;
43
+ VALUE handler;
44
+ } rb_grn_logger_info_wrapper;
45
+
46
+ static rb_grn_logger_info_wrapper *
47
+ rb_grn_logger_info_wrapper_from_ruby_object (VALUE object)
48
+ {
49
+ rb_grn_logger_info_wrapper *wrapper;
50
+
51
+ if (NIL_P(object))
52
+ return NULL;
53
+
54
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnLogger))) {
55
+ rb_raise(rb_eTypeError, "not a groonga logger");
56
+ }
57
+
58
+ Data_Get_Struct(object, rb_grn_logger_info_wrapper, wrapper);
59
+ if (!wrapper)
60
+ rb_raise(rb_eTypeError, "groonga logger is NULL");
61
+
62
+ return wrapper;
63
+ }
64
+
65
+ grn_logger_info *
66
+ rb_grn_logger_from_ruby_object (VALUE object)
67
+ {
68
+ rb_grn_logger_info_wrapper *wrapper;
69
+
70
+ wrapper = RVAL2GRNWRAPPER(object);
71
+ if (!wrapper)
72
+ return NULL;
73
+
74
+ return wrapper->logger;
75
+ }
76
+
77
+ static void
78
+ rb_grn_logger_free (void *object)
79
+ {
80
+ rb_grn_logger_info_wrapper *wrapper = object;
81
+
82
+ xfree(wrapper->logger);
83
+ xfree(wrapper);
84
+ }
85
+
86
+ static VALUE
87
+ rb_grn_logger_alloc (VALUE klass)
88
+ {
89
+ return Data_Wrap_Struct(klass, NULL, rb_grn_logger_free, NULL);
90
+ }
91
+
92
+ static grn_log_level
93
+ rb_grn_log_level_from_ruby_object (VALUE rb_level)
94
+ {
95
+ grn_log_level level = GRN_LOG_NONE;
96
+
97
+ if (NIL_P(rb_level)) {
98
+ level = GRN_LOG_DEFAULT_LEVEL;
99
+ } else if (rb_grn_equal_option(rb_level, "none")) {
100
+ level = GRN_LOG_NONE;
101
+ } else if (rb_grn_equal_option(rb_level, "emergency")) {
102
+ level = GRN_LOG_EMERG;
103
+ } else if (rb_grn_equal_option(rb_level, "alert")) {
104
+ level = GRN_LOG_ALERT;
105
+ } else if (rb_grn_equal_option(rb_level, "critical")) {
106
+ level = GRN_LOG_CRIT;
107
+ } else if (rb_grn_equal_option(rb_level, "error")) {
108
+ level = GRN_LOG_ERROR;
109
+ } else if (rb_grn_equal_option(rb_level, "warning")) {
110
+ level = GRN_LOG_WARNING;
111
+ } else if (rb_grn_equal_option(rb_level, "notice")) {
112
+ level = GRN_LOG_NOTICE;
113
+ } else if (rb_grn_equal_option(rb_level, "info")) {
114
+ level = GRN_LOG_INFO;
115
+ } else if (rb_grn_equal_option(rb_level, "debug")) {
116
+ level = GRN_LOG_DEBUG;
117
+ } else if (rb_grn_equal_option(rb_level, "dump")) {
118
+ level = GRN_LOG_DUMP;
119
+ } else {
120
+ rb_raise(rb_eArgError,
121
+ "log level should be one of "
122
+ "[nil, :none, :emergency, :alert, :critical, :error, "
123
+ ":warning, :notice, :info, :debug, :dump]: %s",
124
+ rb_grn_inspect(rb_level));
125
+ }
126
+
127
+ return level;
128
+ }
129
+
130
+ static VALUE
131
+ rb_grn_log_level_to_ruby_object (grn_log_level level)
132
+ {
133
+ VALUE rb_level = Qnil;
134
+
135
+ switch (level) {
136
+ case GRN_LOG_NONE:
137
+ rb_level = RB_GRN_INTERN("none");
138
+ break;
139
+ case GRN_LOG_EMERG:
140
+ rb_level = RB_GRN_INTERN("emergency");
141
+ break;
142
+ case GRN_LOG_ALERT:
143
+ rb_level = RB_GRN_INTERN("alert");
144
+ break;
145
+ case GRN_LOG_CRIT:
146
+ rb_level = RB_GRN_INTERN("critical");
147
+ break;
148
+ case GRN_LOG_ERROR:
149
+ rb_level = RB_GRN_INTERN("error");
150
+ break;
151
+ case GRN_LOG_WARNING:
152
+ rb_level = RB_GRN_INTERN("warning");
153
+ break;
154
+ case GRN_LOG_NOTICE:
155
+ rb_level = RB_GRN_INTERN("notice");
156
+ break;
157
+ case GRN_LOG_INFO:
158
+ rb_level = RB_GRN_INTERN("info");
159
+ break;
160
+ case GRN_LOG_DEBUG:
161
+ rb_level = RB_GRN_INTERN("debug");
162
+ break;
163
+ case GRN_LOG_DUMP:
164
+ rb_level = RB_GRN_INTERN("dump");
165
+ break;
166
+ default:
167
+ rb_level = INT2NUM(level);
168
+ break;
169
+ }
170
+
171
+ return rb_level;
172
+ }
173
+
174
+ static void
175
+ rb_grn_log (int level, const char *time, const char *title,
176
+ const char *message, const char *location, void *func_arg)
177
+ {
178
+ rb_grn_logger_info_wrapper *wrapper = func_arg;
179
+
180
+ rb_funcall(wrapper->handler, rb_intern("call"), 5,
181
+ GRNLOGLEVEL2RVAL(level),
182
+ rb_str_new2(time),
183
+ rb_str_new2(title),
184
+ rb_str_new2(message),
185
+ rb_str_new2(location));
186
+ }
187
+
188
+ static void
189
+ rb_grn_logger_set_handler (VALUE self, VALUE rb_handler)
190
+ {
191
+ rb_grn_logger_info_wrapper *wrapper;
192
+ grn_logger_info *logger;
193
+
194
+ wrapper = RVAL2GRNWRAPPER(self);
195
+ wrapper->handler = rb_handler;
196
+ rb_iv_set(self, "@handler", rb_handler);
197
+
198
+ logger = wrapper->logger;
199
+ if (NIL_P(rb_handler)) {
200
+ logger->func = NULL;
201
+ logger->func_arg = NULL;
202
+ } else {
203
+ logger->func = rb_grn_log;
204
+ logger->func_arg = wrapper;
205
+ }
206
+ }
207
+
208
+ static VALUE
209
+ rb_grn_logger_initialize (int argc, VALUE *argv, VALUE self)
210
+ {
211
+ rb_grn_logger_info_wrapper *wrapper;
212
+ grn_logger_info *logger;
213
+ grn_log_level level;
214
+ int flags = 0;
215
+ VALUE options, rb_level, rb_time, rb_title, rb_message, rb_location;
216
+ VALUE rb_handler;
217
+
218
+ rb_scan_args(argc, argv, "01&", &options, &rb_handler);
219
+
220
+ rb_grn_scan_options(options,
221
+ "level", &rb_level,
222
+ "time", &rb_time,
223
+ "title", &rb_title,
224
+ "message", &rb_message,
225
+ "location", &rb_location,
226
+ NULL);
227
+
228
+ level = RVAL2GRNLOGLEVEL(rb_level);
229
+
230
+ if (NIL_P(rb_time) || RVAL2CBOOL(rb_time))
231
+ flags |= GRN_LOG_TIME;
232
+ if (NIL_P(rb_title) || RVAL2CBOOL(rb_title))
233
+ flags |= GRN_LOG_TITLE;
234
+ if (NIL_P(rb_message) || RVAL2CBOOL(rb_message))
235
+ flags |= GRN_LOG_MESSAGE;
236
+ if (NIL_P(rb_location) || RVAL2CBOOL(rb_location))
237
+ flags |= GRN_LOG_LOCATION;
238
+
239
+ wrapper = ALLOC(rb_grn_logger_info_wrapper);
240
+ logger = ALLOC(grn_logger_info);
241
+ wrapper->logger = logger;
242
+ DATA_PTR(self) = wrapper;
243
+
244
+ logger->max_level = level;
245
+ logger->flags = flags;
246
+ rb_grn_logger_set_handler(self, rb_handler);
247
+
248
+ return Qnil;
249
+ }
250
+
251
+ /*
252
+ * call-seq:
253
+ * Groonga::Logger.register(options={})
254
+ {|level, time, title, message, location| ...}
255
+ *
256
+ * groongaがログを出力する度に呼び出されるブロックを登録す
257
+ * る。
258
+ *
259
+ * ブロックに渡されてくる引数は_level_, _time_, _title_,
260
+ * _message_, _location_の5つで、_level_はSymbol、それ以外は
261
+ * 全て文字列で渡される。その4つについては_options_で+false+
262
+ * を指定することでブロックに渡さないようにすることができ、
263
+ * その場合は空文字列が実際には渡される。
264
+ *
265
+ * _options_に指定可能な値は以下の通り。
266
+ *
267
+ * [+:level+]
268
+ * ログのレベルを+:none+, +:emergency+, +:alert+,
269
+ * +:critical+, +:error+, +:warning+, +:notice+, +:info+,
270
+ * +:debug+, +:dump+のいずれかで指定する。それより重要度が
271
+ * 低いログはブロックに渡されなくなる。デフォルトでは
272
+ * +:notice+。
273
+ *
274
+ * [+:time+]
275
+ * ログが出力された時間をブロックに渡したいなら+true+を指
276
+ * 定する。デフォルトでは渡す。
277
+ *
278
+ * [+:title+]
279
+ * ログのタイトルをブロックに渡したいなら+true+を指定す
280
+ * る。デフォルトでは渡す。(FIXME: groongaで実装されてい
281
+ * ない?)
282
+ *
283
+ * [+:message+]
284
+ * ログのメッセージをブロックに渡したいなら+true+を指定す
285
+ * る。デフォルトでは渡す。
286
+ *
287
+ * [+:location+]
288
+ * ログの発生元のプロセスIDとgroongaのソースコードのファイ
289
+ * ル名、行番号、関数名をブロックに渡したいなら+true+を指
290
+ * 定する。デフォルトでは渡す。
291
+ */
292
+ static VALUE
293
+ rb_grn_logger_s_register (int argc, VALUE *argv, VALUE klass)
294
+ {
295
+ VALUE logger, rb_context = Qnil;
296
+ grn_ctx *context;
297
+
298
+ logger = rb_funcall2(klass, rb_intern("new"), argc, argv);
299
+ rb_grn_logger_set_handler(logger, rb_block_proc());
300
+ context = rb_grn_context_ensure(&rb_context);
301
+ grn_logger_info_set(context, RVAL2GRNLOGGER(logger));
302
+ rb_grn_context_check(context, logger);
303
+ rb_cv_set(klass, "@@current_logger", logger);
304
+
305
+ return Qnil;
306
+ }
307
+
308
+ static void
309
+ rb_grn_logger_reset_with_error_check (VALUE klass, grn_ctx *context)
310
+ {
311
+ VALUE current_logger;
312
+
313
+ current_logger = rb_cv_get(klass, "@@current_logger");
314
+ if (NIL_P(current_logger))
315
+ return;
316
+
317
+ rb_cv_set(klass, "@@current_logger", Qnil);
318
+ if (context) {
319
+ grn_logger_info_set(context, NULL);
320
+ rb_grn_context_check(context, current_logger);
321
+ } else {
322
+ grn_logger_info_set(NULL, NULL);
323
+ }
324
+ }
325
+
326
+ static void
327
+ rb_grn_logger_reset (VALUE klass)
328
+ {
329
+ rb_grn_logger_reset_with_error_check(klass, NULL);
330
+ }
331
+
332
+ static VALUE
333
+ rb_grn_logger_s_reopen_with_related_object (VALUE klass, VALUE related_object)
334
+ {
335
+ #ifdef WIN32
336
+ rb_raise(rb_eNotImpError, "grn_log_reopen() isn't available on Windows.");
337
+ #else
338
+ VALUE rb_context = Qnil;
339
+ grn_ctx *context;
340
+
341
+ context = rb_grn_context_ensure(&rb_context);
342
+ rb_grn_logger_reset_with_error_check(klass, context);
343
+ grn_log_reopen(context);
344
+ rb_grn_context_check(context, related_object);
345
+ #endif
346
+
347
+ return Qnil;
348
+ }
349
+
350
+ /*
351
+ * call-seq:
352
+ * Groonga::Logger.reopen
353
+ *
354
+ * groongaのデフォルトロガーがログを出力するファイルを再オー
355
+ * プンする。ログファイルのバックアップ時などに使用する。
356
+ *
357
+ * Groonga::Logger.registerで独自のロガーを設定している場合
358
+ * は例外が発生する。
359
+ */
360
+ static VALUE
361
+ rb_grn_logger_s_reopen (VALUE klass)
362
+ {
363
+ return rb_grn_logger_s_reopen_with_related_object(klass, klass);
364
+ }
365
+
366
+ #ifndef WIN32
367
+ static VALUE
368
+ rb_grn_logger_s_set_path (VALUE klass, VALUE rb_path,
369
+ const char **path, const char *class_variable_name)
370
+ {
371
+ rb_grn_boolean need_reopen = RB_GRN_FALSE;
372
+
373
+ if (NIL_P(rb_path)) {
374
+ need_reopen = *path != NULL;
375
+ *path = NULL;
376
+ } else {
377
+ const char *current_path = *path;
378
+ *path = RSTRING_PTR(rb_path);
379
+ if (!current_path || strcmp(*path, current_path) != 0) {
380
+ need_reopen = RB_GRN_TRUE;
381
+ }
382
+ }
383
+ rb_cv_set(klass, class_variable_name, rb_path);
384
+
385
+ if (need_reopen) {
386
+ rb_grn_logger_s_reopen_with_related_object(klass, rb_path);
387
+ }
388
+
389
+ return Qnil;
390
+ }
391
+ #endif
392
+
393
+ /*
394
+ * call-seq:
395
+ * Groonga::Logger.log_path # => log_path
396
+ *
397
+ * groongaのデフォルトロガーがログを出力するファイルの
398
+ * パスを返す。
399
+ */
400
+ static VALUE
401
+ rb_grn_logger_s_get_log_path (VALUE klass)
402
+ {
403
+ #ifdef WIN32
404
+ rb_raise(rb_eNotImpError, "grn_log_path isn't available on Windows.");
405
+ return Qnil;
406
+ #else
407
+ if (grn_log_path) {
408
+ return rb_str_new2(grn_log_path);
409
+ } else {
410
+ return Qnil;
411
+ }
412
+ #endif
413
+ }
414
+
415
+ /*
416
+ * call-seq:
417
+ * Groonga::Logger.log_path = log_path
418
+ *
419
+ * groongaのデフォルトロガーがログを出力するファイルのパスを
420
+ * 指定する。
421
+ *
422
+ * Groonga::Logger.registerで独自のロガーを設定している場合、
423
+ * 設定している独自ロガーは無効になる。
424
+ */
425
+ static VALUE
426
+ rb_grn_logger_s_set_log_path (VALUE klass, VALUE path)
427
+ {
428
+ #ifdef WIN32
429
+ rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
430
+ return Qnil;
431
+ #else
432
+ return rb_grn_logger_s_set_path(klass, path, &grn_log_path, "@@log_path");
433
+ #endif
434
+ }
435
+
436
+ /*
437
+ * call-seq:
438
+ * Groonga::Logger.query_log_path # => query_log_path
439
+ *
440
+ * groongaのデフォルトロガーがクエリログを出力するファイルの
441
+ * パスを返す。
442
+ */
443
+ static VALUE
444
+ rb_grn_logger_s_get_query_log_path (VALUE klass)
445
+ {
446
+ #ifdef WIN32
447
+ rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
448
+ return Qnil;
449
+ #else
450
+ if (grn_qlog_path) {
451
+ return rb_str_new2(grn_qlog_path);
452
+ } else {
453
+ return Qnil;
454
+ }
455
+ #endif
456
+ }
457
+
458
+ /*
459
+ * call-seq:
460
+ * Groonga::Logger.query_log_path = query_log_path
461
+ *
462
+ * groongaのデフォルトロガーがクエリログを出力するファイルの
463
+ * パスを指定する。
464
+ *
465
+ * Groonga::Logger.registerで独自のロガーを設定している場合、
466
+ * 設定している独自ロガーは無効になる。
467
+ */
468
+ static VALUE
469
+ rb_grn_logger_s_set_query_log_path (VALUE klass, VALUE path)
470
+ {
471
+ #ifdef WIN32
472
+ rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
473
+ return Qnil;
474
+ #else
475
+ return rb_grn_logger_s_set_path(klass, path, &grn_qlog_path,
476
+ "@@query_log_path");
477
+ #endif
478
+ }
479
+
480
+ void
481
+ rb_grn_init_logger (VALUE mGrn)
482
+ {
483
+ cGrnLogger = rb_define_class_under(mGrn, "Logger", rb_cObject);
484
+ rb_define_alloc_func(cGrnLogger, rb_grn_logger_alloc);
485
+
486
+ rb_cv_set(cGrnLogger, "@@current_logger", Qnil);
487
+ rb_cv_set(cGrnLogger, "@@log_path", Qnil);
488
+ rb_cv_set(cGrnLogger, "@@query_log_path", Qnil);
489
+ rb_define_singleton_method(cGrnLogger, "register",
490
+ rb_grn_logger_s_register, -1);
491
+ rb_define_singleton_method(cGrnLogger, "reopen",
492
+ rb_grn_logger_s_reopen, 0);
493
+ rb_define_singleton_method(cGrnLogger, "log_path",
494
+ rb_grn_logger_s_get_log_path, 0);
495
+ rb_define_singleton_method(cGrnLogger, "log_path=",
496
+ rb_grn_logger_s_set_log_path, 1);
497
+ rb_define_singleton_method(cGrnLogger, "query_log_path",
498
+ rb_grn_logger_s_get_query_log_path, 0);
499
+ rb_define_singleton_method(cGrnLogger, "query_log_path=",
500
+ rb_grn_logger_s_set_query_log_path, 1);
501
+ rb_set_end_proc(rb_grn_logger_reset, cGrnLogger);
502
+
503
+ rb_define_method(cGrnLogger, "initialize", rb_grn_logger_initialize, -1);
504
+ }