Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dchansen06 committed Dec 19, 2024
1 parent e2a4079 commit 3b340a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 47 deletions.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ LDLIBS = $(shell sdl2-config --libs) $(shell sdl2-config --libs)_mixer

SRC_DIR = src
CLIENT_SRC := $(wildcard $(SRC_DIR)/client.cpp)
CLIENT2_SRC := $(wildcard $(SRC_DIR)/client2.cpp)
SERVER_SRC := $(wildcard $(SRC_DIR)/server*.cpp)

# Heavily inspired by https://stackoverflow.com/a/30602701
BUILD_DIR = build
BIN_DIR = $(BUILD_DIR)/bin
OBJ_DIR = $(BUILD_DIR)/obj
CLIENT_OBJ := $(CLIENT_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
CLIENT2_OBJ := $(CLIENT2_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
SERVER_OBJ := $(SERVER_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)

PROGRAM = $(BIN_DIR)/client $(BIN_DIR)/server $(BIN_DIR)/client2
Expand All @@ -36,9 +34,6 @@ $(BIN_DIR)/server: $(SERVER_OBJ) | $(BIN_DIR)
$(BIN_DIR)/client: $(CLIENT_OBJ) | $(BIN_DIR)
$(CXX) $(CXXFLAGS) $(^) -o $(@)

$(BIN_DIR)/client2: $(CLIENT2_OBJ) | $(BIN_DIR)
$(CXX) $(CXXFLAGS) $(^) -o $(@)

$(BIN_DIR) $(OBJ_DIR):
mkdir -p $@

Expand Down
62 changes: 33 additions & 29 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,53 @@ You should have received a copy of the GNU General Public License along with thi

#include <iostream>
#include <csignal>
#include <cstdlib>
#include <string>
#include <unistd.h>

#include "signals.h"

using namespace std;

int main(int argc, char* argv[])
{
int server;
if (argc != 3) {
cerr << "Invalid options\n";
exit(-1);
}

int server = fork();

if (argc == 2 && !kill(stoi(argv[1]), RESUME)) {
server = stoi(argv[1]);
if (server == 0) {
execl(argv[1], argv[1], argv[2], nullptr);
} else {
cout << "Enter PID of server: ";
cin >> server;
}
char input;
cout << "Gained control of server " << server << "\nEnter instructions: [R]esume, [P]ause, re[W]ind, [S]kip, [E]xit (or Ctrl+C to close)\n";
cin >> input;

char input;
cout << "Gained control of server\nEnter instructions: [R]esume, [P]ause, re[W]ind, [S]kip, [E]xit (or Ctrl+C to close)\n";
cin >> input;

while (tolower(input) != 'e') {
switch(tolower(input)) {
case 'w':
kill(server, REWIND);
break;
case 'p':
kill(server, PAUSE);
break;
case 'r':
kill(server, RESUME);
break;
case 's':
kill(server, SKIP);
break;
default:
cout << "Misunderstood input, enter R, P, S, or E only:\n";
while (tolower(input) != 'e') {
switch(tolower(input)) {
case 'w':
kill(server, REWIND);
break;
case 'p':
kill(server, PAUSE);
break;
case 'r':
kill(server, RESUME);
break;
case 's':
kill(server, SKIP);
break;
default:
cout << "Misunderstood input, enter R, P, S, or E only:\n";
}

cin >> input;
}

cin >> input;
kill(server, EXIT);
}

kill(server, EXIT);

return 0;
}
18 changes: 5 additions & 13 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,19 @@ You should have received a copy of the GNU General Public License along with thi
#include <iostream>
#include <vector>

#include <unistd.h>

#include "signals.h"
#include "server_functions.h"

using namespace std;

int main(int argc, char* argv[])
{
cout << "PID: " << getpid() << endl;

fspath path;

// if (argc > 1) {
path = argv[1];
// } else {
// cout << "Enter directory ";
// cin >> path;
// }
if (argc != 2) {
cerr << "Invalid option\n";
exit(-1);
}

music_list validmusic = findMusicFiles(path);
music_list validmusic = findMusicFiles(argv[1]);
shuffleMusic(validmusic);
playMusic(validmusic, 250);
}

0 comments on commit 3b340a7

Please # to comment.