dialog_event_subscribe_action_list.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <ctype.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #define LOG_LEVEL 3
  15. #define LOG_PREFIX "dlg_prop_list"
  16. #include <syslog.h>
  17. #include <curses.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 <csi_camera_property.h>
  24. #include <csi_camera_platform_spec.h>
  25. extern cams_t *cam_session;
  26. static int fill_items(void)
  27. {
  28. char item_name[64];
  29. char item_value[64];
  30. camera_event_action_union_t *event_action;
  31. /* Fill camera event and action */
  32. item_make("*** Camera[%d] Event/Action ***", cam_session->camera_id);
  33. item_set_tag(' ');
  34. item_set_data(NULL);
  35. for (int i = 0; i < CSI_CAMERA_EVENT_MAX_COUNT; i++) {
  36. event_action = &(cam_session->camera_event_action[i]);
  37. if (!event_action->camera.supported)
  38. continue;
  39. item_make(" %-18s", camera_string_camera_event_type(event_action->camera.event));
  40. item_add_str("(%s) --->", event_action->camera.subscribed
  41. ? "Subscribed" : "Un-subscribed");
  42. item_set_tag('M');
  43. item_set_data(event_action);
  44. //cam_mng_dump_event_action_union(event_action);
  45. }
  46. for(int i = 0;i < CSI_CAMERA_CHANNEL_MAX_COUNT;i++){
  47. if((cam_session->chn_cfg[i].status == CSI_CAMERA_CHANNEL_OPENED) ||
  48. (cam_session->chn_cfg[i].status == CSI_CAMERA_CHANNEL_RUNNING)){
  49. item_make(" *** Channel[%d] Event/Action ***",
  50. cam_session->chn_cfg[i].chn_id);
  51. item_set_tag(' ');
  52. item_set_data(NULL);
  53. for (int j = 0; j < CSI_CAMERA_CHANNEL_EVENT_MAX_COUNT; j++) {
  54. event_action = &(cam_session->channel_event_action[i][j]);
  55. if (!event_action->channel.supported)
  56. continue;
  57. item_make(" %-18s", camera_string_channel_event_type(event_action->channel.event));
  58. item_add_str("(%s) --->", event_action->channel.subscribed
  59. ? "Subscribed" : "Un-subscribed");
  60. item_set_tag('N'); // Type: Channel
  61. item_set_data(event_action);
  62. //cam_mng_dump_event_action_union(event_action);
  63. }
  64. }
  65. }
  66. return 0;
  67. }
  68. int dialog_event_subscribe_action_list(camera_event_action_union_t **event_action)
  69. {
  70. int ret_key = KEY_ESC;
  71. int ret = 0;
  72. char selected_tag;
  73. camera_event_action_union_t *selected_data;
  74. *event_action = NULL;
  75. char str_buf[128];
  76. again:
  77. item_reset();
  78. if (fill_items() != 0) {
  79. LOG_E("fill_items() failed\n");
  80. ret = KEY_ESC;
  81. goto exit;
  82. }
  83. int s_scroll = 0;
  84. ret_key = dialog_menu("Camera Event Subscribe & Action Setting",
  85. "Select the Camera/Channel, press Enter to set the event subscribe and event action",
  86. WIN_ROWS-2, WIN_COLS, NULL, -1, &s_scroll, NULL, 0);
  87. //LOG_D("dialog_menu() ret_key=%d, s_scroll=%d\n", ret_key, s_scroll);
  88. switch (ret_key) {
  89. case 0: /* Select button */
  90. selected_tag = item_tag();
  91. selected_data = (camera_event_action_union_t *)item_data();
  92. if (selected_data != NULL) {
  93. *event_action = selected_data;
  94. ret = 0;
  95. break;
  96. } else {
  97. goto again;
  98. }
  99. break;
  100. case 1: /* Apply button */
  101. ret = camera_subscribe_event(cam_session);
  102. snprintf(str_buf, sizeof(str_buf),
  103. "Apply Camera[%d] and Channels event register %s.",
  104. cam_session->camera_id, (ret == 0) ? "OK" : "failed");
  105. dialog_textbox_simple("Infomation", str_buf, 6, 56);
  106. goto again;
  107. case 2: /* Cancel button */
  108. case KEY_ESC: /* Escape */
  109. default:
  110. ret = KEY_ESC;
  111. goto exit;
  112. }
  113. exit:
  114. return ret;
  115. }