menu_process.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <stdio.h>
  10. #include <curses.h>
  11. #include <ctype.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <unistd.h>
  15. #define LOG_LEVEL 3
  16. #define LOG_PREFIX "camera_demo3"
  17. #include <syslog.h>
  18. #include <camera_manager.h>
  19. #include <camera_manager_utils.h>
  20. #include <camera_string.h>
  21. #include "param.h"
  22. #include "app_dialogs.h"
  23. #include "menu_process.h"
  24. void menu_camera_process(menu_camera_item_e item)
  25. {
  26. int ret;
  27. switch (item) {
  28. case MENU_CAMERA_LIST:
  29. LOG_D("dialog_camera_list()\n");
  30. ret = dialog_camera_list();
  31. break;
  32. case MENU_CAMERA_OPEN:
  33. LOG_D("dialog_camera_open()\n");
  34. ret = dialog_camera_open();
  35. break;
  36. case MENU_CAMERA_SET_MODE:
  37. LOG_D("dialog_camera_set_mode()\n");
  38. ret = dialog_camera_set_mode();
  39. break;
  40. case MENU_CAMERA_SET_PROPERTY:
  41. LOG_D("dialog_camera_property_list()\n");
  42. ret = dialog_camera_property_list();
  43. break;
  44. case MENU_CAMERA_CLOSE:
  45. LOG_D("dialog_camera_close()\n");
  46. ret = dialog_camera_close();
  47. break;
  48. case -1:
  49. ret = -1;
  50. break;
  51. default:
  52. LOG_E("Unknown menu item:%d\n", item);
  53. ret = -1;
  54. }
  55. return;
  56. }
  57. void menu_channel_process(menu_camera_item_e item)
  58. {
  59. int ret;
  60. csi_camera_channel_cfg_s *selected_chn;
  61. char str_buf[128];
  62. switch (item) {
  63. case MENU_CHANNEL_LIST:
  64. LOG_D("channel_list()\n");
  65. dialog_channel_list();
  66. break;
  67. case MENU_CHANNEL_OPEN:
  68. again_channel_open:
  69. LOG_D("channel_open()\n");
  70. ret = dialog_channel_select(&selected_chn, 1);
  71. if (ret == KEY_ESC || ret != 0 || /* Not "Select" button */
  72. selected_chn == NULL) { /* No Channel be selected */
  73. return;
  74. }
  75. ret = dialog_channel_open(selected_chn);
  76. touchwin(stdscr);
  77. refresh();
  78. goto again_channel_open;
  79. break;
  80. case MENU_CHANNEL_CLOSE:
  81. again_channel_close:
  82. LOG_D("channel_close()\n");
  83. ret = dialog_channel_select(&selected_chn, 0);
  84. if (ret == KEY_ESC || ret != 0 || /* Not "Select" button */
  85. selected_chn == NULL) { /* No Channel be selected */
  86. return;
  87. }
  88. ret = camera_channel_close(cam_session, selected_chn->chn_id);
  89. snprintf(str_buf, sizeof(str_buf),
  90. "Close Camera[%d]:Channel[%d] %s",
  91. cam_session->camera_id, selected_chn->chn_id,
  92. (ret == 0) ? "OK" : "failed");
  93. dialog_textbox_simple("Infomation", str_buf, 10, 40);
  94. touchwin(stdscr);
  95. refresh();
  96. goto again_channel_close;
  97. break;
  98. case -1:
  99. break;
  100. default:
  101. LOG_E("Unknown menu item:%d\n", item);
  102. break;
  103. }
  104. return;
  105. }
  106. void menu_event_run_process(menu_camera_item_e item)
  107. {
  108. int ret;
  109. char str_buf[128];
  110. camera_event_action_union_t *event_action = NULL;
  111. csi_camera_channel_cfg_s *selected_chn;
  112. switch (item) {
  113. case MENU_EVENT_SUBSCRIBE_ACTION:
  114. again_subscribe_action:
  115. LOG_D("dialog_event_subscribe_action_list()\n");
  116. ret = dialog_event_subscribe_action_list(&event_action);
  117. if (ret == KEY_ESC || ret != 0 || event_action == NULL)
  118. return;
  119. cam_mng_dump_event_action_union(event_action);
  120. if (event_action->target == MANAGE_TARGET_CAMERA) {
  121. ret = dialog_event_subscribe_action_camera(event_action);
  122. LOG_D("dialog_event_subscribe_action_camera() ret=%d\n", ret);
  123. goto again_subscribe_action;
  124. } else if (event_action->target == MANAGE_TARGET_CHANNEL) {
  125. ret = dialog_event_subscribe_action_channel(event_action);
  126. LOG_D("dialog_event_subscribe_action_channel() ret=%d\n", ret);
  127. goto again_subscribe_action;
  128. }
  129. break;
  130. case MENU_EVENT_START_STOP:
  131. ret = dialog_channel_run();
  132. break;
  133. case -1:
  134. break;
  135. default:
  136. LOG_E("Unknown menu item:%d\n", item);
  137. break;
  138. }
  139. return;
  140. }