dialog_camera_close.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <curses.h>
  15. #define LOG_LEVEL 3
  16. #define LOG_PREFIX "dlg_close_camera"
  17. #include <syslog.h>
  18. #include <camera_manager.h>
  19. #include "param.h"
  20. #include "app_dialogs.h"
  21. extern cams_t *cam_session;
  22. int dialog_camera_close(void)
  23. {
  24. int ret_key = KEY_ESC;
  25. int ret;
  26. if (cam_session == NULL) {
  27. LOG_E("cam_session is NULL\n");
  28. return -1;
  29. }
  30. if (cam_session->camera_handle == NULL) {
  31. LOG_I("The camera has not been opened yet\n");
  32. dialog_textbox_simple("Infomation", "There's No camera opened yet", 10, 40);
  33. return -1;
  34. }
  35. char str_buf[256];
  36. int cam_id = cam_session->camera_id;
  37. snprintf(str_buf, sizeof(str_buf),
  38. "The camera below is to be closed:\n"
  39. "\t id=%d \n\t name='%s' \n\t device='%s' \n\t bus='%s'\n",
  40. cam_id,
  41. cam_session->camera_infos.info[cam_id].camera_name,
  42. cam_session->camera_infos.info[cam_id].device_name,
  43. cam_session->camera_infos.info[cam_id].bus_info);
  44. ret_key = dialog_yesno("Infomation", str_buf, 10, 50);
  45. LOG_D("dialog_yesno() return %d\n", ret);
  46. if (ret_key != 0) { // 0 is the button position of 'yes'
  47. LOG_D("close camera is canceled\n");
  48. return 0;
  49. }
  50. ret = camera_close(cam_session);
  51. if (ret != 0) {
  52. LOG_E("camera_close() failed\n");
  53. ret = -1;
  54. }
  55. snprintf(str_buf, sizeof(str_buf),
  56. "The camera close %s: {%d, %s, %s, %s}\n",
  57. (ret == 0) ? "OK" : "Failed",
  58. cam_id,
  59. cam_session->camera_infos.info[cam_id].camera_name,
  60. cam_session->camera_infos.info[cam_id].device_name,
  61. cam_session->camera_infos.info[cam_id].bus_info);
  62. message(str_buf, (ret == 0) ? 1 : 2);
  63. return ret;
  64. }