Server
 
로딩중...
검색중...
일치하는것 없음
tcp_server.hpp
이 파일의 Documentation 페이지로 가기
1
8#pragma once
9
10#include <stdlib.h>
11
12#include <algorithm>
13#include <chrono>
14#include <cstdint> // uint32_t
15#include <ctime>
16#include <iomanip>
17#include <iostream> // 표준 입출력 (std::cout, std::cerr)
18#include <mutex>
19#include <string> // 문자열 처리 (std::string)
20#include <thread>
21#include <vector> // 동적 배열 (std::vector, 여기서는 사용되지 않지만 이전 컨텍스트에서 포함됨)
22
23// POSIX 소켓 API 관련 헤더
24#include <arpa/inet.h> // inet_ntoa
25#include <curl/curl.h>
26#include <netinet/in.h> // sockaddr_in
27#include <sys/socket.h> // socket, bind, listen, accept
28#include <unistd.h> // close
29
30// 오류 처리를 위한 추가 헤더
31#include <cerrno> // errno
32#include <cstring> // memset, strerror
33#include <stdexcept>
34#include <system_error> // strerror
35
36// json 처리를 위한 외부 헤더파일
37#include "json.hpp"
38
39// OpenSSL 관련 헤더
40#include "ssl.hpp"
41
42// DB 관련 헤더
43#include "db_management.hpp"
44
45// 카메라에 line을 설정하기 위한 헤더
46#include "curl_camera.hpp"
47
48#include "metadata_parser.hpp"
49#include <atomic>
50#include <queue>
51
52// OTP 관련 헤더
53#include "otp/otp_manager.hpp"
54
55// 비밀번호 / 복구코드 해싱을 위한 헤더 파일
56#include "hash.hpp"
57
58using namespace std;
59using json = nlohmann::json;
60
64const int PORT = 8080;
65
66// ==================== 기존 함수들 ====================
71string getLines();
72
78string putLines(CrossLine);
79
85string deleteLines(int index);
86
91int tcp_run();
92
93// ==================== 새로운 유틸리티 함수들 ====================
99SSL* setup_ssl_connection(int client_socket);
100
105void initialize_database_tables(SQLite::Database& db);
106
113bool receive_json_message(SSL* ssl, json& received_json);
114
115// ==================== 요청 처리 함수들 ====================
123void handle_detection_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
124
132void handle_line_insert_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
133
141void handle_line_select_all_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
142
150void handle_line_delete_all_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
151
159void handle_baseline_insert_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
160
168void handle_vertical_line_insert_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
169
177void handle_baseline_select_all_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
178
186void handle_login_step1_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
187
195void handle_login_step2_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
196
204void handle_signup_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex);
205
213void handle_bbox_start_request(SSL* ssl, std::atomic<bool>& bbox_push_enabled, std::thread& push_thread, std::thread& metadata_thread);
214
222void handle_bbox_stop_request(SSL* ssl, std::atomic<bool>& bbox_push_enabled, std::thread& push_thread, std::thread& metadata_thread);
223
224// ==================== 요청 라우터 및 정리 함수들 ====================
235void route_request(SSL* ssl, const json& received_json, SQLite::Database& db, std::mutex& db_mutex,
236 std::atomic<bool>& bbox_push_enabled, std::thread& push_thread, std::thread& metadata_thread);
237
246void cleanup_client_connection(SSL* ssl, int client_socket, std::atomic<bool>& bbox_push_enabled,
247 std::thread& push_thread, std::thread& metadata_thread);
248
249// ==================== 메인 클라이언트 처리 함수 ====================
257void handle_client(int client_socket, SQLite::Database& db, std::mutex& db_mutex);
nlohmann::json json
nlohmann::json 타입을 json으로 별칭 정의
Definition config_manager.cpp:17
libcurl을 사용한 카메라 통신 헤더 파일
데이터베이스 관리 헤더 파일
비밀번호 및 복구 코드 해싱 헤더 파일
JSON 처리 유틸리티 헤더 파일
void metadata_thread(SQLite::Database &db)
ffmpeg 메타데이터 스트림을 처리하는 루프 함수입니다.
Definition main_control.cpp:683
메타데이터 파싱 헤더 파일
SSL 통신 헤더 파일
감지선 정보를 저장하는 구조체
Definition db_management.hpp:33
void handle_client(int client_socket, SQLite::Database &db, std::mutex &db_mutex)
개별 클라이언트와의 연결을 처리하는 메인 함수입니다.
Definition tcp_server.cpp:183
void cleanup_client_connection(SSL *ssl, int client_socket, std::atomic< bool > &bbox_push_enabled, std::thread &push_thread, std::thread &metadata_thread)
클라이언트 연결을 정리하고 관련 리소스를 해제합니다.
Definition tcp_server.cpp:160
const int PORT
TCP 서버 포트 번호
Definition tcp_server.hpp:64
SSL * setup_ssl_connection(int client_socket)
클라이언트 소켓에 SSL 연결을 설정합니다.
Definition tcp_server.cpp:30
void initialize_database_tables(SQLite::Database &db)
데이터베이스 테이블들을 초기화합니다.
Definition tcp_server.cpp:56
void handle_login_step1_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
1단계 로그인 요청(ID/PW 검증)을 처리합니다. (request_id == 8)
Definition request_handlers.cpp:392
void handle_baseline_insert_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
도로 기준선 삽입 요청을 처리합니다. (request_id == 5)
Definition request_handlers.cpp:284
void handle_line_delete_all_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
감지선, 기준선, 수직선 전체 삭제 요청을 처리합니다. (request_id == 4)
Definition request_handlers.cpp:244
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)
Definition request_handlers.cpp:619
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)
Definition request_handlers.cpp:663
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 요청을 적절한 처리 함수로 라우팅합니다.
Definition tcp_server.cpp:105
string getLines()
카메라에서 라인 크로싱 설정을 가져옵니다.
Definition curl_camera.cpp:32
void handle_detection_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
감지 데이터 조회 요청을 처리합니다. (request_id == 1)
Definition request_handlers.cpp:48
string deleteLines(int index)
카메라에서 지정한 라인을 삭제합니다.
Definition curl_camera.cpp:266
void handle_line_select_all_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
감지선 전체 조회 요청을 처리합니다. (request_id == 3)
Definition request_handlers.cpp:159
void handle_line_insert_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
감지선 좌표값 삽입 요청을 처리합니다. (request_id == 2)
Definition request_handlers.cpp:89
void handle_baseline_select_all_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
도로 기준선 전체 조회 요청을 처리합니다. (request_id == 7)
Definition request_handlers.cpp:354
void handle_login_step2_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
2단계 로그인 요청(OTP/복구코드 검증)을 처리합니다. (request_id == 22)
Definition request_handlers.cpp:458
void handle_signup_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
회원가입 요청을 처리합니다. (request_id == 9)
Definition request_handlers.cpp:526
string putLines(CrossLine)
카메라에 라인 크로싱 설정을 전송합니다.
Definition curl_camera.cpp:129
void handle_vertical_line_insert_request(SSL *ssl, const json &received_json, SQLite::Database &db, std::mutex &db_mutex)
감지선의 수직선 방정식 삽입 요청을 처리합니다. (request_id == 6)
Definition request_handlers.cpp:322
bool receive_json_message(SSL *ssl, json &received_json)
SSL 연결에서 JSON 메시지를 수신합니다.
Definition tcp_server.cpp:71
int tcp_run()
TCP 서버를 시작하고 클라이언트 연결을 대기합니다.
Definition tcp_server.cpp:224