Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_Param.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#pragma once1617#include "AP_Filesystem_config.h"1819#if AP_FILESYSTEM_PARAM_ENABLED2021#include "AP_Filesystem_backend.h"22#include <AP_Common/ExpandingString.h>2324#include <AP_Param/AP_Param.h>2526class AP_Filesystem_Param : public AP_Filesystem_Backend27{28public:29// functions that closely match the equivalent posix calls30int open(const char *fname, int flags, bool allow_absolute_paths = false) override;31int close(int fd) override;32int32_t read(int fd, void *buf, uint32_t count) override;33int32_t lseek(int fd, int32_t offset, int whence) override;34int stat(const char *pathname, struct stat *stbuf) override;35int32_t write(int fd, const void *buf, uint32_t count) override;3637private:38// we maintain two cursors per open file to minimise seeking39// when filling in gaps40static constexpr uint8_t num_cursors = 2;4142// only allow up to 4 files at a time43static constexpr uint8_t max_open_file = 4;4445// maximum size of one packed parameter and default value46static constexpr uint8_t max_pack_len = AP_MAX_NAME_SIZE + 2 + 4 + 4 + 3;4748// Support both protocol versions49static constexpr uint16_t pmagic = 0x671b;50static constexpr uint16_t pmagic_with_default = 0x671c;5152// header at front of the file53struct header {54uint16_t magic = pmagic;55uint16_t num_params;56uint16_t total_params; // for upload this is total file length57};5859struct cursor {60AP_Param::ParamToken token;61uint32_t token_ofs;62char last_name[AP_MAX_NAME_SIZE+1];63uint8_t trailer_len;64uint8_t trailer[max_pack_len];65uint16_t idx;66};6768struct rfile {69bool open;70bool with_defaults;71uint16_t read_size;72uint16_t start;73uint16_t count;74uint32_t file_ofs;75uint32_t file_size;76struct cursor *cursors;77ExpandingString *writebuf; // for upload78} file[max_open_file];7980bool token_seek(const struct rfile &r, const uint32_t data_ofs, struct cursor &c);81uint8_t pack_param(const struct rfile &r, struct cursor &c, uint8_t *buf);82bool check_file_name(const char *fname);8384// finish uploading parameters85bool finish_upload(const rfile &r);86bool param_upload_parse(const rfile &r, bool &need_retry);87};8889#endif // AP_FILESYSTEM_PARAM_ENABLED909192