From cc6a08ade5b80324269dfeddae11b429759f9f08 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 17 Feb 2019 14:31:04 +0100 Subject: [PATCH] added skeleton of provider example app --- CMakeLists.txt | 1 + example/provider/main.c | 151 ++++++++++++++++++++++++++++++++++++++- include/wsfsp/client.h | 34 ++++----- include/wsfsp/provider.h | 13 ++-- lib/wsfsp/client.c | 80 +++++++++++++++++++++ lib/wsfsp/provider.c | 63 ++++++++++++++++ 6 files changed, 318 insertions(+), 24 deletions(-) create mode 100644 lib/wsfsp/provider.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 611a0cd..dba321e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,7 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs.pc" DESTINATION lib${LIB_SUFFIX}/pk set(WSFS_PROVIDER_SOURCES lib/wsfsp/client.c + lib/wsfsp/provider.c ) add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES}) diff --git a/example/provider/main.c b/example/provider/main.c index 141ea80..799f8de 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -1,12 +1,161 @@ #include #include +#include +#include +#include #include "wsfs_provider.h" + +struct fs_dir +{ + ino_t parent; + ino_t inode; + char const * name; +}; + +struct fs_file +{ + ino_t parent; + ino_t inode; + char const * name; + char const * content; + size_t content_length; + bool is_executable; +}; + +struct fs +{ + struct fs_dir const * directories; + struct fs_file const * files; +}; + +static void fs_lookup( + struct wsfsp_request * request, + ino_t parent, + char const * name, + void * user_data) +{ + (void) parent; + (void) name; + (void) user_data; + + puts("lookup"); + wsfsp_respond_error(request, -1); +} + +static void fs_getattr( + struct wsfsp_request * request, + ino_t inode, + void * user_data) +{ + (void) inode; + (void) user_data; + + puts("getattr"); + wsfsp_respond_error(request, -1); +} + +static void fs_readdir( + struct wsfsp_request * request, + ino_t directory, + struct wsfsp_dirbuffer * dirbuffer, + void * user_data) +{ + (void) directory; + (void) dirbuffer; + (void) user_data; + + puts("readdir"); + wsfsp_respond_error(request, -1); +} + +static void fs_open( + struct wsfsp_request * request, + ino_t inode, + int flags, + void * user_data) +{ + (void) inode; + (void) flags; + (void) user_data; + + puts("open"); + wsfsp_respond_error(request, -1); +} + +static void fs_read( + struct wsfsp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data) +{ + (void) inode; + (void) handle; + (void) offset; + (void) length; + (void) user_data; + + wsfsp_respond_error(request, -1); +} + +static struct wsfsp_provider fs_provider = +{ + .lookup = &fs_lookup, + .getattr = &fs_getattr, + .readdir = &fs_readdir, + .open = &fs_open, + .read = &fs_read +}; + +static struct wsfsp_client * client; + +static void on_interrupt(int signal_id) +{ + (void) signal_id; + + wsfsp_client_shutdown(client); +} + int main(int argc, char* argv[]) { (void) argc; (void) argv; - return EXIT_FAILURE; + static struct fs_dir const directories[]= + { + {.parent = 0, .inode = 1, .name = ""}, + {.parent = 0, .inode = 0, .name = NULL} + }; + + static struct fs_file const files[] = + { + { + .parent = 1, + .inode = 2, + .name = "hello.txt", + .content="hello, world!", + .content_length = 13, + .is_executable = false + }, + {.parent = 0, .inode = 0} + }; + + struct fs fs = + { + .directories = directories, + .files = files + }; + + signal(SIGINT, &on_interrupt); + + client = wsfsp_client_create(&fs_provider, &fs); + wsfsp_client_connect(client, "ws://localhost:8080/"); + + wsfsp_client_run(client); + + wsfsp_client_dispose(client); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/include/wsfsp/client.h b/include/wsfsp/client.h index 4a08dd9..d31ddb4 100644 --- a/include/wsfsp/client.h +++ b/include/wsfsp/client.h @@ -1,39 +1,39 @@ #ifndef _WSFSP_CLIENT_H #define _WSFSP_CLIENT_H -#include "wsfs/api.h" +#include "wsfsp/api.h" -struct wsfs_provider; -struct wsfs_provider_client_config; +struct wsfsp_provider; +struct wsfsp_client; #ifdef __cplusplus extern "C" { #endif -extern WSFS_API struct wsfs_provider_client * wsfs_provider_client_create( - struct wsfs_provider * provider, +extern WSFSP_API struct wsfsp_client * wsfsp_client_create( + struct wsfsp_provider * provider, void * user_data); -extern WSFS_API void wsfs_provider_client_connect( - struct wsfs_provider_client * client, +extern WSFSP_API void wsfsp_client_connect( + struct wsfsp_client * client, char const * url); -extern WSFS_API void wsfs_provider_client_disconnect( - struct wsfs_provider_client * client); +extern WSFSP_API void wsfsp_client_disconnect( + struct wsfsp_client * client); -extern WSFS_API void wsfs_provider_client_settimeout( - struct wsfs_provider_client * client, +extern WSFSP_API void wsfsp_client_settimeout( + struct wsfsp_client * client, unsigned int timepoint); -extern WSFS_API void wsfs_provider_client_dispose( - struct wsfs_provider_client * client); +extern WSFSP_API void wsfsp_client_dispose( + struct wsfsp_client * client); -extern WSFS_API void wsfs_provider_client_run( - struct wsfs_provider_client * client); +extern WSFSP_API void wsfsp_client_run( + struct wsfsp_client * client); -extern WSFS_API void wsfs_provider_client_shutdown( - struct wsfs_provider_client * client); +extern WSFSP_API void wsfsp_client_shutdown( + struct wsfsp_client * client); #ifdef __cplusplus diff --git a/include/wsfsp/provider.h b/include/wsfsp/provider.h index 5ab34fe..ad9388c 100644 --- a/include/wsfsp/provider.h +++ b/include/wsfsp/provider.h @@ -14,6 +14,7 @@ using std::size_t; #include #include +#include "wsfsp/api.h" struct wsfsp_request; struct wsfsp_dirbuffer; @@ -82,27 +83,27 @@ extern "C" { #endif -extern void wsfsp_respond_error( +extern WSFSP_API void wsfsp_respond_error( struct wsfsp_request * request, int status); -extern void wsfsp_respond_lookup( +extern WSFSP_API void wsfsp_respond_lookup( struct wsfsp_request * request, struct stat const * stat); -extern void wsfsp_respond_getattr( +extern WSFSP_API void wsfsp_respond_getattr( struct wsfsp_request * request, struct stat const * stat); -extern void wsfsp_respond_readdir( +extern WSFSP_API void wsfsp_respond_readdir( struct wsfsp_request * request, struct wsfsp_dirbuffer * dirbuffer); -extern void wsfsp_respond_open( +extern WSFSP_API void wsfsp_respond_open( struct wsfsp_request * request, uint32_t handle); -extern void wsfsp_respond_read( +extern WSFSP_API void wsfsp_respond_read( struct wsfsp_request * request, char const * data, size_t length); diff --git a/lib/wsfsp/client.c b/lib/wsfsp/client.c index bd6577b..71aaf7b 100644 --- a/lib/wsfsp/client.c +++ b/lib/wsfsp/client.c @@ -1,2 +1,82 @@ #include "wsfsp/client.h" +#include +#include +#include + +#include "wsfsp/provider.h" + +struct wsfsp_client +{ + volatile bool is_running; + struct wsfsp_provider provider; + void * user_data; +}; + + +struct wsfsp_client * wsfsp_client_create( + struct wsfsp_provider * provider, + void * user_data) +{ + struct wsfsp_client * client = malloc(sizeof(struct wsfsp_client)); + if (NULL != client) + { + client->is_running = true; + client->user_data = user_data; + memcpy(&client->provider, provider, sizeof(struct wsfsp_provider)); + } + + return client; +} + +void wsfsp_client_dispose( + struct wsfsp_client * client) +{ + free(client); +} + +void wsfsp_client_connect( + struct wsfsp_client * client, + char const * url) +{ + (void) client; + (void) url; + + // ToDo: implement me +} + +void wsfsp_client_disconnect( + struct wsfsp_client * client) +{ + (void) client; + + // ToDo: implement me +} + +void wsfsp_client_settimeout( + struct wsfsp_client * client, + unsigned int timepoint) +{ + (void) client; + (void) timepoint; + + // ToDo: implement me +} + + +void wsfsp_client_run( + struct wsfsp_client * client) +{ + while (client->is_running) + { + // ToDo: implement me + break; + } +} + +void wsfsp_client_shutdown( + struct wsfsp_client * client) +{ + client->is_running = false; +} + diff --git a/lib/wsfsp/provider.c b/lib/wsfsp/provider.c new file mode 100644 index 0000000..4810400 --- /dev/null +++ b/lib/wsfsp/provider.c @@ -0,0 +1,63 @@ +#include "wsfsp/provider.h" + +void wsfsp_respond_error( + struct wsfsp_request * request, + int status) +{ + (void) request; + (void) status; + + // ToDo: implement me +} + +void wsfsp_respond_lookup( + struct wsfsp_request * request, + struct stat const * stat) +{ + (void) request; + (void) stat; + + // ToDo: implement me +} + +void wsfsp_respond_getattr( + struct wsfsp_request * request, + struct stat const * stat) +{ + (void) request; + (void) stat; + + // ToDo: implement me +} + +void wsfsp_respond_readdir( + struct wsfsp_request * request, + struct wsfsp_dirbuffer * dirbuffer) +{ + (void) request; + (void) dirbuffer; + + // ToDo: implement me +} + +void wsfsp_respond_open( + struct wsfsp_request * request, + uint32_t handle) +{ + (void) request; + (void) handle; + + // ToDo: implement me +} + +void wsfsp_respond_read( + struct wsfsp_request * request, + char const * data, + size_t length) +{ + (void) request; + (void) data; + (void) length; + + // ToDo: implement me +}