Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
dchansen06 committed Dec 19, 2024
1 parent 866b856 commit f6a5397
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 12 deletions.
15 changes: 4 additions & 11 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <cstdlib>
#include <string>

#include "client_functions.h"
Expand All @@ -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;
}
80 changes: 80 additions & 0 deletions src/client_functions.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <cstdlib>
#include <string>

#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);
}
14 changes: 14 additions & 0 deletions src/client_functions.h
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

#include <string>

#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
1 change: 0 additions & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ You should have received a copy of the GNU General Public License along with thi
*/

#include <iostream>
#include <vector>

#include "signals.h"
#include "server_functions.h"
Expand Down

0 comments on commit f6a5397

Please # to comment.