From 6c70a3c14122b4ff32026f5c4b943840e8ce2096 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 16 Aug 2025 21:37:16 -0400 Subject: [PATCH] Code cleanup. --- sstp/CMakeLists.txt | 2 +- sstp/main.cpp | 130 +------------------------------------------- sstp/sstp.cpp | 52 ++++++++++++++++++ sstp/sstp.hpp | 33 +++++++++++ 4 files changed, 87 insertions(+), 130 deletions(-) create mode 100644 sstp/sstp.cpp create mode 100644 sstp/sstp.hpp diff --git a/sstp/CMakeLists.txt b/sstp/CMakeLists.txt index 31eb352..9dc6321 100644 --- a/sstp/CMakeLists.txt +++ b/sstp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.0) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/pi/CPP") project(sstp VERSION 0.1.0 LANGUAGES C CXX) -add_executable(sstp main.cpp clientsocketsender.cpp socketconnectionreceiver.cpp socketserver.cpp) +add_executable(sstp main.cpp clientsocketsender.cpp socketconnectionreceiver.cpp socketserver.cpp sstp.cpp) add_subdirectory(/home/pi/CPP/common /home/pi/CPP/common/build) target_link_libraries(sstp PRIVATE common) diff --git a/sstp/main.cpp b/sstp/main.cpp index 7866217..e464c76 100644 --- a/sstp/main.cpp +++ b/sstp/main.cpp @@ -1,103 +1,20 @@ -#include #include -#include -#include -#include -#include #include -#include -#include -#include #include #include #include -#include #include #include #include +#include void handleServer(Block &commands); // handler for server mode void handleClient(Block &commands); // handler for client mode bool registerSignalHandler(void); // registers a Control-c handler void signalHandler(int signal); // The Control-C handler -class SSTP; - SmartPointer sstp; -class SSTP -{ - public: - SSTP(); - ~SSTP(); - void handleServer(Block& arguments); - void handleClient(Block& arguments); - private: - SmartPointer mSocketServer; - SmartPointer mClientSocketSender; -}; - -inline -SSTP::SSTP() -{ -} - -inline -SSTP::~SSTP() -{ - mSocketServer.destroy(); - mClientSocketSender.destroy(); -} - -/// @brief [0]=program [1]=SERVERMODE [2]={port} -/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion -/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer() -/// @param commands -inline -void SSTP::handleServer(Block& commands) -{ - Profiler profiler; - - if(commands.size()!=3) - { - std::cout << "Missing required parameters" << std::endl; - return; - } - int port = commands[2].toInt(); - std::cout << commands[1] << ":" << commands[2] << std::endl; - mSocketServer = ::new SocketServer(commands[2].toInt()); - mSocketServer.disposition(PointerDisposition::Delete); - mSocketServer->listen(); - std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; -} - -/// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename -/// @param commands -inline -void SSTP::handleClient(Block& arguments) -{ - Profiler profiler; - if(arguments.size()!=5) - { - std::cout << "Missing required parameters" << std::endl; - return; - } - mClientSocketSender.destroy(); - mClientSocketSender = new ClientSocketSender(arguments[2],arguments[3].toInt()); - mClientSocketSender.disposition(PointerDisposition::Delete); - bool returnCode = mClientSocketSender->sendFile(arguments[4]); - if(!returnCode) - { - std::cout << "The transfer failed." << std::endl; - } - else - { - std::cout << "Transfer complete" << std::endl; - } - std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; -} - - // **************************************************************************************************************************************************************** /// @brief @@ -137,12 +54,10 @@ int main(int argc, char **argv) if(arguments[1]=="SERVERMODE") { sstp->handleServer(arguments); -// handleServer(arguments); } else if(arguments[1]=="CLIENTMODE") { sstp->handleClient(arguments); -// handleClient(arguments); } else { @@ -192,46 +107,3 @@ bool registerSignalHandler(void) return true; } -/// @brief [0]=program [1]=SERVERMODE [2]={port} -/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion -/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer() -/// @param commands -// void handleServer(Block &commands) -// { -// Profiler profiler; - -// if(commands.size()!=3) -// { -// std::cout << "Missing required parameters" << std::endl; -// return; -// } -// int port = commands[2].toInt(); -// std::cout << commands[1] << ":" << commands[2] << std::endl; -// SocketServer socketServer(commands[2].toInt()); -// socketServer.listen(); -// std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; -// } - -/// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename -/// @param commands -// void handleClient(Block &commands) -// { -// Profiler profiler; -// if(commands.size()!=5) -// { -// std::cout << "Missing required parameters" << std::endl; -// return; -// } - -// ClientSocketSender clientSocketSender(commands[2],commands[3].toInt()); -// bool returnCode = clientSocketSender.sendFile(commands[4]); -// if(!returnCode) -// { -// std::cout << "The transfer failed." << std::endl; -// } -// else -// { -// std::cout << "Transfer complete" << std::endl; -// } -// std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; -// } diff --git a/sstp/sstp.cpp b/sstp/sstp.cpp new file mode 100644 index 0000000..f255f25 --- /dev/null +++ b/sstp/sstp.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +/// @brief [0]=program [1]=SERVERMODE [2]={port} +/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion +/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer() +/// @param commands +void SSTP::handleServer(Block& commands) +{ + Profiler profiler; + + if(commands.size()!=3) + { + std::cout << "Missing required parameters" << std::endl; + return; + } + int port = commands[2].toInt(); + std::cout << commands[1] << ":" << commands[2] << std::endl; + mSocketServer = ::new SocketServer(commands[2].toInt()); + mSocketServer.disposition(PointerDisposition::Delete); + mSocketServer->listen(); + std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; +} + +/// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename +/// @param commands +void SSTP::handleClient(Block& arguments) +{ + Profiler profiler; + if(arguments.size()!=5) + { + std::cout << "Missing required parameters" << std::endl; + return; + } + mClientSocketSender.destroy(); + mClientSocketSender = new ClientSocketSender(arguments[2],arguments[3].toInt()); + mClientSocketSender.disposition(PointerDisposition::Delete); + bool returnCode = mClientSocketSender->sendFile(arguments[4]); + if(!returnCode) + { + std::cout << "The transfer failed." << std::endl; + } + else + { + std::cout << "Transfer complete" << std::endl; + } + std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; +} diff --git a/sstp/sstp.hpp b/sstp/sstp.hpp new file mode 100644 index 0000000..e69a57d --- /dev/null +++ b/sstp/sstp.hpp @@ -0,0 +1,33 @@ +#ifndef _SSTP_SSTP_HPP_ +#define _SSTP_SSTP_HPP_ +#include +#include + +class SocketServer; +class ClientSocketSender; + +class SSTP +{ + public: + SSTP(); + ~SSTP(); + void handleServer(Block& arguments); + void handleClient(Block& arguments); + private: + SmartPointer mSocketServer; + SmartPointer mClientSocketSender; +}; + +inline +SSTP::SSTP() +{ +} + +inline +SSTP::~SSTP() +{ + mSocketServer.destroy(); + mClientSocketSender.destroy(); +} + +#endif