Skip to content

Commit

Permalink
Add final docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
simaosanguinho committed Dec 17, 2023
1 parent f7d5e69 commit d0c47f1
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
Binary file removed src/server/server
Binary file not shown.
4 changes: 4 additions & 0 deletions src/server/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ void handle_packet(AuctionServerState &serverState, std::stringstream &buffer,
*/
void wait_for_tcp_packet(AuctionServerState &serverState, TcpWorkerPool &pool);

/**
* @brief Creates all the main directories and files of the AS Database.
*
*/
void setupDB();

#endif
1 change: 0 additions & 1 deletion src/server/tcp_worker_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void TcpWorkerPool::giveConnection(int fd) {
busy_threads[i] = true;
workers[i].tcpSocketFD = fd;
workers[i].to_execute = true;

workers[i].cond.notify_one();

state.verbose << "Sent to worker number " << i << std::endl;
Expand Down
18 changes: 18 additions & 0 deletions src/server/tcp_worker_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,28 @@ class TcpWorkerPool {
AuctionServerState &state;

TcpWorkerPool(AuctionServerState &auctionState);

/**
* @brief Attributes a socket to a worker that is available.
*
* @param fd socket file descriptor.
*/
void giveConnection(int fd);

/**
* @brief Frees a busy worker.
*
* @param workerID worker ID to be set free.
*/
void freeWorker(uint32_t workerID);
};

/**
* @brief Get the packet ID of a TCP message from a socket.
*
* @param fd TCP socket file descriptor.
* @return packet ID.
*/
std::string read_packet_id(int fd);

class AllWorkersBusyException : public std::runtime_error {
Expand Down
2 changes: 2 additions & 0 deletions src/server/verbose_stream.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <iostream>

/* Verbose Mode Implementation */

class VerboseStream {
bool active;

Expand Down
96 changes: 96 additions & 0 deletions src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,46 +242,142 @@ int8_t validateAssetFileSize(uint32_t assetSize);
*/
int8_t validateFileSize(std::string file_path);

/**
* @brief Get the User Password object
*
* @param userID ID of the user
* @return std::string
*/
std::string getUserPassword(std::string userID);

/**
* @brief Get the current date and time in a string format of 19B.
*
* @return string of the current date and time
*/
std::string getCurrentTimeFormated();

/**
* @brief Get the current date and time.
*
* @return string of the current date and time
*/
std::string getStartFullTime();

/**
* @brief Convert an integer to a string of given size.
*
* @param number integer to be converted
* @param size size of desired string
* @return string of the integer with zeros on the left
*/
std::string intToStringWithZeros(int number, size_t size);

/**
* @brief Get the first word of a file.
*
* @param path path of the file.
* @return string of first word of the file.
*/
std::string getFirstWord(std::string path);

/**
* @brief Calculate the time difference between two time instances.
*
* @param startTime
* @param endTime
* @return time difference in seconds in a string
*/
std::string getTimeDifferenceStr(std::string startTime, std::string endTime);

/**
* @brief Formatter for user auctions table.
*
* @param auctions vector of pairs containing the auction name and the auction
* status
*/
void printListUserAuctionsTable(
std::vector<std::pair<std::string, uint8_t>> auctions);

/**
* @brief Formatter for user bids table.
*
* @param auctions vector of pairs containing the auction name and the auction
* status
*/
void printListUserBidsTable(
std::vector<std::pair<std::string, uint8_t>> auctions);

/**
* @brief Formatter for list auctions table.
*
* @param auctions vector of pairs containing the auction name and the auction
* status
*/
void printListAuctionsTable(
std::vector<std::pair<std::string, uint8_t>> auctions);

/**
* @brief
*
* @param hostUID the host/owner user ID.
* @param auctionName auction name.
* @param assetFileName asset filename.
* @param startValue starting value of the auction.
* @param startDate date on which the auction was opened.
* @param timeActive duration set for the auction.
* @param bids list of bids made to the auction.
* @param end pair containing the user ID of the winner and the winning bid.
*/
void printListShowRecordTable(
std::string hostUID, std::string auctionName, std::string assetFileName,
uint32_t startValue, std::string startDate, uint32_t timeActive,
std::vector<std::tuple<std::string, uint32_t, std::string, uint32_t>> bids,
std::pair<std::string, uint32_t> end);

/**
* @brief split a string on a given separator.
*
* @param __str
* @param __separator
* @return vector of diferent words of the string.
*/
std::vector<std::string> splitOnSeparator(std::string __str, char __separator);

/**
* @brief Sort the bids of an auction by the bid value.
*
* @param auctionBids vector of tuples containing the user bidder ID, bid value, date.
*/
void sortAuctionBids(
std::vector<std::tuple<std::string, uint32_t, std::string, uint32_t>>
&auctionBids);

/**
* @brief Get the largest N bids of an auction.
*
* @param auctionBids tuple containing the user bidder ID, bid value, date of each bid.
* @param numBids maximum number of bids to be returned.
*/
void getTopNumBids(
std::vector<std::tuple<std::string, uint32_t, std::string, uint32_t>>
&auctionBids,
uint32_t numBids);

/**
* @brief Get the auction info about its closure.
*
* @param auctionID ID of the auction.
* @return date and time of the auction closure and the time that it remained opened.
*/
std::pair<std::string, uint32_t> getAuctionEndInfo(std::string auctionID);

/**
* @brief Get the auction bids.
*
* @param auctionID ID of the auction.
* @return vector of tuples containing the user bidder ID, bid value, date of each bid.
*/
std::vector<std::tuple<std::string, uint32_t, std::string, uint32_t>>
getAuctionBids(std::string auctionID);

Expand Down

0 comments on commit d0c47f1

Please sign in to comment.