Skip to content

Commit

Permalink
remove unused class-es, fix includes
Browse files Browse the repository at this point in the history
  • Loading branch information
fszontagh committed Jan 11, 2025
1 parent d9cc316 commit d7df235
Show file tree
Hide file tree
Showing 16 changed files with 429 additions and 764 deletions.
12 changes: 10 additions & 2 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ set(SERVER_BINARY_NAME "${PROJECT_BINARY_NAME}_server")
set(SOURCES src/main.cpp src/TerminalApp.cpp src/SocketApp.cpp)

if (MSVC)
list(APPEND SOURCES ${CMAKE_SOURCE_DIR}/minimal.rc)
set(BNAME ${SERVER_BINARY_NAME})
set(COMPONENT_NAME "${PROJECT_DISPLAY_NAME} Server")
configure_file(../platform/msvc/app.rc.in app.rc)
configure_file(../platform/msvc/minimal.rc.in minimal.rc)
list(APPEND SOURCES minimal.rc)
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/app.rc)
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/minimal.rc)
endif()

add_executable(${SERVER_BINARY_NAME} ${SOURCES} ${CMAKE_SOURCE_DIR}/src/libs/SharedLibrary.cpp ${CMAKE_SOURCE_DIR}/src/libs/SharedMemoryManager.cpp)
add_dependencies(${SERVER_BINARY_NAME} sockets_cpp)
#target_precompile_headers(${SERVER_BINARY_NAME} PRIVATE src/pch.h)
target_precompile_headers(${SERVER_BINARY_NAME} PRIVATE src/pch.h)

if (MSVC)
target_link_options(${SERVER_BINARY_NAME} PRIVATE /STACK:${STACK_SIZE})
Expand All @@ -17,6 +23,8 @@ else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,stack-size=${STACK_SIZE}")
endif()



