comparison src/ex_cmds2.c @ 9790:34cc6a101340 v7.4.2170

commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 6 22:05:07 2016 +0200 patch 7.4.2170 Problem: Cannot get information about timers. Solution: Add timer_info().
author Christian Brabandt <cb@256bit.org>
date Sat, 06 Aug 2016 22:15:05 +0200
parents 4360b2b46125
children 711b42c1013b
comparison
equal deleted inserted replaced
9789:b864a0dabc74 9790:34cc6a101340
1137 if (timer == NULL) 1137 if (timer == NULL)
1138 return NULL; 1138 return NULL;
1139 timer->tr_id = ++last_timer_id; 1139 timer->tr_id = ++last_timer_id;
1140 insert_timer(timer); 1140 insert_timer(timer);
1141 if (repeat != 0) 1141 if (repeat != 0)
1142 {
1143 timer->tr_repeat = repeat - 1; 1142 timer->tr_repeat = repeat - 1;
1144 timer->tr_interval = msec; 1143 timer->tr_interval = msec;
1145 }
1146 1144
1147 profile_setlimit(msec, &timer->tr_due); 1145 profile_setlimit(msec, &timer->tr_due);
1148 return timer; 1146 return timer;
1149 } 1147 }
1150 1148
1249 void 1247 void
1250 stop_timer(timer_T *timer) 1248 stop_timer(timer_T *timer)
1251 { 1249 {
1252 remove_timer(timer); 1250 remove_timer(timer);
1253 free_timer(timer); 1251 free_timer(timer);
1252 }
1253
1254 void
1255 add_timer_info(typval_T *rettv, timer_T *timer)
1256 {
1257 list_T *list = rettv->vval.v_list;
1258 dict_T *dict = dict_alloc();
1259 dictitem_T *di;
1260 long remaining;
1261 proftime_T now;
1262
1263 if (dict == NULL)
1264 return;
1265 list_append_dict(list, dict);
1266
1267 dict_add_nr_str(dict, "id", (long)timer->tr_id, NULL);
1268 dict_add_nr_str(dict, "time", (long)timer->tr_interval, NULL);
1269
1270 profile_start(&now);
1271 # ifdef WIN3264
1272 remaining = (long)(((double)(timer->tr_due.QuadPart - now.QuadPart)
1273 / (double)fr.QuadPart) * 1000);
1274 # else
1275 remaining = (timer->tr_due.tv_sec - now.tv_sec) * 1000
1276 + (timer->tr_due.tv_usec - now.tv_usec) / 1000;
1277 # endif
1278 dict_add_nr_str(dict, "remaining", (long)remaining, NULL);
1279
1280 dict_add_nr_str(dict, "repeat",
1281 (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1), NULL);
1282
1283 di = dictitem_alloc((char_u *)"callback");
1284 if (di != NULL)
1285 {
1286 if (dict_add(dict, di) == FAIL)
1287 vim_free(di);
1288 else if (timer->tr_partial != NULL)
1289 {
1290 di->di_tv.v_type = VAR_PARTIAL;
1291 di->di_tv.vval.v_partial = timer->tr_partial;
1292 ++timer->tr_partial->pt_refcount;
1293 }
1294 else
1295 {
1296 di->di_tv.v_type = VAR_FUNC;
1297 di->di_tv.vval.v_string = vim_strsave(timer->tr_callback);
1298 }
1299 di->di_tv.v_lock = 0;
1300 }
1301 }
1302
1303 void
1304 add_timer_info_all(typval_T *rettv)
1305 {
1306 timer_T *timer;
1307
1308 for (timer = first_timer; timer != NULL; timer = timer->tr_next)
1309 add_timer_info(rettv, timer);
1254 } 1310 }
1255 1311
1256 /* 1312 /*
1257 * Mark references in partials of timers. 1313 * Mark references in partials of timers.
1258 */ 1314 */