This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
665 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "bidder.hpp" | ||
|
||
Bidder::Bidder() | ||
{ | ||
|
||
} | ||
|
||
Bidder::Bidder(std::string name, int argc, std::vector<std::string> argv) | ||
{ | ||
this->name = name; | ||
this->argv = argv; | ||
this->argc = argc; | ||
} | ||
|
||
Bidder::Bidder(const Bidder& rhs) | ||
{ | ||
this->name = rhs.getName(); | ||
this->argv = rhs.getArgs(); | ||
this->argc = rhs.getArgCount(); | ||
} | ||
|
||
Bidder::~Bidder() | ||
{ | ||
|
||
} | ||
|
||
std::string Bidder::getName() const | ||
{ | ||
return this->name; | ||
} | ||
|
||
std::vector<std::string> Bidder::getArgs() const | ||
{ | ||
return this->argv; | ||
} | ||
|
||
int Bidder::getArgCount() const | ||
{ | ||
return this->argc; | ||
} | ||
|
||
int Bidder::getDelay() const | ||
{ | ||
return this->delay; | ||
} | ||
|
||
struct timeval Bidder::getDelayStruct() const | ||
{ | ||
struct timeval delayStruct; | ||
delayStruct.tv_sec = this->delay / 1000; | ||
delayStruct.tv_usec = (this->delay % 1000) * 1000; | ||
return delayStruct; | ||
} | ||
|
||
void Bidder::setDelay(int delay) | ||
{ | ||
this->delay = delay; | ||
} | ||
|
||
pid_t Bidder::getPID() const | ||
{ | ||
return this->pid; | ||
} | ||
|
||
void Bidder::setPID(pid_t pid) | ||
{ | ||
this->pid = pid; | ||
} | ||
|
||
int Bidder::getExitStatus() const | ||
{ | ||
return this->exit_status; | ||
} | ||
|
||
void Bidder::setExitStatus(int status) | ||
{ | ||
this->exit_status = status; | ||
} | ||
|
||
bool Bidder::getStatus() const | ||
{ | ||
return this->isActive; | ||
} | ||
|
||
void Bidder::setStatus(bool status) | ||
{ | ||
this->isActive = status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef CENG334HOMEWORK1_BIDDER_HPP | ||
#define CENG334HOMEWORK1_BIDDER_HPP | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <sys/types.h> | ||
|
||
class Bidder { | ||
private: | ||
std::string name; | ||
std::vector<std::string> argv; | ||
int argc; | ||
int delay = 50; | ||
pid_t pid; | ||
int exit_status; | ||
bool isActive = true; | ||
|
||
public: | ||
Bidder(); | ||
Bidder(std::string name, int argc, std::vector<std::string> argv); | ||
Bidder(const Bidder& rhs); | ||
~Bidder(); | ||
std::string getName() const; | ||
std::vector<std::string> getArgs() const; | ||
int getArgCount() const; | ||
int getDelay() const; | ||
struct timeval getDelayStruct() const; | ||
void setDelay(int delay); | ||
pid_t getPID() const; | ||
void setPID(pid_t pid); | ||
int getExitStatus() const; | ||
void setExitStatus(int status); | ||
bool getStatus() const; | ||
void setStatus(bool status); | ||
|
||
}; | ||
|
||
#endif //CENG334HOMEWORK1_BIDDER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "logging.h" | ||
|
||
void print_output(oi* data, int client_id) { | ||
printf("COMM: 1 CID: %d TYPE: %d PID: %d ", client_id, data->type, data->pid); | ||
if (data->type == SERVER_CONNECTION_ESTABLISHED) | ||
printf("SBID: %d CBID: %d MI: %d \n", data->info.start_info.starting_bid, data->info.start_info.current_bid, data->info.start_info.minimum_increment); | ||
else if (data->type == SERVER_BID_RESULT) | ||
printf("RESULT: %d CBID: %d \n", data->info.result_info.result, data->info.result_info.current_bid); | ||
else | ||
printf("WINNER: %d WBID: %d \n", data->info.winner_info.winner_id, data->info.winner_info.winning_bid); | ||
} | ||
|
||
void print_input(ii* data, int client_id) { | ||
printf("COMM: 0 CID: %d TYPE: %d PID: %d ", client_id, data->type, data->pid); | ||
if (data->type == CLIENT_CONNECT) | ||
printf("DELAY: %d \n", data->info.delay); | ||
else if (data->type == CLIENT_BID) | ||
printf("BID: %d \n", data->info.bid); | ||
else | ||
printf("STATUS: %d \n", data->info.status); | ||
} | ||
|
||
void print_server_finished(int winner, int winning_bid) { | ||
printf("COMM: 2 W: %d WB: %d\n", winner, winning_bid); | ||
} | ||
|
||
void print_client_finished(int client_id, int status, int status_match) { | ||
printf("COMM: 3 CID: %d STATUS: %d SM: %d\n", client_id, status, status_match); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef CENG334HOMEWORK1_LOGGING_H | ||
#define CENG334HOMEWORK1_LOGGING_H | ||
|
||
|
||
#include "message.h" | ||
#ifndef __cplusplus | ||
#include <stdio.h> | ||
#else | ||
#include <cstdio> | ||
#endif | ||
|
||
typedef struct output_info { | ||
int type; | ||
int pid; | ||
smp info; | ||
} oi; | ||
|
||
typedef struct input_info { | ||
int type; | ||
int pid; | ||
cmp info; | ||
} ii; | ||
|
||
void print_output(oi* data, int client_id); | ||
void print_input(ii* data, int client_id); | ||
void print_server_finished(int winner, int winning_bid); | ||
void print_client_finished(int client_id, int status, int status_match); | ||
#endif //CENG334HOMEWORK1_LOGGING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CC=g++ | ||
CFLAGS=-c -std=c++14 | ||
|
||
all: logging.o server.o bidder.o utils.o methods.o | ||
$(CC) server.o logging.o bidder.o utils.o methods.o -o server | ||
|
||
logging.o: logging.h message.h | ||
$(CC) $(CFLAGS) logging.c -o logging.o | ||
|
||
server.o: server.cpp | ||
$(CC) $(CFLAGS) server.cpp -o server.o | ||
|
||
bidder.o : bidder.cpp | ||
$(CC) $(CFLAGS) bidder.cpp -o bidder.o | ||
|
||
utils.o : utils.cpp | ||
$(CC) $(CFLAGS) utils.cpp -o utils.o | ||
|
||
methods.o : methods.cpp | ||
$(CC) $(CFLAGS) methods.cpp -o methods.o | ||
|
||
clean: | ||
rm -f *.o | ||
rm server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef CENG334HOMEWORK1_MESSAGE_H | ||
#define CENG334HOMEWORK1_MESSAGE_H | ||
|
||
#define CLIENT_CONNECT 1 | ||
#define CLIENT_BID 2 | ||
#define CLIENT_FINISHED 3 | ||
|
||
#define SERVER_CONNECTION_ESTABLISHED 1 | ||
#define SERVER_BID_RESULT 2 | ||
#define SERVER_AUCTION_FINISHED 3 | ||
|
||
#define BID_ACCEPTED 0 | ||
#define BID_LOWER_THAN_STARTING_BID 1 | ||
#define BID_LOWER_THAN_CURRENT 2 | ||
#define BID_INCREMENT_LOWER_THAN_MINIMUM 3 | ||
|
||
typedef union client_message_parameters { | ||
int status; | ||
int bid; | ||
int delay; | ||
} cmp; | ||
|
||
typedef struct client_message { | ||
int message_id; //non-zero and unique message id | ||
cmp params; | ||
} cm; | ||
|
||
typedef struct connection_established_info { | ||
int client_id; | ||
int starting_bid; | ||
int current_bid; | ||
int minimum_increment; | ||
} cei; | ||
|
||
typedef struct bid_info { | ||
int result; | ||
int current_bid; | ||
} bi; | ||
|
||
typedef struct winner_info { | ||
int winner_id; | ||
int winning_bid; | ||
} wi; | ||
|
||
typedef union server_message_parameters { | ||
cei start_info; | ||
bi result_info; | ||
wi winner_info; | ||
} smp; | ||
|
||
typedef struct server_message { | ||
int message_id; //non-zero and unique message id | ||
smp params; | ||
} sm; | ||
|
||
#endif //CENG334HOMEWORK1_MESSAGE_H |
Oops, something went wrong.