TCP 서버 구동 모듈 (리팩토링된 버전) 더 자세히 ...
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include <arpa/inet.h>
#include <curl/curl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <stdexcept>
#include <system_error>
#include "json.hpp"
#include "ssl.hpp"
#include "db_management.hpp"
#include "curl_camera.hpp"
#include "metadata_parser.hpp"
#include <atomic>
#include <queue>
#include "otp/otp_manager.hpp"
#include "hash.hpp"
타입정의 | |
using | json = nlohmann::json |
함수 | |
string | getLines () |
카메라에서 라인 크로싱 설정을 가져옵니다. | |
string | putLines (CrossLine) |
카메라에 라인 크로싱 설정을 전송합니다. | |
string | deleteLines (int index) |
카메라에서 지정한 라인을 삭제합니다. | |
int | tcp_run () |
TCP 서버를 시작하고 클라이언트 연결을 대기합니다. | |
SSL * | setup_ssl_connection (int client_socket) |
클라이언트 소켓에 SSL 연결을 설정합니다. | |
void | initialize_database_tables (SQLite::Database &db) |
데이터베이스 테이블들을 초기화합니다. | |
bool | receive_json_message (SSL *ssl, json &received_json) |
SSL 연결에서 JSON 메시지를 수신합니다. | |
void | handle_detection_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
감지 데이터 조회 요청을 처리합니다. (request_id == 1) | |
void | handle_line_insert_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
감지선 좌표값 삽입 요청을 처리합니다. (request_id == 2) | |
void | handle_line_select_all_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
감지선 전체 조회 요청을 처리합니다. (request_id == 3) | |
void | handle_line_delete_all_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
감지선, 기준선, 수직선 전체 삭제 요청을 처리합니다. (request_id == 4) | |
void | handle_baseline_insert_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
도로 기준선 삽입 요청을 처리합니다. (request_id == 5) | |
void | handle_vertical_line_insert_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
감지선의 수직선 방정식 삽입 요청을 처리합니다. (request_id == 6) | |
void | handle_baseline_select_all_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
도로 기준선 전체 조회 요청을 처리합니다. (request_id == 7) | |
void | handle_login_step1_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
1단계 로그인 요청(ID/PW 검증)을 처리합니다. (request_id == 8) | |
void | handle_login_step2_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
2단계 로그인 요청(OTP/복구코드 검증)을 처리합니다. (request_id == 22) | |
void | handle_signup_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex) |
회원가입 요청을 처리합니다. (request_id == 9) | |
void | handle_bbox_start_request (SSL *ssl, std::atomic< bool > &bbox_push_enabled, std::thread &push_thread, std::thread &metadata_thread) |
BBox push 시작 요청을 처리합니다. (request_id == 31) | |
void | handle_bbox_stop_request (SSL *ssl, std::atomic< bool > &bbox_push_enabled, std::thread &push_thread, std::thread &metadata_thread) |
BBox push 중지 요청을 처리합니다. (request_id == 32) | |
void | route_request (SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex, std::atomic< bool > &bbox_push_enabled, std::thread &push_thread, std::thread &metadata_thread) |
수신된 JSON 요청을 적절한 처리 함수로 라우팅합니다. | |
void | cleanup_client_connection (SSL *ssl, int client_socket, std::atomic< bool > &bbox_push_enabled, std::thread &push_thread, std::thread &metadata_thread) |
클라이언트 연결을 정리하고 관련 리소스를 해제합니다. | |
void | handle_client (int client_socket, SQLite::Database &db, std::mutex &db_mutex) |
개별 클라이언트와의 연결을 처리하는 메인 함수입니다. | |
변수 | |
const int | PORT = 8080 |
TCP 서버 포트 번호 | |
TCP 서버 구동 모듈 (리팩토링된 버전)
SSL/TLS를 지원하는 멀티스레드 TCP 서버로 클라이언트 요청을 처리합니다. JSON 기반 프로토콜을 사용하며 데이터베이스 연동과 실시간 메타데이터 처리를 지원합니다.
void cleanup_client_connection | ( | SSL * | ssl, |
int | client_socket, | ||
std::atomic< bool > & | bbox_push_enabled, | ||
std::thread & | push_thread, | ||
std::thread & | metadata_thread | ||
) |
클라이언트 연결을 정리하고 관련 리소스를 해제합니다.
ssl | OpenSSL SSL 포인터 |
client_socket | 클라이언트 소켓 파일 디스크립터 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
클라이언트 연결을 정리하고 관련 리소스를 해제합니다.
ssl | OpenSSL SSL 포인터 |
client_socket | 클라이언트 소켓 디스크립터 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
string deleteLines | ( | int | index | ) |
카메라에서 지정한 라인을 삭제합니다.
index | 삭제할 라인 인덱스 |
카메라에서 지정한 라인을 삭제합니다.
index | 삭제할 라인 인덱스 |
string getLines | ( | ) |
카메라에서 라인 크로싱 설정을 가져옵니다.
카메라에서 라인 크로싱 설정을 가져옵니다.
void handle_baseline_insert_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
도로 기준선 삽입 요청을 처리합니다. (request_id == 5)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_baseline_select_all_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
도로 기준선 전체 조회 요청을 처리합니다. (request_id == 7)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_bbox_start_request | ( | SSL * | ssl, |
std::atomic< bool > & | bbox_push_enabled, | ||
std::thread & | push_thread, | ||
std::thread & | metadata_thread | ||
) |
BBox push 시작 요청을 처리합니다. (request_id == 31)
ssl | OpenSSL SSL 포인터 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
void handle_bbox_stop_request | ( | SSL * | ssl, |
std::atomic< bool > & | bbox_push_enabled, | ||
std::thread & | push_thread, | ||
std::thread & | metadata_thread | ||
) |
BBox push 중지 요청을 처리합니다. (request_id == 32)
ssl | OpenSSL SSL 포인터 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
void handle_client | ( | int | client_socket, |
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
개별 클라이언트와의 연결을 처리하는 메인 함수입니다.
SSL 연결 설정, JSON 메시지 수신, 요청 라우팅, 연결 정리를 담당합니다.
client_socket | 클라이언트 소켓 파일 디스크립터 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
개별 클라이언트와의 연결을 처리하는 메인 함수입니다.
client_socket | 클라이언트 소켓 디스크립터 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_detection_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
감지 데이터 조회 요청을 처리합니다. (request_id == 1)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_line_delete_all_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
감지선, 기준선, 수직선 전체 삭제 요청을 처리합니다. (request_id == 4)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_line_insert_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
감지선 좌표값 삽입 요청을 처리합니다. (request_id == 2)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_line_select_all_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
감지선 전체 조회 요청을 처리합니다. (request_id == 3)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_login_step1_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
1단계 로그인 요청(ID/PW 검증)을 처리합니다. (request_id == 8)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_login_step2_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
2단계 로그인 요청(OTP/복구코드 검증)을 처리합니다. (request_id == 22)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_signup_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
회원가입 요청을 처리합니다. (request_id == 9)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void handle_vertical_line_insert_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex | ||
) |
감지선의 수직선 방정식 삽입 요청을 처리합니다. (request_id == 6)
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
void initialize_database_tables | ( | SQLite::Database & | db | ) |
데이터베이스 테이블들을 초기화합니다.
db | SQLite 데이터베이스 참조 |
데이터베이스 테이블들을 초기화합니다.
db | SQLite 데이터베이스 참조 |
string putLines | ( | CrossLine | crossLine | ) |
카메라에 라인 크로싱 설정을 전송합니다.
crossLine | 설정할 라인 정보 |
카메라에 라인 크로싱 설정을 전송합니다.
crossLine | 전송할 라인 정보 구조체 |
bool receive_json_message | ( | SSL * | ssl, |
json & | received_json | ||
) |
SSL 연결에서 JSON 메시지를 수신합니다.
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON을 저장할 참조 |
SSL 연결에서 JSON 메시지를 수신합니다.
ssl | OpenSSL SSL 포인터 |
received_json | 파싱된 JSON 객체 (출력) |
void route_request | ( | SSL * | ssl, |
const json & | received_json, | ||
SQLite::Database & | db, | ||
std::mutex & | db_mutex, | ||
std::atomic< bool > & | bbox_push_enabled, | ||
std::thread & | push_thread, | ||
std::thread & | metadata_thread | ||
) |
수신된 JSON 요청을 적절한 처리 함수로 라우팅합니다.
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
수신된 JSON 요청을 적절한 처리 함수로 라우팅합니다.
ssl | OpenSSL SSL 포인터 |
received_json | 수신된 JSON 요청 |
db | SQLite 데이터베이스 참조 |
db_mutex | DB 접근 뮤텍스 |
bbox_push_enabled | BBox push 활성화 플래그 |
push_thread | BBox push 스레드 참조 |
metadata_thread | 메타데이터 파싱 스레드 참조 |
SSL * setup_ssl_connection | ( | int | client_socket | ) |
클라이언트 소켓에 SSL 연결을 설정합니다.
client_socket | 클라이언트 소켓 파일 디스크립터 |
클라이언트 소켓에 SSL 연결을 설정합니다.
client_socket | 클라이언트 소켓 디스크립터 |
int tcp_run | ( | ) |
TCP 서버를 시작하고 클라이언트 연결을 대기합니다.
TCP 서버를 시작하고 클라이언트 연결을 대기합니다.