Code cleanup.
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.0)
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/pi/CPP")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/pi/CPP")
|
||||||
project(sstp VERSION 0.1.0 LANGUAGES C CXX)
|
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)
|
add_subdirectory(/home/pi/CPP/common /home/pi/CPP/common/build)
|
||||||
target_link_libraries(sstp PRIVATE common)
|
target_link_libraries(sstp PRIVATE common)
|
||||||
|
|||||||
130
sstp/main.cpp
130
sstp/main.cpp
@@ -1,103 +1,20 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <thread>
|
|
||||||
#include <vector>
|
|
||||||
#include <common/string.hpp>
|
#include <common/string.hpp>
|
||||||
#include <common/profiler.hpp>
|
#include <common/profiler.hpp>
|
||||||
#include <common/block.hpp>
|
#include <common/block.hpp>
|
||||||
#include <common/fileio.hpp>
|
|
||||||
#include <common/utility.hpp>
|
#include <common/utility.hpp>
|
||||||
#include <sstp/socketserver.hpp>
|
#include <sstp/socketserver.hpp>
|
||||||
#include <sstp/clientsocketsender.hpp>
|
#include <sstp/clientsocketsender.hpp>
|
||||||
|
#include <sstp/sstp.hpp>
|
||||||
|
|
||||||
void handleServer(Block<String> &commands); // handler for server mode
|
void handleServer(Block<String> &commands); // handler for server mode
|
||||||
void handleClient(Block<String> &commands); // handler for client mode
|
void handleClient(Block<String> &commands); // handler for client mode
|
||||||
bool registerSignalHandler(void); // registers a Control-c handler
|
bool registerSignalHandler(void); // registers a Control-c handler
|
||||||
void signalHandler(int signal); // The Control-C handler
|
void signalHandler(int signal); // The Control-C handler
|
||||||
|
|
||||||
class SSTP;
|
|
||||||
|
|
||||||
SmartPointer<SSTP> sstp;
|
SmartPointer<SSTP> sstp;
|
||||||
|
|
||||||
class SSTP
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SSTP();
|
|
||||||
~SSTP();
|
|
||||||
void handleServer(Block<String>& arguments);
|
|
||||||
void handleClient(Block<String>& arguments);
|
|
||||||
private:
|
|
||||||
SmartPointer<SocketServer> mSocketServer;
|
|
||||||
SmartPointer<ClientSocketSender> 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<String>& 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<String>& 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
|
/// @brief
|
||||||
@@ -137,12 +54,10 @@ int main(int argc, char **argv)
|
|||||||
if(arguments[1]=="SERVERMODE")
|
if(arguments[1]=="SERVERMODE")
|
||||||
{
|
{
|
||||||
sstp->handleServer(arguments);
|
sstp->handleServer(arguments);
|
||||||
// handleServer(arguments);
|
|
||||||
}
|
}
|
||||||
else if(arguments[1]=="CLIENTMODE")
|
else if(arguments[1]=="CLIENTMODE")
|
||||||
{
|
{
|
||||||
sstp->handleClient(arguments);
|
sstp->handleClient(arguments);
|
||||||
// handleClient(arguments);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -192,46 +107,3 @@ bool registerSignalHandler(void)
|
|||||||
return true;
|
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<String> &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<String> &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;
|
|
||||||
// }
|
|
||||||
|
|||||||
52
sstp/sstp.cpp
Normal file
52
sstp/sstp.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <sstp/sstp.hpp>
|
||||||
|
#include <common/profiler.hpp>
|
||||||
|
#include <common/utility.hpp>
|
||||||
|
#include <sstp/socketserver.hpp>
|
||||||
|
#include <sstp/clientsocketsender.hpp>
|
||||||
|
|
||||||
|
/// @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<String>& 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<String>& 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;
|
||||||
|
}
|
||||||
33
sstp/sstp.hpp
Normal file
33
sstp/sstp.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef _SSTP_SSTP_HPP_
|
||||||
|
#define _SSTP_SSTP_HPP_
|
||||||
|
#include <common/block.hpp>
|
||||||
|
#include <common/pointer.hpp>
|
||||||
|
|
||||||
|
class SocketServer;
|
||||||
|
class ClientSocketSender;
|
||||||
|
|
||||||
|
class SSTP
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SSTP();
|
||||||
|
~SSTP();
|
||||||
|
void handleServer(Block<String>& arguments);
|
||||||
|
void handleClient(Block<String>& arguments);
|
||||||
|
private:
|
||||||
|
SmartPointer<SocketServer> mSocketServer;
|
||||||
|
SmartPointer<ClientSocketSender> mClientSocketSender;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
SSTP::SSTP()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
SSTP::~SSTP()
|
||||||
|
{
|
||||||
|
mSocketServer.destroy();
|
||||||
|
mClientSocketSender.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user