void rb_grn_init_context (VALUE mGrn) { cGrnContext = rb_define_class_under(mGrn, "Context", rb_cObject); rb_define_alloc_func(cGrnContext, rb_grn_context_alloc); rb_cv_set(cGrnContext, "@@default", Qnil); rb_cv_set(cGrnContext, "@@default_options", Qnil); rb_define_singleton_method(cGrnContext, "default", rb_grn_context_s_get_default, 0); rb_define_singleton_method(cGrnContext, "default=", rb_grn_context_s_set_default, 1); rb_define_singleton_method(cGrnContext, "default_options", rb_grn_context_s_get_default_options, 0); rb_define_singleton_method(cGrnContext, "default_options=", rb_grn_context_s_set_default_options, 1); rb_define_method(cGrnContext, "initialize", rb_grn_context_initialize, -1); rb_define_method(cGrnContext, "inspect", rb_grn_context_inspect, 0); rb_define_method(cGrnContext, "encoding", rb_grn_context_get_encoding, 0); rb_define_method(cGrnContext, "encoding=", rb_grn_context_set_encoding, 1); rb_define_method(cGrnContext, "database", rb_grn_context_get_database, 0); rb_define_method(cGrnContext, "[]", rb_grn_context_array_reference, 1); rb_define_method(cGrnContext, "pop", rb_grn_context_pop, 0); rb_define_method(cGrnContext, "connect", rb_grn_context_connect, -1); rb_define_method(cGrnContext, "send", rb_grn_context_send, 1); rb_define_method(cGrnContext, "receive", rb_grn_context_receive, 0); }
static VALUE pairwize_force(VALUE self, VALUE pi, VALUE pj, VALUE c) { real massi, massj; real posi[3], posj[3], veli[3], velj[3]; real acci[3], accj[3], jerki[3], jerkj[3]; real epot, coll_time_q; get_pos_vel_and_mass(pi, posi, veli, &massi); get_pos_vel_and_mass(pj, posj, velj, &massj); epot = NUM2DBL(rb_cv_get(c, "@@epot")); coll_time_q = NUM2DBL(rb_cv_get(c, "@@coll_time_q")); pairwise_acc_jerk_pot_coll(massi, massj, posi, posj, veli, velj, acci, accj, jerki, jerkj, &epot, &coll_time_q); inc_acc_jerk(pi, acci, jerki); inc_acc_jerk(pj, accj, jerkj); rb_cv_set(c, "@@epot",rb_float_new(epot)); rb_cv_set(c, "@@coll_time_q",rb_float_new(coll_time_q)); return Qnil; }
static VALUE function_attach(VALUE self, VALUE module, VALUE name) { Function* fn; char var[1024]; Data_Get_Struct(self, Function, fn); if (fn->info->parameterCount == -1) { rb_raise(rb_eRuntimeError, "Cannot attach variadic functions"); } if (fn->methodHandle == NULL) { fn->methodHandle = rbffi_MethodHandle_Alloc(fn->info, fn->memory.address); } // // Stash the Function in a module variable so it does not get garbage collected // snprintf(var, sizeof(var), "@@%s", StringValueCStr(name)); rb_cv_set(module, var, self); rb_define_module_function(module, StringValueCStr(name), rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1); rb_define_method(module, StringValueCStr(name), rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1); return self; }
void Init_epeg() { VALUE mEpeg = rb_define_module("Epeg"), cEpegImage = rb_define_class_under(mEpeg, "Image", rb_cObject); rb_cv_set(cEpegImage, "@@quality", INT2NUM(85)); rb_define_singleton_method(cEpegImage, "from_blob", rb_epeg_image_from_blob, 1); rb_define_singleton_method(cEpegImage, "open", rb_epeg_image_open, 1); rb_define_singleton_method(cEpegImage, "default_quality=", rb_epeg_image_set_default_quality, 1); rb_define_singleton_method(cEpegImage, "default_quality", rb_epeg_image_get_default_quality, 0); rb_define_method(cEpegImage, "initialize", rb_epeg_image_initialize, 0); rb_define_method(cEpegImage, "resize", rb_epeg_image_resize, 2); rb_define_method(cEpegImage, "resize_to_fit", rb_epeg_image_resize_to_fit, 2); rb_define_method(cEpegImage, "resize_to_fill", rb_epeg_image_resize_to_fill, 2); rb_define_method(cEpegImage, "crop", rb_epeg_image_crop, -1); rb_define_method(cEpegImage, "write", rb_epeg_image_write, 1); rb_define_method(cEpegImage, "to_blob", rb_epeg_image_to_blob, 0); rb_define_method(cEpegImage, "close", rb_epeg_image_close, 0); rb_define_method(cEpegImage, "closed?", rb_epeg_image_is_closed, 0); rb_define_method(cEpegImage, "quality", rb_epeg_image_get_or_set_quality, -1); rb_define_method(cEpegImage, "quality=", rb_epeg_image_set_quality, 1); rb_define_attr(cEpegImage, "width", 1, 0); rb_define_attr(cEpegImage, "height", 1, 0); }
VALUE renet_main_deinitialize(VALUE self) { if (rb_cv_get(mENet, "@@initialized") == Qtrue) { enet_deinitialize(); } rb_cv_set(mENet, "@@initialized", Qfalse); return Qtrue; }
/* * call-seq: * default_quality=(q) * * Sets the default quality (+q+ >= 0 and +q+ <= 100) * * Epeg::Image.default_quality = 10 */ static VALUE rb_epeg_image_set_default_quality(VALUE klass, VALUE q) { Check_Type(q, T_FIXNUM); int quality = NUM2INT(q); rb_cv_set(klass, "@@quality", q); return Qnil; }
static VALUE rg_s_set_change_palette_hook(VALUE self) { VALUE func = rb_block_proc(); rb_cv_set(RG_TARGET_NAMESPACE, "__palette_proc__", func); gtk_color_selection_set_change_palette_with_screen_hook( (GtkColorSelectionChangePaletteWithScreenFunc)screen_func); return self; }
void rb_grn_init_query_logger (VALUE mGrn) { id_new = rb_intern("new"); id_parse = rb_intern("parse"); id_log = rb_intern("log"); id_reopen = rb_intern("reopen"); id_fin = rb_intern("fin"); rb_grn_query_logger.log = rb_grn_query_logger_log; rb_grn_query_logger.reopen = rb_grn_query_logger_reopen; rb_grn_query_logger.fin = rb_grn_query_logger_fin; rb_grn_query_logger.user_data = (void *)Qnil; cGrnQueryLogger = rb_define_class_under(mGrn, "QueryLogger", rb_cObject); rb_cv_set(cGrnQueryLogger, "@@current_logger", Qnil); rb_define_singleton_method(cGrnQueryLogger, "log", rb_grn_query_logger_s_log, -1); rb_define_singleton_method(cGrnQueryLogger, "register", rb_grn_query_logger_s_register, -1); rb_define_singleton_method(cGrnQueryLogger, "unregister", rb_grn_query_logger_s_unregister, 0); rb_define_singleton_method(cGrnQueryLogger, "reopen", rb_grn_query_logger_s_reopen, 0); rb_define_singleton_method(cGrnQueryLogger, "path", rb_grn_query_logger_s_get_path, 0); rb_define_singleton_method(cGrnQueryLogger, "path=", rb_grn_query_logger_s_set_path, 1); rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size", rb_grn_query_logger_s_get_rotate_threshold_size, 0); rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size=", rb_grn_query_logger_s_set_rotate_threshold_size, 1); mGrnQueryLoggerFlags = rb_define_module_under(cGrnQueryLogger, "Flags"); #define DEFINE_FLAG(NAME) \ rb_define_const(mGrnQueryLoggerFlags, \ #NAME, UINT2NUM(GRN_QUERY_LOG_ ## NAME)) DEFINE_FLAG(NONE); DEFINE_FLAG(COMMAND); DEFINE_FLAG(RESULT_CODE); DEFINE_FLAG(DESTINATION); DEFINE_FLAG(CACHE); DEFINE_FLAG(SIZE); DEFINE_FLAG(SCORE); DEFINE_FLAG(ALL); DEFINE_FLAG(DEFAULT); #undef DEFINE_FLAG cGrnCallbackQueryLogger = rb_define_class_under(mGrn, "CallbackQueryLogger", cGrnQueryLogger); }
void Init_renet() { mENet = rb_define_module("ENet"); rb_define_singleton_method(mENet, "initialize", renet_main_initialize, 0); rb_define_singleton_method(mENet, "deinitialize", renet_main_deinitialize, 0); rb_cv_set(mENet, "@@initialized", Qfalse); /*Init_Constants();*/ init_renet_connection(); init_renet_server(); rb_define_const(mENet, "ENET_VERSION", rb_str_new2("1.3.0")); rb_define_const(mENet, "RENET_VERSION", rb_str_new2("0.1.13")); }
/* * call-seq: * Groonga::Context.default -> Groonga::Context * * デフォルトのコンテキストを返す。デフォルトのコンテキスト * が作成されていない場合は暗黙のうちに作成し、それを返す。 * * 暗黙のうちにコンテキストを作成する場合は、 * Groonga::Context.default_optionsに設定されているオプショ * ンを利用する。 */ static VALUE rb_grn_context_s_get_default (VALUE self) { VALUE context; context = rb_cv_get(self, "@@default"); if (NIL_P(context)) { context = rb_funcall(cGrnContext, rb_intern("new"), 0); rb_cv_set(self, "@@default", context); } return context; }
/* External: write_temp_image Purpose: Write a temporary copy of the image to the IM registry Returns: the "filename" of the registered image Notes: The `temp_name' argument must point to an char array of size MaxTextExtent. */ void rm_write_temp_image(Image *image, char *temp_name) { #define TMPNAM_CLASS_VAR "@@_tmpnam_" MagickBooleanType okay; ExceptionInfo exception; volatile VALUE id_value; int id; GetExceptionInfo(&exception); // 'id' is always the value of its previous use if (rb_cvar_defined(Module_Magick, rb_intern(TMPNAM_CLASS_VAR)) == Qtrue) { id_value = rb_cv_get(Module_Magick, TMPNAM_CLASS_VAR); id = FIX2INT(id_value); } else { id = 0; rb_cv_set(Module_Magick, TMPNAM_CLASS_VAR, INT2FIX(id)); } id += 1; rb_cv_set(Module_Magick, TMPNAM_CLASS_VAR, INT2FIX(id)); sprintf(temp_name, "mpri:%d", id); // Omit "mpri:" from filename to form the key okay = SetImageRegistry(ImageRegistryType, temp_name+5, image, &exception); CHECK_EXCEPTION() DestroyExceptionInfo(&exception); if (!okay) { rb_raise(rb_eRuntimeError, "SetImageRegistry failed."); } }
VALUE renet_main_initialize(VALUE self) { if (rb_cv_get(mENet, "@@initialized") == Qfalse) { if (enet_initialize() != 0) { return Qfalse; } rb_cv_set(mENet, "@@initialized", Qtrue); return Qtrue; } return Qtrue; }
static void rb_grn_logger_reset_with_error_check (VALUE klass, grn_ctx *context) { VALUE current_logger; current_logger = rb_cv_get(klass, "@@current_logger"); if (NIL_P(current_logger)) return; rb_cv_set(klass, "@@current_logger", Qnil); if (context) { grn_logger_set(context, NULL); rb_grn_context_check(context, current_logger); } else { grn_logger_set(NULL, NULL); } }
void rb_gi_loader_init(VALUE rb_mGI) { VALUE RG_TARGET_NAMESPACE; RG_TARGET_NAMESPACE = rb_define_class_under(rb_mGI, "Loader", rb_cObject); rb_cv_set(RG_TARGET_NAMESPACE, boxed_class_converters_name, rb_ary_new()); RG_DEF_SMETHOD(define_class, -1); RG_DEF_SMETHOD(define_interface, 3); RG_DEF_SMETHOD(define_struct, -1); RG_DEF_SMETHOD(define_error, -1); RG_DEF_SMETHOD(register_boxed_class_converter, 1); RG_DEF_SMETHOD(register_constant_rename_map, 2); RG_DEF_SMETHOD(start_callback_dispatch_thread, 0); RG_DEF_SMETHOD(reference_gobject, -1); RG_DEF_SMETHOD(instantiate_gobject_pointer, 1); }
static VALUE rb_grn_query_logger_s_unregister (VALUE klass) { VALUE current_logger; VALUE rb_context = Qnil; grn_ctx *context; current_logger = rb_cv_get(klass, "@@current_logger"); if (NIL_P(current_logger)) return Qnil; rb_cv_set(klass, "@@current_logger", Qnil); context = rb_grn_context_ensure(&rb_context); grn_query_logger_set(context, NULL); rb_grn_context_check(context, klass); return Qnil; }
/* * This is called implictly when you require libusb. It gets all the current * devices. It returns if true if the devices have changed since last load. * * You can use this function if you need to get any newly added usb devices, but * onece you use it stop using any old USB devoce objects you mights still have * around */ VALUE load_devices() { int num_buses_changed = usb_find_busses(); int num_devices_changed = usb_find_devices(); if(num_buses_changed || num_devices_changed) { struct usb_bus *bus; struct usb_device *dev; VALUE result = rb_ary_new(); for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { VALUE new_device = Data_Wrap_Struct(cDevice, NULL, NULL, dev); rb_ary_push(result, new_device); } } rb_cv_set(module, "@@devices", result); return Qtrue; } return Qfalse; }
void Set_initialized() { rb_cv_set(cFM, "@@initialized", OBJ_TRUE); }
static VALUE class_spec_cv_set(VALUE self, VALUE klass, VALUE name, VALUE val) { rb_cv_set(klass, StringValuePtr(name), val); return Qnil; }
static VALUE set_prefs_path( VALUE self, VALUE path ) { rb_cv_set( self, "@@prefs_path", path ); return Qnil; }
ruby_value rb_mGraphicsCLASS_SETwindow_title(ruby_value self, ruby_value value) { rb_cv_set(self, "@@wndw_title", value); qgf_tools_window_rename(StringValuePtr(value)); return value; }
void Init_QGF_Graphics() { qgf_graphics_width = QGF_GRAPHICS_DEFAULT_WIDTH; qgf_graphics_height = QGF_GRAPHICS_DEFAULT_HEIGHT; qgf_graphics_frame_rate = QGF_GRAPHICS_DEFAULT_FRAME_RATE; qgf_graphics_frame_count = 0; qgf_graphics_brightness = 255; qgf_graphics_frame_skip = qgf_graphics_frame_rate / 10; qgf_graphics_needed_frame_skips = 0; qgf_graphics_last_ticks = qgf_tools_time_getTicks(); qgf_graphics_next_ticks = qgf_tools_time_getTicks() + 1000 / qgf_graphics_frame_rate; rb_mGraphics = rb_define_module("Graphics"); rb_cv_set(rb_mGraphics, "@@wndw_title", rb_str_new2("QGF Window")); rb_cv_set(rb_mGraphics, "@@drawable_objects", rb_ary_new()); rb_define_singleton_method(rb_mGraphics, "update", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_update), 0); rb_define_singleton_method(rb_mGraphics, "wait", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_wait), 1); rb_define_singleton_method(rb_mGraphics, "fadein", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_fadein), 1); rb_define_singleton_method(rb_mGraphics, "fadeout", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_fadeout), 1); rb_define_singleton_method(rb_mGraphics, "freeze", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_freeze), 0); rb_define_singleton_method(rb_mGraphics, "transition", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_transition), -1); rb_define_singleton_method(rb_mGraphics, "snap_to_bitmap", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_snap_to_bitmap), 0); rb_define_singleton_method(rb_mGraphics, "frame_reset", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_frame_reset), 0); rb_define_singleton_method(rb_mGraphics, "width", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_width), 0); rb_define_singleton_method(rb_mGraphics, "height", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_height), 0); rb_define_singleton_method(rb_mGraphics, "resize_screen", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_resize_screen), 0); rb_define_singleton_method(rb_mGraphics, "play_movie", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_play_movie), 0); rb_define_singleton_method(rb_mGraphics, "frame_rate", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_GETframe_rate), 0); rb_define_singleton_method(rb_mGraphics, "frame_rate=", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_SETframe_rate), 1); rb_define_singleton_method(rb_mGraphics, "frame_count", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_GETframe_count), 0); rb_define_singleton_method(rb_mGraphics, "frame_count=", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_SETframe_count), 1); rb_define_singleton_method(rb_mGraphics, "brightness", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_GETbrightness), 0); rb_define_singleton_method(rb_mGraphics, "brightness=", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_SETbrightness), 1); rb_define_singleton_method(rb_mGraphics, "window_title", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_GETwindow_title), 0); rb_define_singleton_method(rb_mGraphics, "window_title=", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_SETwindow_title), 1); rb_define_singleton_method(rb_mGraphics, "frame_skip", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_GETframe_skip), 0); rb_define_singleton_method(rb_mGraphics, "frame_skip=", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_SETframe_skip), 1); rb_define_singleton_method(rb_mGraphics, "real_frame_rate", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_real_frame_rate), 0); rb_define_singleton_method(rb_mGraphics, "to_bmp", RUBY_METHOD_FUNC(rb_mGraphicsCLASS_to_bmp), 1); Init_QGF_Graphics_Color(); Init_QGF_Graphics_Tone(); Init_QGF_Graphics_Bitmap(); Init_QGF_Graphics_Font(); Init_QGF_Graphics_Rect(); Init_QGF_Graphics_Sprite(); Init_QGF_Graphics_Plane(); Init_QGF_Graphics_Table(); Init_QGF_Graphics_Viewport(); rb_cv_set(rb_mGraphics, "@@bckgrnd_clr", rb_color_new()); }
/* * Registers a query logger or a callback that is called when a * query log event is emitted. * * @overload register(logger, options={}) * @param logger [#log, #reopen, #fin] The query logger. It is easy to * inherit {QueryLogger}. * * @!macro query-logger.register.options * @param options [::Hash] The options. * @option options [Symbol, String, Integer or nil] :flags (:default) * Flags describe what query log should be logged. * * If `flags` is String, it is parsed by {QueryLogger::Flags.parse}. * * @return void * * @overload register(options={}) * @yield [action, flag, timestamp, info, message] * ... * * @!macro query-logger.register.options */ static VALUE rb_grn_query_logger_s_register (int argc, VALUE *argv, VALUE klass) { VALUE rb_context = Qnil; grn_ctx *context; VALUE rb_logger, rb_callback; VALUE rb_options, rb_command, rb_result_code, rb_destination; VALUE rb_cache, rb_size, rb_score, rb_default, rb_all, rb_flags; unsigned int flags = GRN_QUERY_LOG_NONE; rb_scan_args(argc, argv, "02&", &rb_logger, &rb_options, &rb_callback); if (rb_block_given_p()) { rb_logger = rb_funcall(cGrnCallbackQueryLogger, id_new, 1, rb_callback); } rb_grn_scan_options(rb_options, "command", &rb_command, "result_code", &rb_result_code, "destination", &rb_destination, "cache", &rb_cache, "size", &rb_size, "score", &rb_score, "default", &rb_default, "all", &rb_all, "flags", &rb_flags, NULL); if (RVAL2CBOOL(rb_command)) { flags |= GRN_QUERY_LOG_COMMAND; } if (RVAL2CBOOL(rb_result_code)) { flags |= GRN_QUERY_LOG_RESULT_CODE; } if (RVAL2CBOOL(rb_destination)) { flags |= GRN_QUERY_LOG_DESTINATION; } if (RVAL2CBOOL(rb_cache)) { flags |= GRN_QUERY_LOG_CACHE; } if (RVAL2CBOOL(rb_size)) { flags |= GRN_QUERY_LOG_SIZE; } if (RVAL2CBOOL(rb_score)) { flags |= GRN_QUERY_LOG_SCORE; } if (RVAL2CBOOL(rb_default)) { flags |= GRN_QUERY_LOG_DEFAULT; } if (RVAL2CBOOL(rb_all)) { flags |= GRN_QUERY_LOG_ALL; } if (!NIL_P(rb_flags)) { flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 2, rb_flags, UINT2NUM(flags)); } rb_grn_query_logger.flags = flags; rb_grn_query_logger.user_data = (void *)rb_logger; context = rb_grn_context_ensure(&rb_context); grn_query_logger_set(context, &rb_grn_query_logger); rb_grn_context_check(context, rb_logger); rb_cv_set(klass, "@@current_logger", rb_logger); return Qnil; }
/* * call-seq: * Groonga::Context.default_options=(options) * * コンテキストを作成する時に利用するデフォルトのオプション * を設定する。利用可能なオプションは * Groonga::Context.newを参照。 */ static VALUE rb_grn_context_s_set_default_options (VALUE self, VALUE options) { rb_cv_set(self, "@@default_options", options); return Qnil; }
/* * call-seq: * Groonga::Context.default=(context) * * デフォルトのコンテキストを設定する。+nil+を指定すると、デ * フォルトのコンテキストをリセットする。リセットすると、次 * 回Groonga::Context.defaultを呼び出したときに新しくコンテ * キストが作成される。 */ static VALUE rb_grn_context_s_set_default (VALUE self, VALUE context) { rb_cv_set(self, "@@default", context); return Qnil; }
/* * groongaがログを出力する度に呼び出されるブロックを登録する。 * * @overload register(options={}) * @yield [event, level, time, title, message, location] * _event_ と _level_ はSymbol、それ以外は全て文字列で渡される。 * _event_ と _level_ 以外 * の4つについては _options_ で +false+ を指定することでブロックに * 渡さないようにすることができ、その場合は空文字列が実際には渡される。 * @param options [::Hash] The name and value * pairs. Omitted names are initialized as the default value. * @option options :max_level (:notice) * ログのレベルを +:none+ , +:emergency+ , +:alert+ , * +:critical+ , +:error+ , +:warning+ , +:notice+ , +:info+ , * +:debug+ , +:dump+ のいずれかで指定する。それより重要度が * 低いログはブロックに渡されなくなる。デフォルトでは +:notice+ 。 * @option options :time * ログが出力された時間をブロックに渡したいなら +true+ を指 * 定する。デフォルトでは渡す。 * @option options :title * ログのタイトルをブロックに渡したいなら +true+ を指定す * る。デフォルトでは渡す。 * (FIXME: groongaで実装されていない?) * @option options :message * ログのメッセージをブロックに渡したいなら +true+ を指定す * る。デフォルトでは渡す。 * @option options :location * ログの発生元のプロセスIDとgroongaのソースコードのファイ * ル名、行番号、関数名をブロックに渡したいなら +true+ を指 * 定する。デフォルトでは渡す。 */ static VALUE rb_grn_logger_s_register (int argc, VALUE *argv, VALUE klass) { VALUE rb_context = Qnil; grn_ctx *context; VALUE rb_logger, rb_callback; VALUE rb_options, rb_max_level; VALUE rb_time, rb_title, rb_message, rb_location; VALUE rb_flags; grn_log_level max_level = GRN_LOG_DEFAULT_LEVEL; int flags = 0; rb_scan_args(argc, argv, "02&", &rb_logger, &rb_options, &rb_callback); if (rb_block_given_p()) { if (!NIL_P(rb_logger)) { rb_options = rb_logger; } rb_logger = rb_funcall(rb_cGrnCallbackLogger, id_new, 1, rb_callback); } rb_grn_scan_options(rb_options, "max_level", &rb_max_level, "time", &rb_time, "title", &rb_title, "message", &rb_message, "location", &rb_location, "flags", &rb_flags, NULL); if (!NIL_P(rb_max_level)) { max_level = RVAL2GRNLOGLEVEL(rb_max_level); } if (NIL_P(rb_time) || CBOOL2RVAL(rb_time)) { flags |= GRN_LOG_TIME; } if (NIL_P(rb_title) || CBOOL2RVAL(rb_title)) { flags |= GRN_LOG_TITLE; } if (NIL_P(rb_message) || CBOOL2RVAL(rb_message)) { flags |= GRN_LOG_MESSAGE; } if (NIL_P(rb_location) || CBOOL2RVAL(rb_location)) { flags |= GRN_LOG_LOCATION; } if (!NIL_P(rb_flags)) { flags = rb_funcall(rb_mGrnLoggerFlags, id_parse, 2, INT2NUM(flags), rb_flags); } rb_grn_logger.max_level = max_level; rb_grn_logger.flags = flags; rb_grn_logger.user_data = (void *)rb_logger; context = rb_grn_context_ensure(&rb_context); grn_logger_set(context, &rb_grn_logger); rb_grn_context_check(context, rb_logger); rb_cv_set(klass, "@@current_logger", rb_logger); return Qnil; }
static VALUE Cbody_get_epot_and_collq(VALUE self,VALUE c) { rb_cv_set(c, "@@epot",rb_float_new(epot)); rb_cv_set(c, "@@coll_time_q",rb_float_new(coll_time_q)); return Qnil; }
void rb_grn_init_logger (VALUE mGrn) { id_caller_locations = rb_intern("caller_locations"); id_path = rb_intern("path"); id_lineno = rb_intern("lineno"); id_label = rb_intern("label"); id_new = rb_intern("new"); id_parse = rb_intern("parse"); id_log = rb_intern("log"); id_reopen = rb_intern("reopen"); id_fin = rb_intern("fin"); rb_grn_logger.log = rb_grn_logger_log; rb_grn_logger.reopen = rb_grn_logger_reopen; rb_grn_logger.fin = rb_grn_logger_fin; rb_grn_logger.user_data = (void *)Qnil; rb_cGrnLogger = rb_define_class_under(mGrn, "Logger", rb_cObject); rb_cv_set(rb_cGrnLogger, "@@current_logger", Qnil); rb_define_singleton_method(rb_cGrnLogger, "log", rb_grn_logger_s_log, -1); rb_define_singleton_method(rb_cGrnLogger, "register", rb_grn_logger_s_register, -1); rb_define_singleton_method(rb_cGrnLogger, "unregister", rb_grn_logger_s_unregister, 0); rb_define_singleton_method(rb_cGrnLogger, "reopen", rb_grn_logger_s_reopen, 0); rb_define_singleton_method(rb_cGrnLogger, "max_level", rb_grn_logger_s_get_max_level, 0); rb_define_singleton_method(rb_cGrnLogger, "max_level=", rb_grn_logger_s_set_max_level, 1); rb_define_singleton_method(rb_cGrnLogger, "path", rb_grn_logger_s_get_path, 0); rb_define_singleton_method(rb_cGrnLogger, "path=", rb_grn_logger_s_set_path, 1); rb_define_singleton_method(rb_cGrnLogger, "flags", rb_grn_logger_s_get_flags, 0); rb_define_singleton_method(rb_cGrnLogger, "flags=", rb_grn_logger_s_set_flags, 1); rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size", rb_grn_logger_s_get_rotate_threshold_size, 0); rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size=", rb_grn_logger_s_set_rotate_threshold_size, 1); rb_set_end_proc(rb_grn_logger_reset, rb_cGrnLogger); rb_mGrnLoggerFlags = rb_define_module_under(rb_cGrnLogger, "Flags"); #define DEFINE_FLAG(NAME) \ rb_define_const(rb_mGrnLoggerFlags, \ #NAME, INT2NUM(GRN_LOG_ ## NAME)) DEFINE_FLAG(TIME); DEFINE_FLAG(TITLE); DEFINE_FLAG(MESSAGE); DEFINE_FLAG(LOCATION); DEFINE_FLAG(PID); #undef DEFINE_FLAG rb_cGrnCallbackLogger = rb_define_class_under(mGrn, "CallbackLogger", rb_cGrnLogger); }
static VALUE sa_cv_set(VALUE self, VALUE klass, VALUE name, VALUE val) { return rb_cv_set(klass, StringValuePtr(name), val); }
static void Set_fm_data_size() { rb_cv_set(cFM, "@@fm_data_size", Integer_New(1 + (sizeof(FM) / sizeof(double)))); // size is number of doubles needed to hold FM data }