diff --git a/Makefile b/Makefile index 178e3b9..36b1e05 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ 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 @@ -17,7 +16,6 @@ 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 @@ -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 $@ diff --git a/src/client.cpp b/src/client.cpp index 726f5a2..58f299c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -6,7 +6,9 @@ You should have received a copy of the GNU General Public License along with thi #include #include +#include #include +#include #include "signals.h" @@ -14,41 +16,43 @@ 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; } diff --git a/src/server.cpp b/src/server.cpp index bb2eb56..a85a3cd 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -7,8 +7,6 @@ You should have received a copy of the GNU General Public License along with thi #include #include -#include - #include "signals.h" #include "server_functions.h" @@ -16,18 +14,12 @@ 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); }