Skip to content

Commit

Permalink
base directory AS done
Browse files Browse the repository at this point in the history
  • Loading branch information
simaosanguinho committed Dec 8, 2023
1 parent 099400f commit 78ff3a2
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DL_Store
.vscode
cli
cli
AS-DB
Binary file added AMS2023-01b-SysEng&Modeling_v2.pdf
Binary file not shown.
Binary file removed AS
Binary file not shown.
6 changes: 6 additions & 0 deletions src/server/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iomanip>
#include <iostream>

#include "../utils/protocol.hpp"
#include "../utils/utils.hpp"
#include "server_state.hpp"

Expand All @@ -14,6 +15,11 @@ void handleLogin(AuctionServerState &state, std::stringstream &buf,
(void)state;
(void)buf;
(void)addressFrom;

// check if directory names ASDIR exists
// if not, create it
if (!std::filesystem::exists(ASDIR))
std::filesystem::create_directory(ASDIR);
}

void handleLogout(AuctionServerState &state, std::stringstream &buf,
Expand Down
Binary file removed src/server/handlers.o
Binary file not shown.
Binary file removed src/server/server
Binary file not shown.
12 changes: 11 additions & 1 deletion src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ extern bool is_exiting;
int main(int argc, char *argv[]) {

try {

ServerConfig config(argc, argv);

if (config.help) {
config.printHelp(std::cout);
return EXIT_SUCCESS;
}

setup_custom_signal_handlers();
setupDB();

// TODO: print verbose mode activated if so

while (!is_exiting) {
}

} catch (...) {
std::cerr << "An error has ocurred while running the application. "
"Shutting down..."
Expand Down Expand Up @@ -68,4 +72,10 @@ void ServerConfig::printHelp(std::ostream &stream) {
stream << "Available options:" << std::endl;
stream << " -p ASport: Set the port number to listen on" << std::endl;
stream << " -v: Enable verbose logging" << std::endl;
}
}

void setupDB() {
create_directory(ASDIR);
create_directory(USERDIR);
create_directory(AUCTIONDIR);
};
2 changes: 2 additions & 0 deletions src/server/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ class ServerConfig {
};

void waitForUdpPacket(UdpPacket &packet);

void setupDB();
#endif
Binary file removed src/server/server.o
Binary file not shown.
Binary file removed src/server/server_state.o
Binary file not shown.
4 changes: 4 additions & 0 deletions src/utils/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@

#define SERVER_TIMEOUT 3

#define ASDIR "AS-DB"
#define USERDIR "AS-DB/USERS"
#define AUCTIONDIR "AS-DB/AUCTIONS"

#endif
Binary file removed src/utils/protocol.o
Binary file not shown.
9 changes: 9 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "utils.hpp"
#include <filesystem>

// Flag to indicate whether the application is terminating
bool is_exiting = false;
Expand Down Expand Up @@ -87,3 +88,11 @@ std::vector<std::string> parse_args(std::string args) {

return parameters;
}

void create_directory(const std::string &path) {
if (!std::filesystem::exists(path)) {
std::filesystem::create_directory(path);
return;
}
return;
}
7 changes: 7 additions & 0 deletions src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ bool is_alphanumeric(const std::string &str);
*/
std::vector<std::string> parse_args(std::string args);

/**
* @brief Creates a directory with the given path.
*
* @param path A reference to a string containing the path of the directory to
* be created.
*/
void create_directory(const std::string &path);
#endif
Binary file removed src/utils/utils.o
Binary file not shown.

0 comments on commit 78ff3a2

Please sign in to comment.