|
32 | 32 | #include <tbox/util/json.h>
|
33 | 33 | #include <tbox/util/fs.h>
|
34 | 34 | #include <tbox/terminal/session.h>
|
| 35 | +#include <tbox/terminal/helper.h> |
35 | 36 |
|
36 | 37 | #include "main.h"
|
37 | 38 |
|
@@ -290,257 +291,35 @@ void ContextImp::initShell()
|
290 | 291 | {
|
291 | 292 | auto water_line_node = wp_nodes->createDirNode("This is water line directory");
|
292 | 293 | wp_nodes->mountNode(loop_node, water_line_node, "wl");
|
293 |
| - { |
294 |
| - auto func_node = wp_nodes->createFuncNode( |
295 |
| - [this] (const Session &s, const Args &args) { |
296 |
| - bool print_usage = false; |
297 |
| - std::ostringstream oss; |
298 |
| - if (args.size() >= 2) { |
299 |
| - int value = 0; |
300 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
301 |
| - if (CatchThrowQuietly(may_throw_func)) { |
302 |
| - oss << "must be number\r\n"; |
303 |
| - print_usage = true; |
304 |
| - } else { |
305 |
| - sp_loop_->water_line().run_in_loop_queue_size = value; |
306 |
| - oss << "done\r\n"; |
307 |
| - } |
308 |
| - } else { |
309 |
| - oss << sp_loop_->water_line().run_in_loop_queue_size << "\r\n"; |
310 |
| - } |
311 |
| - |
312 |
| - if (print_usage) |
313 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
314 |
| - |
315 |
| - s.send(oss.str()); |
316 |
| - } |
317 |
| - ); |
318 |
| - wp_nodes->mountNode(water_line_node, func_node, "run_in_loop_queue_size"); |
319 |
| - } |
320 |
| - |
321 |
| - { |
322 |
| - auto func_node = wp_nodes->createFuncNode( |
323 |
| - [this] (const Session &s, const Args &args) { |
324 |
| - bool print_usage = false; |
325 |
| - std::ostringstream oss; |
326 |
| - if (args.size() >= 2) { |
327 |
| - int value = 0; |
328 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
329 |
| - if (CatchThrowQuietly(may_throw_func)) { |
330 |
| - oss << "must be number\r\n"; |
331 |
| - print_usage = true; |
332 |
| - } else { |
333 |
| - sp_loop_->water_line().run_next_queue_size = value; |
334 |
| - oss << "done\r\n"; |
335 |
| - } |
336 |
| - } else { |
337 |
| - oss << sp_loop_->water_line().run_next_queue_size << "\r\n"; |
338 |
| - } |
339 |
| - |
340 |
| - if (print_usage) |
341 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
342 |
| - |
343 |
| - s.send(oss.str()); |
344 |
| - } |
345 |
| - ); |
346 |
| - wp_nodes->mountNode(water_line_node, func_node, "run_next_queue_size"); |
347 |
| - } |
348 | 294 |
|
349 |
| - { |
350 |
| - auto func_node = wp_nodes->createFuncNode( |
351 |
| - [this] (const Session &s, const Args &args) { |
352 |
| - bool print_usage = false; |
353 |
| - std::ostringstream oss; |
354 |
| - if (args.size() >= 2) { |
355 |
| - int value = 0; |
356 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
357 |
| - if (CatchThrowQuietly(may_throw_func)) { |
358 |
| - oss << "must be number\r\n"; |
359 |
| - print_usage = true; |
360 |
| - } else { |
361 |
| - sp_loop_->water_line().run_in_loop_delay = std::chrono::microseconds(value); |
362 |
| - oss << "done\r\n"; |
363 |
| - } |
364 |
| - } else { |
365 |
| - oss << sp_loop_->water_line().run_in_loop_delay.count()/1000 << " us\r\n"; |
366 |
| - } |
367 |
| - |
368 |
| - if (print_usage) |
369 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
370 |
| - |
371 |
| - s.send(oss.str()); |
372 |
| - } |
373 |
| - ); |
374 |
| - wp_nodes->mountNode(water_line_node, func_node, "run_in_loop_delay"); |
| 295 | + #define ADD_WATERLINE_SIZE_FUNC_NODE(field) \ |
| 296 | + {\ |
| 297 | + terminal::IntegerFuncNodeProfile profile; \ |
| 298 | + profile.get_func = [this] { return sp_loop_->water_line().field; }; \ |
| 299 | + profile.set_func = [this] (int value) { sp_loop_->water_line().field = value; return true; }; \ |
| 300 | + profile.min_value = 0; \ |
| 301 | + terminal::AddFuncNode(*wp_nodes, water_line_node, #field, profile); \ |
375 | 302 | }
|
376 | 303 |
|
377 |
| - { |
378 |
| - auto func_node = wp_nodes->createFuncNode( |
379 |
| - [this] (const Session &s, const Args &args) { |
380 |
| - bool print_usage = false; |
381 |
| - std::ostringstream oss; |
382 |
| - if (args.size() >= 2) { |
383 |
| - int value = 0; |
384 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
385 |
| - if (CatchThrowQuietly(may_throw_func)) { |
386 |
| - oss << "must be number\r\n"; |
387 |
| - print_usage = true; |
388 |
| - } else { |
389 |
| - sp_loop_->water_line().run_next_delay = std::chrono::microseconds(value); |
390 |
| - oss << "done\r\n"; |
391 |
| - } |
392 |
| - } else { |
393 |
| - oss << sp_loop_->water_line().run_next_delay.count()/1000 << " us\r\n"; |
394 |
| - } |
395 |
| - |
396 |
| - if (print_usage) |
397 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
398 |
| - |
399 |
| - s.send(oss.str()); |
400 |
| - } |
401 |
| - ); |
402 |
| - wp_nodes->mountNode(water_line_node, func_node, "run_next_delay"); |
403 |
| - } |
| 304 | + ADD_WATERLINE_SIZE_FUNC_NODE(run_in_loop_queue_size); |
| 305 | + ADD_WATERLINE_SIZE_FUNC_NODE(run_next_queue_size); |
404 | 306 |
|
405 |
| - { |
406 |
| - auto func_node = wp_nodes->createFuncNode( |
407 |
| - [this] (const Session &s, const Args &args) { |
408 |
| - bool print_usage = false; |
409 |
| - std::ostringstream oss; |
410 |
| - if (args.size() >= 2) { |
411 |
| - int value = 0; |
412 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
413 |
| - if (CatchThrowQuietly(may_throw_func)) { |
414 |
| - oss << "must be number\r\n"; |
415 |
| - print_usage = true; |
416 |
| - } else { |
417 |
| - sp_loop_->water_line().loop_cost = std::chrono::microseconds(value); |
418 |
| - oss << "done\r\n"; |
419 |
| - } |
420 |
| - } else { |
421 |
| - oss << sp_loop_->water_line().loop_cost.count()/1000 << " us\r\n"; |
422 |
| - } |
423 |
| - |
424 |
| - if (print_usage) |
425 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
426 |
| - |
427 |
| - s.send(oss.str()); |
428 |
| - } |
429 |
| - ); |
430 |
| - wp_nodes->mountNode(water_line_node, func_node, "loop_cost"); |
| 307 | + #define ADD_WATERLINE_TIME_FUNC_NODE(field) \ |
| 308 | + {\ |
| 309 | + terminal::IntegerFuncNodeProfile profile; \ |
| 310 | + profile.get_func = [this] { return sp_loop_->water_line().field.count()/1000; }; \ |
| 311 | + profile.set_func = [this] (int value) { sp_loop_->water_line().field= std::chrono::microseconds(value); return true; }; \ |
| 312 | + profile.min_value = 0; \ |
| 313 | + terminal::AddFuncNode(*wp_nodes, water_line_node, #field, profile); \ |
431 | 314 | }
|
432 | 315 |
|
433 |
| - { |
434 |
| - auto func_node = wp_nodes->createFuncNode( |
435 |
| - [this] (const Session &s, const Args &args) { |
436 |
| - bool print_usage = false; |
437 |
| - std::ostringstream oss; |
438 |
| - if (args.size() >= 2) { |
439 |
| - int value = 0; |
440 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
441 |
| - if (CatchThrowQuietly(may_throw_func)) { |
442 |
| - oss << "must be number\r\n"; |
443 |
| - print_usage = true; |
444 |
| - } else { |
445 |
| - sp_loop_->water_line().event_cb_cost = std::chrono::microseconds(value); |
446 |
| - oss << "done\r\n"; |
447 |
| - } |
448 |
| - } else { |
449 |
| - oss << sp_loop_->water_line().event_cb_cost.count()/1000 << " us\r\n"; |
450 |
| - } |
451 |
| - |
452 |
| - if (print_usage) |
453 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
454 |
| - |
455 |
| - s.send(oss.str()); |
456 |
| - } |
457 |
| - ); |
458 |
| - wp_nodes->mountNode(water_line_node, func_node, "event_cb_cost"); |
459 |
| - } |
460 |
| - |
461 |
| - { |
462 |
| - auto func_node = wp_nodes->createFuncNode( |
463 |
| - [this] (const Session &s, const Args &args) { |
464 |
| - bool print_usage = false; |
465 |
| - std::ostringstream oss; |
466 |
| - if (args.size() >= 2) { |
467 |
| - int value = 0; |
468 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
469 |
| - if (CatchThrowQuietly(may_throw_func)) { |
470 |
| - oss << "must be number\r\n"; |
471 |
| - print_usage = true; |
472 |
| - } else { |
473 |
| - sp_loop_->water_line().run_cb_cost = std::chrono::microseconds(value); |
474 |
| - oss << "done\r\n"; |
475 |
| - } |
476 |
| - } else { |
477 |
| - oss << sp_loop_->water_line().run_cb_cost.count()/1000 << " us\r\n"; |
478 |
| - } |
479 |
| - |
480 |
| - if (print_usage) |
481 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
482 |
| - |
483 |
| - s.send(oss.str()); |
484 |
| - } |
485 |
| - ); |
486 |
| - wp_nodes->mountNode(water_line_node, func_node, "run_cb_cost"); |
487 |
| - } |
488 |
| - |
489 |
| - { |
490 |
| - auto func_node = wp_nodes->createFuncNode( |
491 |
| - [this] (const Session &s, const Args &args) { |
492 |
| - bool print_usage = false; |
493 |
| - std::ostringstream oss; |
494 |
| - if (args.size() >= 2) { |
495 |
| - int value = 0; |
496 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
497 |
| - if (CatchThrowQuietly(may_throw_func)) { |
498 |
| - oss << "must be number\r\n"; |
499 |
| - print_usage = true; |
500 |
| - } else { |
501 |
| - sp_loop_->water_line().wake_delay = std::chrono::microseconds(value); |
502 |
| - oss << "done\r\n"; |
503 |
| - } |
504 |
| - } else { |
505 |
| - oss << sp_loop_->water_line().wake_delay.count()/1000 << " us\r\n"; |
506 |
| - } |
507 |
| - |
508 |
| - if (print_usage) |
509 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
510 |
| - |
511 |
| - s.send(oss.str()); |
512 |
| - } |
513 |
| - ); |
514 |
| - wp_nodes->mountNode(water_line_node, func_node, "wake_delay"); |
515 |
| - } |
516 |
| - |
517 |
| - { |
518 |
| - auto func_node = wp_nodes->createFuncNode( |
519 |
| - [this] (const Session &s, const Args &args) { |
520 |
| - bool print_usage = false; |
521 |
| - std::ostringstream oss; |
522 |
| - if (args.size() >= 2) { |
523 |
| - int value = 0; |
524 |
| - auto may_throw_func = [&] { value = std::stoi(args[1]); }; |
525 |
| - if (CatchThrowQuietly(may_throw_func)) { |
526 |
| - oss << "must be number\r\n"; |
527 |
| - print_usage = true; |
528 |
| - } else { |
529 |
| - sp_loop_->water_line().timer_delay = std::chrono::microseconds(value); |
530 |
| - oss << "done\r\n"; |
531 |
| - } |
532 |
| - } else { |
533 |
| - oss << sp_loop_->water_line().timer_delay.count()/1000 << " us\r\n"; |
534 |
| - } |
535 |
| - |
536 |
| - if (print_usage) |
537 |
| - oss << "Usage: " << args[0] << " <num>\r\n"; |
538 |
| - |
539 |
| - s.send(oss.str()); |
540 |
| - } |
541 |
| - ); |
542 |
| - wp_nodes->mountNode(water_line_node, func_node, "timer_delay"); |
543 |
| - } |
| 316 | + ADD_WATERLINE_TIME_FUNC_NODE(run_in_loop_delay); |
| 317 | + ADD_WATERLINE_TIME_FUNC_NODE(run_next_delay); |
| 318 | + ADD_WATERLINE_TIME_FUNC_NODE(loop_cost); |
| 319 | + ADD_WATERLINE_TIME_FUNC_NODE(event_cb_cost); |
| 320 | + ADD_WATERLINE_TIME_FUNC_NODE(run_cb_cost); |
| 321 | + ADD_WATERLINE_TIME_FUNC_NODE(wake_delay); |
| 322 | + ADD_WATERLINE_TIME_FUNC_NODE(timer_delay); |
544 | 323 | }
|
545 | 324 |
|
546 | 325 | {
|
|
0 commit comments