made the communication between the server and cmdline client more direct
This commit is contained in:
parent
1bb5864a29
commit
f1e2c85e3a
@ -47,51 +47,10 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "time")) {
|
bzero(buffer, 256);
|
||||||
strcpy(buffer, "current_time");
|
for (int i = 1; i < argc; i++) {
|
||||||
} else if (!strcmp(argv[1], "start")) {
|
strcat(buffer, argv[i]);
|
||||||
strcpy(buffer, "start");
|
strcat(buffer, " ");
|
||||||
} else if (!strcmp(argv[1], "stop")) {
|
|
||||||
strcpy(buffer, "stop");
|
|
||||||
} else if (!strcmp(argv[1], "kill")) {
|
|
||||||
strcpy(buffer, "kill");
|
|
||||||
} else if (!strcmp(argv[1], "split")) {
|
|
||||||
strcpy(buffer, "split");
|
|
||||||
} else if (!strcmp(argv[1], "skip")) {
|
|
||||||
strcpy(buffer, "skip");
|
|
||||||
} else if (!strcmp(argv[1], "pause")) {
|
|
||||||
strcpy(buffer, "pause");
|
|
||||||
} else if (!strcmp(argv[1], "resume")) {
|
|
||||||
strcpy(buffer, "resume");
|
|
||||||
} else if (!strcmp(argv[1], "undo")) {
|
|
||||||
strcpy(buffer, "undo");
|
|
||||||
} else if (!strcmp(argv[1], "redo")) {
|
|
||||||
strcpy(buffer, "redo");
|
|
||||||
} else if (!strcmp(argv[1], "foreground")) {
|
|
||||||
strcpy(buffer, "Foreground-Color");
|
|
||||||
} else if (!strcmp(argv[1], "background")) {
|
|
||||||
strcpy(buffer, "Background-Color");
|
|
||||||
} else if (!strcmp(argv[1], "save")) {
|
|
||||||
strcpy(buffer, "save");
|
|
||||||
} else if (!strcmp(argv[1], "runs")) {
|
|
||||||
strcpy(buffer, "run_count");
|
|
||||||
} else if (!strcmp(argv[1], "segments")) {
|
|
||||||
strcpy(buffer, "segment_count");
|
|
||||||
} else if (!strcmp(argv[1], "start-split-stop")) {
|
|
||||||
strcpy(buffer, "start-split-stop");
|
|
||||||
} else if (!strcmp(argv[1], "pause-resume")) {
|
|
||||||
strcpy(buffer, "pause-resume");
|
|
||||||
} else if (!strcmp(argv[1], "start-stop")) {
|
|
||||||
strcpy(buffer, "start-stop");
|
|
||||||
} else if (!strcmp(argv[1], "start-split")) {
|
|
||||||
strcpy(buffer, "start-split");
|
|
||||||
} else if (!strcmp(argv[1], "split-stop")) {
|
|
||||||
strcpy(buffer, "split-stop");
|
|
||||||
} else if (!strcmp(argv[1], "undo-redo")) {
|
|
||||||
strcpy(buffer, "undo-redo");
|
|
||||||
} else {
|
|
||||||
perror("No valid command given");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send message to the server */
|
/* Send message to the server */
|
||||||
@ -104,26 +63,11 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Now read server response */
|
/* Now read server response */
|
||||||
bzero(buffer,256);
|
bzero(buffer,256);
|
||||||
n = read(sockfd, &buffer, 256);
|
n = read(sockfd, &buffer, 256);
|
||||||
|
|
||||||
//read an int response
|
|
||||||
if (!strcmp(argv[1], "time") || !strcmp(argv[1], "runs") || !strcmp(argv[1], "segments")) {
|
|
||||||
int x = -1;
|
|
||||||
x = *(int*)&buffer;
|
|
||||||
if (n < 0) {
|
|
||||||
perror("ERROR reading from socket");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (x != -1)
|
|
||||||
printf("%d\n",x);
|
|
||||||
}
|
|
||||||
//read a string response
|
|
||||||
else {
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
perror("ERROR reading from socket");
|
perror("ERROR reading from socket");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (buffer != NULL)
|
if (buffer != NULL)
|
||||||
printf("%s", buffer);
|
printf("%s\n", buffer);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,9 @@ void timespecToRFC3339(struct timespec t, char buf[]);
|
|||||||
void loadFiles();
|
void loadFiles();
|
||||||
void add_segment(char *sname, char *lname, char *desc);
|
void add_segment(char *sname, char *lname, char *desc);
|
||||||
void addFile(char *path);
|
void addFile(char *path);
|
||||||
void sendValue(int sock, char* name);
|
|
||||||
void sendInt(int sock, int value);
|
void sendInt(int sock, int value);
|
||||||
|
void sendValue(int sock, char* name);
|
||||||
|
void sendString(int sock, char* str);
|
||||||
void doprocessing (int sock);
|
void doprocessing (int sock);
|
||||||
void addPauseTime();
|
void addPauseTime();
|
||||||
void subtractPauseTime();
|
void subtractPauseTime();
|
||||||
@ -397,7 +398,6 @@ void loadFiles()
|
|||||||
char buff2[255];
|
char buff2[255];
|
||||||
|
|
||||||
for (int i = 0; i < files; i++) {
|
for (int i = 0; i < files; i++) {
|
||||||
printf("loading file: \"%s\"\n", filePaths[i]);
|
|
||||||
fp = fopen(filePaths[i], "r+");
|
fp = fopen(filePaths[i], "r+");
|
||||||
while(1) {
|
while(1) {
|
||||||
if (!fgets(buff, 255, fp))
|
if (!fgets(buff, 255, fp))
|
||||||
@ -459,17 +459,6 @@ void loadFiles()
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Print metadata arrays
|
|
||||||
for (int i = 0; i < valuecount; i++) {
|
|
||||||
printf("%s | %s", names[i], values[i]);
|
|
||||||
}
|
|
||||||
//Print segments
|
|
||||||
for (int i = 0; i < segment_count; i++) {
|
|
||||||
printf("Segment %d: %s\n", i, segments[i].shortname);
|
|
||||||
}
|
|
||||||
//Print run count
|
|
||||||
printf("%d\n", run_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_segment(char *sname, char *lname, char *desc)
|
void add_segment(char *sname, char *lname, char *desc)
|
||||||
@ -505,7 +494,7 @@ int current_ms()
|
|||||||
void sendInt(int sock, int value)
|
void sendInt(int sock, int value)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
strncpy(buffer, (char*)&value, sizeof(int));
|
sprintf(buffer, "%d", value);
|
||||||
int n = write(sock, &buffer, 256);
|
int n = write(sock, &buffer, 256);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
perror("ERROR writing to socket");
|
perror("ERROR writing to socket");
|
||||||
@ -535,79 +524,95 @@ void sendValue(int sock, char* name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendString(int sock, char* str)
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
strcpy(buffer, str);
|
||||||
|
int n = write(sock, &buffer, 256);
|
||||||
|
if (n < 0) {
|
||||||
|
perror("ERROR writing to socket");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void doprocessing (int sock)
|
void doprocessing (int sock)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
n = read(sock, &buffer, 256);
|
n = read(sock, &buffer, 256);
|
||||||
|
char *token = strtok(buffer, " ");
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
perror("ERROR reading from socket");
|
perror("ERROR reading from socket");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!strcmp(buffer, "current_time")) {
|
if (!strcmp(token, "current_time")) {
|
||||||
//printf("Recieved time command\n");
|
//printf("Recieved time command\n");
|
||||||
sendInt(sock, current_ms());
|
sendInt(sock, current_ms());
|
||||||
} else if (!strcmp(buffer, "start")) {
|
} else if (!strcmp(token, "start")) {
|
||||||
printf("Recieved start command\n");
|
printf("Recieved start command\n");
|
||||||
start();
|
start();
|
||||||
} else if (!strcmp(buffer, "stop")) {
|
} else if (!strcmp(token, "stop")) {
|
||||||
printf("Recieved stop command\n");
|
printf("Recieved stop command\n");
|
||||||
stop();
|
stop();
|
||||||
} else if (!strcmp(buffer, "kill")) {
|
} else if (!strcmp(token, "kill")) {
|
||||||
printf("Recieved kill command\n");
|
printf("Recieved kill command\n");
|
||||||
alive = false;
|
alive = false;
|
||||||
} else if (!strcmp(buffer, "split")) {
|
} else if (!strcmp(token, "split")) {
|
||||||
printf("Recieved split command\n");
|
printf("Recieved split command\n");
|
||||||
split();
|
split();
|
||||||
} else if (!strcmp(buffer, "skip")) {
|
} else if (!strcmp(token, "skip")) {
|
||||||
printf("Recieved skip command\n");
|
printf("Recieved skip command\n");
|
||||||
skip();
|
skip();
|
||||||
} else if (!strcmp(buffer, "pause")) {
|
} else if (!strcmp(token, "pause")) {
|
||||||
printf("Recieved pause command\n");
|
printf("Recieved pause command\n");
|
||||||
pause_timer();
|
pause_timer();
|
||||||
} else if (!strcmp(buffer, "resume")) {
|
} else if (!strcmp(token, "resume")) {
|
||||||
printf("Recieved resume command\n");
|
printf("Recieved resume command\n");
|
||||||
resume();
|
resume();
|
||||||
} else if (!strcmp(buffer, "undo")) {
|
} else if (!strcmp(token, "undo")) {
|
||||||
printf("Recieved undo command\n");
|
printf("Recieved undo command\n");
|
||||||
undo();
|
undo();
|
||||||
} else if (!strcmp(buffer, "redo")) {
|
} else if (!strcmp(token, "redo")) {
|
||||||
printf("Recieved redo command\n");
|
printf("Recieved redo command\n");
|
||||||
redo();
|
redo();
|
||||||
} else if (!strcmp(buffer, "Foreground-Color")) {
|
} else if (!strcmp(token, "Foreground-Color")) {
|
||||||
printf("Recieved request for foreground color\n");
|
printf("Recieved request for foreground color\n");
|
||||||
sendValue(sock, "Foreground-Color");
|
sendValue(sock, "Foreground-Color");
|
||||||
} else if (!strcmp(buffer, "Background-Color")) {
|
} else if (!strcmp(token, "Background-Color")) {
|
||||||
printf("Recieved request for background color\n");
|
printf("Recieved request for background color\n");
|
||||||
sendValue(sock, "Background-Color");
|
sendValue(sock, "Background-Color");
|
||||||
} else if (!strcmp(buffer, "save")) {
|
} else if (!strcmp(token, "save")) {
|
||||||
printf("Recieved save command\n");
|
printf("Recieved save command\n");
|
||||||
appendRunToFile();
|
appendRunToFile();
|
||||||
} else if (!strcmp(buffer, "run_count")) {
|
} else if (!strcmp(token, "run_count")) {
|
||||||
printf("Recieved request for run count\n");
|
printf("Recieved request for run count\n");
|
||||||
sendInt(sock, run_count);
|
sendInt(sock, run_count);
|
||||||
} else if (!strcmp(buffer, "segment_count")) {
|
} else if (!strcmp(token, "segment_count")) {
|
||||||
printf("Recieved request for segment count\n");
|
printf("Recieved request for segment count\n");
|
||||||
sendInt(sock, segment_count);
|
sendInt(sock, segment_count);
|
||||||
} else if (!strcmp(buffer, "start_split_stop")) {
|
} else if (!strcmp(token, "start_split_stop")) {
|
||||||
printf("Recieved start_split_stop command\n");
|
printf("Recieved start_split_stop command\n");
|
||||||
start_split_stop();
|
start_split_stop();
|
||||||
} else if (!strcmp(buffer, "pause_resume")) {
|
} else if (!strcmp(token, "pause_resume")) {
|
||||||
printf("Recieved pause_resume command\n");
|
printf("Recieved pause_resume command\n");
|
||||||
pause_resume();
|
pause_resume();
|
||||||
} else if (!strcmp(buffer, "start-stop")) {
|
} else if (!strcmp(token, "start-stop")) {
|
||||||
printf("Recieved start-stop command\n");
|
printf("Recieved start-stop command\n");
|
||||||
start_stop();
|
start_stop();
|
||||||
} else if (!strcmp(buffer, "start-split")) {
|
} else if (!strcmp(token, "start-split")) {
|
||||||
printf("Recieved start-split command\n");
|
printf("Recieved start-split command\n");
|
||||||
start_split();
|
start_split();
|
||||||
} else if (!strcmp(buffer, "split-stop")) {
|
} else if (!strcmp(token, "split-stop")) {
|
||||||
printf("Recieved split-stop command\n");
|
printf("Recieved split-stop command\n");
|
||||||
split_stop();
|
split_stop();
|
||||||
} else if (!strcmp(buffer, "undo-redo")) {
|
} else if (!strcmp(token, "undo-redo")) {
|
||||||
printf("Recieved undo-redo command\n");
|
printf("Recieved undo-redo command\n");
|
||||||
undo_redo();
|
undo_redo();
|
||||||
|
} else if (!strcmp(token, "segment_name")) {
|
||||||
|
token = strtok(NULL, " ");
|
||||||
|
int x = atoi(token);
|
||||||
|
printf("Recieved request for segment %s's name: %s\n", token, segments[x].shortname);
|
||||||
|
sendString(sock, segments[x].shortname);
|
||||||
} else {
|
} else {
|
||||||
printf("Recieved invalid command, ignoring...\n");
|
printf("Recieved invalid command, ignoring...\n");
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ int main (int argc, char *argv[])
|
|||||||
char ti[13];
|
char ti[13];
|
||||||
|
|
||||||
//Request foreground color from config file
|
//Request foreground color from config file
|
||||||
fp = popen("./result/bin/quest-log foreground", "r");
|
fp = popen("./result/bin/quest-log Foreground-Color", "r");
|
||||||
if (fgets(path, sizeof(path), fp)) {
|
if (fgets(path, sizeof(path), fp)) {
|
||||||
if (strcmp(path, "DATA NOT PRESENT"))
|
if (strcmp(path, "DATA NOT PRESENT"))
|
||||||
processColorString(&f, path);
|
processColorString(&f, path);
|
||||||
@ -202,7 +202,7 @@ int main (int argc, char *argv[])
|
|||||||
pclose(fp);
|
pclose(fp);
|
||||||
|
|
||||||
//Request background color from config file
|
//Request background color from config file
|
||||||
fp = popen("./result/bin/quest-log background", "r");
|
fp = popen("./result/bin/quest-log Background-Color", "r");
|
||||||
if (fgets(path, sizeof(path), fp)) {
|
if (fgets(path, sizeof(path), fp)) {
|
||||||
if (strcmp(path, "DATA NOT PRESENT"))
|
if (strcmp(path, "DATA NOT PRESENT"))
|
||||||
processColorString(&b, path);
|
processColorString(&b, path);
|
||||||
@ -217,7 +217,7 @@ int main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
int time = 0;
|
int time = 0;
|
||||||
fp = popen("./result/bin/quest-log time", "r");
|
fp = popen("./result/bin/quest-log current_time", "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("Failed to run command\n");
|
printf("Failed to run command\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user