diff --git a/src/client.cpp b/src/client.cpp
index a0f522e..06176ae 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -4,8 +4,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along with this program. If not, see .
*/
-#include
-#include
#include
#include "client_functions.h"
@@ -17,17 +15,12 @@ int main(int argc, char* argv[])
{
string path, directory;
- if (!getInformation(path, directory, argc, argv)) {
- cerr << "Failed to get information\n";
- exit(-1);
- }
+ int pidInput = getInformation(path, directory, argc, argv);
- int server = fork();
+ if (pidInput == 0)
+ pidInput = setupServer(path, directory);
- if (server == 0)
- execl(path.c_str(), path.c_str(), directory.c_str(), nullptr);
-
- controlServer(server);
+ controlServer(pidInput);
return 0;
}
diff --git a/src/client_functions.cpp b/src/client_functions.cpp
new file mode 100644
index 0000000..fb2fb9f
--- /dev/null
+++ b/src/client_functions.cpp
@@ -0,0 +1,80 @@
+/*
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along with this program. If not, see .
+*/
+
+#include
+#include
+#include
+
+#include "client_functions.h"
+#include "signals.h"
+
+using namespace std;
+
+int getInformation(string& path, string& dir, int argc, char* argv[])
+{
+ if (argc > 2 && ((string)argv[1]).find("-p") != string::npos) {
+ return stoi(argv[2]);
+ }
+
+ switch(argc) {
+ case 3:
+ path = argv[1];
+ dir = argv[2];
+ break;
+ case 2:
+ path = argv[1];
+ cout << "Enter directory: ";
+ cin >> dir;
+ break;
+ default:
+ cout << "Enter path: ";
+ cin >> path;
+ cout << "Enter directory: ";
+ cin >> dir;
+ }
+
+ return 0;
+}
+
+int setupServer(string path, string directory)
+{
+ int server = fork();
+
+ if (server == 0)
+ execl(path.c_str(), path.c_str(), directory.c_str(), nullptr);
+
+ return server;
+}
+
+void controlServer(int 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;
+
+ 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;
+ }
+
+ kill(server, EXIT);
+}
diff --git a/src/client_functions.h b/src/client_functions.h
new file mode 100644
index 0000000..6c32347
--- /dev/null
+++ b/src/client_functions.h
@@ -0,0 +1,14 @@
+/*
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along with this program. If not, see .
+*/
+
+#include
+
+#ifndef CLIENT_FUNCTIONS_H
+ #define CLIENT_FUNCTIONS_H
+ int getInformation(std::string& path, std::string& dir, int argc, char* argv[]);
+ int setupServer(std::string path, std::string directory);
+ void controlServer(int server);
+#endif
diff --git a/src/server.cpp b/src/server.cpp
index a85a3cd..46aecb7 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -5,7 +5,6 @@ You should have received a copy of the GNU General Public License along with thi
*/
#include
-#include
#include "signals.h"
#include "server_functions.h"