target_include_directories(${SERVER_BINARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/server/src ${CMAKE_SOURCE_DIR}/src ${sockets_cpp_SOURCE} ${wxWidgets_SOURCE_DIR}/include ${exiv2_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})


Expand Down
5 changes: 0 additions & 5 deletions server/src/ServerConfig.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#ifndef __SERVER_CONFIG_H
#define __SERVER_CONFIG_H

#include <cstddef>
#include <cstdint>

#include "libs/json.hpp"

enum class backend_type {
AVX,
AVX2,
Expand Down
17 changes: 8 additions & 9 deletions server/src/SocketApp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "SocketApp.h"
#include "TerminalApp.h"
SocketApp::SocketApp(const char* listenAddr, uint16_t port, TerminalApp* parent)
: m_socketOpt({sockets::TX_BUFFER_SIZE, sockets::RX_BUFFER_SIZE, listenAddr}), m_server(*this, &m_socketOpt), parent(parent) {
sockets::SocketRet ret = m_server.start(port);
Expand Down Expand Up @@ -80,8 +79,8 @@ void SocketApp::onClientConnect(const sockets::ClientHandle& client) {
this->m_clientInfo[client] = {ipAddr, port, client, wxGetLocalTime()};
}
sd_gui_utils::networks::Packet auth_required_packet;
auth_required_packet.type = sd_gui_utils::networks::PacketType::REQUEST;
auth_required_packet.param = sd_gui_utils::networks::PacketParam::AUTH;
auth_required_packet.type = sd_gui_utils::networks::Packet::Type::REQUEST_TYPE;
auth_required_packet.param = sd_gui_utils::networks::Packet::Param::PARAM_AUTH;
this->sendMsg(client, auth_required_packet);
}
}
Expand All @@ -107,7 +106,7 @@ void SocketApp::OnTimer() {
} else {
if (it->second.last_keepalive == 0 || (wxGetLocalTime() - it->second.last_keepalive) > this->parent->configData->tcp_keepalive) {
it->second.last_keepalive = wxGetLocalTime();
this->sendMsg(it->second.idx, sd_gui_utils::networks::Packet(sd_gui_utils::networks::PacketType::REQUEST, sd_gui_utils::networks::PacketParam::KEEPALIVE));
this->sendMsg(it->second.idx, sd_gui_utils::networks::Packet(sd_gui_utils::networks::Packet::Type::REQUEST_TYPE, sd_gui_utils::networks::Packet::Param::PARAM_KEEPALIVE));
}
++it;
}
Expand All @@ -118,19 +117,19 @@ void SocketApp::parseMsg(sd_gui_utils::networks::Packet& packet) {
// parse from cbor to struct Packet
try {
if (packet.version != SD_GUI_VERSION) {
auto errorPacket = sd_gui_utils::networks::Packet(sd_gui_utils::networks::PacketType::RESPONSE, sd_gui_utils::networks::PacketParam::ERROR);
auto errorPacket = sd_gui_utils::networks::Packet(sd_gui_utils::networks::Packet::Type::RESPONSE_TYPE, sd_gui_utils::networks::Packet::Param::PARAM_ERROR);
errorPacket.SetData("Version Mismatch, server: " + std::string(SD_GUI_VERSION) + ", client: " + packet.version);
this->sendMsg(packet.source_idx, errorPacket);
this->parent->sendLogEvent(wxString::Format("Version Mismatch, server: %s, client: %s", SD_GUI_VERSION, packet.version), wxLOG_Error);
this->DisconnectClient(packet.source_idx);
return;
}
if (packet.type == sd_gui_utils::networks::PacketType::REQUEST) {
if (packet.type == sd_gui_utils::networks::Packet::Type::REQUEST_TYPE) {
this->parent->ProcessReceivedSocketPackages(packet);
}
// handle the response to the auth request
if (packet.type == sd_gui_utils::networks::PacketType::RESPONSE) {
if (packet.param == sd_gui_utils::networks::PacketParam::AUTH) {
if (packet.type == sd_gui_utils::networks::Packet::Type::RESPONSE_TYPE) {
if (packet.param == sd_gui_utils::networks::Packet::Param::PARAM_AUTH) {
{
std::lock_guard<std::mutex> guard(m_mutex);
std::string packetData = packet.GetData<std::string>();
Expand All @@ -140,7 +139,7 @@ void SocketApp::parseMsg(sd_gui_utils::networks::Packet& packet) {
this->m_clientInfo[packet.source_idx].apikey = packetData;
this->parent->sendLogEvent("Client authenticated: " + std::to_string(packet.source_idx), wxLOG_Info);
} else {
auto errorPacket = sd_gui_utils::networks::Packet(sd_gui_utils::networks::PacketType::RESPONSE, sd_gui_utils::networks::PacketParam::ERROR);
auto errorPacket = sd_gui_utils::networks::Packet(sd_gui_utils::networks::Packet::Type::RESPONSE_TYPE, sd_gui_utils::networks::Packet::Param::PARAM_ERROR);
errorPacket.SetData("Authentication Failed");
this->sendMsg(packet.source_idx, errorPacket);
this->parent->sendLogEvent("Authentication Failed, ip: " + this->m_clientInfo[packet.source_idx].host + " port: " + std::to_string(this->m_clientInfo[packet.source_idx].port) + " key: " + this->m_clientInfo[packet.source_idx].apikey + "", wxLOG_Error);
Expand Down
9 changes: 0 additions & 9 deletions server/src/SocketApp.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#ifndef _SERVER_SOCKETAPP_H
#define _SERVER_SOCKETAPP_H
#include <map>

#include <wx/log.h>
#include <wx/time.h>
#include <wx/timer.h>
#include "libs/json.hpp"

#include "network/packets.h"
#include "sockets-cpp/TcpServer.h"



Expand Down
6 changes: 3 additions & 3 deletions server/src/TerminalApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool TerminalApp::ProcessEventHandler(std::string message) {
}
try {
nlohmann::json msg = nlohmann::json::parse(message);
sd_gui_utils::networks::Packet packet(sd_gui_utils::networks::PacketType::REQUEST, sd_gui_utils::networks::PacketParam::ERROR);
sd_gui_utils::networks::Packet packet(sd_gui_utils::networks::Packet::Type::REQUEST_TYPE, sd_gui_utils::networks::Packet::Param::PARAM_ERROR);
packet.SetData(message);
this->socket->sendMsg(0, packet);

Expand All @@ -371,8 +371,8 @@ void TerminalApp::ProcessReceivedSocketPackages(const sd_gui_utils::networks::Pa
this->sendLogEvent("Invalid source index", wxLOG_Error);
return;
}
if (packet.param == sd_gui_utils::networks::PacketParam::MODEL_LIST) {
auto response = sd_gui_utils::networks::Packet(sd_gui_utils::networks::PacketType::RESPONSE, sd_gui_utils::networks::PacketParam::MODEL_LIST);
if (packet.param == sd_gui_utils::networks::Packet::Param::PARAM_MODEL_LIST) {
auto response = sd_gui_utils::networks::Packet(sd_gui_utils::networks::Packet::Type::RESPONSE_TYPE, sd_gui_utils::networks::Packet::Param::PARAM_MODEL_LIST);
std::vector<sd_gui_utils::networks::RemoteModelInfo> list;
for (auto model : this->modelFiles) {
// change the model's path
Expand Down
22 changes: 0 additions & 22 deletions server/src/TerminalApp.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
#ifndef _SERVER_TERMINALAPP_H
#define _SERVER_TERMINALAPP_H

#include "libs/SharedLibrary.h"

#include <wx/app.h>
#include <wx/evtloop.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/textfile.h>
#include <wx/timer.h>

#include <iostream>
#include "libs/json.hpp"
#include "network/RemoteModelInfo.h"

#include "ServerConfig.h"
#include "SocketApp.h"
#include "helpers/sslUtils.hpp"
#include "libs/ExternalProcess.h"

#include "EventQueue.h"

wxDECLARE_APP(TerminalApp);

class TerminalApp : public wxAppConsole {
Expand Down
40 changes: 40 additions & 0 deletions server/src/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <map>
#include <string>
#include <vector>
#include <cstddef>
#include <cstdint>

#include "libs/SharedLibrary.h"


#include <wx/app.h>
#include <wx/evtloop.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/textfile.h>
#include <wx/time.h>
#include <wx/timer.h>
#include <wx/event.h>

#include "sockets-cpp/TcpServer.h"
#include "EventQueue.h"
#include "libs/SharedLibrary.h"
#include "libs/SharedMemoryManager.h"
#include "ver.hpp"
#include "extprocess/config.hpp"
#include "libs/json.hpp"
#include "helpers/sslUtils.hpp"
#include "network/packets.h"
#include "network/RemoteModelInfo.h"

#include "ServerConfig.h"
#include "SocketApp.h"
#include "TerminalApp.h"
#include "EventQueue.h"

#include "ServerConfig.h"


#include "libs/json.hpp"

Loading

0 comments on commit d7df235

Please sign in to comment.