-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate client view from client api
- Loading branch information
Showing
6 changed files
with
129 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef CLIENT_VIEW_H | ||
#define CLIENT_VIEW_H | ||
|
||
void client_view(); | ||
void show_get_result(unsigned int, char *); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#include "client.h" | ||
#include "client_view.h" | ||
#include "msg.h" | ||
|
||
static void menu(); | ||
static void menu_get(); | ||
static void menu_put(); | ||
static void menu_remove(); | ||
static void menu_quit(); | ||
|
||
static bool first_loop = true; | ||
|
||
void client_view() { | ||
if (first_loop) { | ||
printf("Welcome to Key Value Store\n"); | ||
first_loop = false; | ||
} | ||
|
||
menu(); | ||
} | ||
|
||
void show_get_result(unsigned int key, char *value) { | ||
printf("%u\n", key); | ||
if (strcmp(value, NODATA) == 0) { | ||
printf("no data\n"); | ||
} else { | ||
printf("value: %s\n", value); | ||
} | ||
} | ||
|
||
static void menu() { | ||
printf("1. put, 2. get, 3. delete, 4. quit: "); | ||
int num; | ||
scanf("%d", &num); | ||
|
||
switch (num) { | ||
case 1: | ||
menu_put(); | ||
break; | ||
|
||
case 2: | ||
menu_get(); | ||
break; | ||
|
||
case 3: | ||
menu_remove(); | ||
break; | ||
|
||
case 4: | ||
menu_quit(); | ||
break; | ||
|
||
default: | ||
printf("invalid num\n"); | ||
|
||
} | ||
} | ||
|
||
static void menu_put() { | ||
unsigned int key; | ||
char value[VALUESIZE]; | ||
|
||
printf("key > "); | ||
scanf("%d", &key); | ||
printf("value > "); | ||
scanf("%s", value); | ||
|
||
req_put(key, value); | ||
} | ||
|
||
static void menu_get() { | ||
unsigned int key; | ||
|
||
printf("key > "); | ||
scanf("%d", &key); | ||
|
||
req_get(key); | ||
} | ||
|
||
static void menu_remove() { | ||
unsigned int key; | ||
|
||
printf("key > "); | ||
scanf("%d", &key); | ||
|
||
req_remove(key); | ||
} | ||
|
||
static void menu_quit() { | ||
printf("Bye\n"); | ||
req_quit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters