static void push_timer_from_row(MYSQL_ROW row, int fields) { char *rng_duration, *rng_time; bool rng_sub; if( fields < 3 ) { wrn_print("fields(%d) < 3",fields); return; } rng_sub = !!atoi(row[4]); rng_duration = row[3]; rng_time = row[2]; struct sigevent se; se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = fit_default_durations(rng_duration); if(se.sigev_signo == -1 ) { se.sigev_signo = SIG_RING_CUSTOM; se.sigev_value.sival_int = duration(rng_duration); } if( push_timer_from_string(&se, rng_time, NULL,TIMER_ABSTIME,1) == -1 ) { wrn_print("push_timer_from_string %s", rng_time); return; } dbg_print(" duration: (%ss) time: (%s)",rng_duration, rng_time); if (rng_sub || sub_bell_conf.global_enable) { struct sigevent sub_se; struct timespec exp; time_t tm, gap; sub_se.sigev_value.sival_int = sub_bell_conf.ring_for; sub_se.sigev_notify = SIGEV_SIGNAL; sub_se.sigev_signo = SIG_RING_CUSTOM; gap = str_to_time(sub_bell_conf.ring_before, 0); gap -= timezone; /* ??? what ???*/ tm = str_to_time(rng_time, 1); exp.tv_sec = tm - gap; exp.tv_nsec = 0; dbg_print("Sub duartion: (%ldns) time: (%s/%ld)", (long) sub_bell_conf.ring_for,str_time("%H:%M:%S",&exp.tv_sec), (long)exp.tv_sec); if(push_timer(&sub_se, &exp, NULL,TIMER_ABSTIME,1) == -1) { wrn_print("push_timer"); return; } } }
/** * \brief Implementation of sol.timer.start(). * \param l the Lua context that is calling this function * \return number of values to return to Lua */ int LuaContext::timer_api_start(lua_State *l) { return LuaTools::exception_boundary_handle(l, [&] { // Parameters: [context] delay callback. LuaContext& lua_context = get_lua_context(l); if (lua_type(l, 1) != LUA_TNUMBER) { // The first parameter is the context. if (lua_type(l, 1) != LUA_TTABLE && lua_type(l, 1) != LUA_TUSERDATA) { LuaTools::type_error(l, 1, "table or userdata"); } } else { // No context specified: set a default context: // - during a game: the current map, // - outside a game: sol.main. Game* game = lua_context.get_main_loop().get_game(); if (game != nullptr && game->has_current_map()) { push_map(l, game->get_current_map()); } else { LuaContext::push_main(l); } lua_insert(l, 1); } // Now the first parameter is the context. uint32_t delay = uint32_t(LuaTools::check_int(l, 2)); const ScopedLuaRef& callback_ref = LuaTools::check_function(l, 3); // Create the timer. TimerPtr timer = std::make_shared<Timer>(delay); lua_context.add_timer(timer, 1, callback_ref); if (delay == 0) { // The delay is zero: call the function right now. lua_context.do_timer_callback(timer); } push_timer(l, timer); return 1; }); }
/** * @brief Implementation of sol.timer.start(). * @param l the Lua context that is calling this function * @return number of values to return to Lua */ int LuaContext::timer_api_start(lua_State *l) { // Parameters: [context] delay callback. LuaContext& lua_context = get_lua_context(l); if (lua_type(l, 1) != LUA_TNUMBER) { // The first parameter is the context. if (lua_type(l, 1) != LUA_TTABLE && lua_type(l, 1) != LUA_TUSERDATA) { luaL_typerror(l, 1, "table or userdata"); } } else { // No context specified: set a default context: // - during a game: the current map, // - outside a game: sol.main. Game* game = lua_context.get_main_loop().get_game(); if (game != NULL) { push_map(l, game->get_current_map()); } else { LuaContext::push_main(l); } lua_insert(l, 1); } // Now the first parameter is the context. uint32_t delay = uint32_t(luaL_checkint(l, 2)); luaL_checktype(l, 3, LUA_TFUNCTION); if (delay == 0) { // The delay is zero: call the function right now. lua_settop(l, 3); lua_context.call_function(0, 0, "callback"); lua_pushnil(l); } else { // Create the timer. Timer* timer = new Timer(delay); lua_context.add_timer(timer, 1, 3); push_timer(l, *timer); } return 1; }