extract shared mosis-core library from sandbox APIs
Create core/ directory with platform-agnostic sandbox components: - Timer manager, JSON API, Crypto API, Virtual FS - Lua sandbox, Permission gate, Audit log, Rate limiter - Platform abstraction interfaces (IAssetInterface, IFilesystemInterface) - Platform-agnostic logger with Android/Desktop implementations Update designer to link against mosis-core library instead of including sandbox sources directly. This is the foundation for unifying the Android service and desktop designer to share the same codebase. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
57
core/include/mosis/platform/asset_interface.h
Normal file
57
core/include/mosis/platform/asset_interface.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace mosis {
|
||||
|
||||
/**
|
||||
* Platform-agnostic interface for loading assets.
|
||||
* Android implements this using AAssetManager.
|
||||
* Desktop implements this using filesystem operations.
|
||||
*/
|
||||
class IAssetInterface {
|
||||
public:
|
||||
virtual ~IAssetInterface() = default;
|
||||
|
||||
/**
|
||||
* Read entire file contents as bytes.
|
||||
* @param path Relative path to asset (e.g., "apps/home/home.rml")
|
||||
* @return File contents, or empty vector if not found
|
||||
*/
|
||||
virtual std::vector<uint8_t> ReadFile(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Read entire file contents as string.
|
||||
* @param path Relative path to asset
|
||||
* @return File contents, or empty string if not found
|
||||
*/
|
||||
virtual std::string ReadFileString(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Check if an asset exists.
|
||||
* @param path Relative path to asset
|
||||
* @return true if asset exists
|
||||
*/
|
||||
virtual bool Exists(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* List files in a directory.
|
||||
* @param path Relative path to directory
|
||||
* @return List of filenames (not full paths)
|
||||
*/
|
||||
virtual std::vector<std::string> ListDirectory(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Get the absolute path for an asset (if applicable).
|
||||
* On Android this may return empty as assets are in APK.
|
||||
* @param path Relative path to asset
|
||||
* @return Absolute path or empty string
|
||||
*/
|
||||
virtual std::string GetAbsolutePath(const std::string& path) = 0;
|
||||
};
|
||||
|
||||
using AssetInterfacePtr = std::shared_ptr<IAssetInterface>;
|
||||
|
||||
} // namespace mosis
|
||||
98
core/include/mosis/platform/filesystem_interface.h
Normal file
98
core/include/mosis/platform/filesystem_interface.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace mosis {
|
||||
|
||||
/**
|
||||
* Platform-agnostic interface for filesystem operations.
|
||||
* Used for app data storage, not assets.
|
||||
*/
|
||||
class IFilesystemInterface {
|
||||
public:
|
||||
virtual ~IFilesystemInterface() = default;
|
||||
|
||||
/**
|
||||
* Get the base data directory for apps.
|
||||
* Android: /data/data/com.omixlab.mosis/files/
|
||||
* Desktop: ./data/ or configurable
|
||||
*/
|
||||
virtual std::string GetDataRoot() = 0;
|
||||
|
||||
/**
|
||||
* Get the apps installation directory.
|
||||
* Contains installed app packages.
|
||||
*/
|
||||
virtual std::string GetAppsDirectory() = 0;
|
||||
|
||||
/**
|
||||
* Get app-specific data directory.
|
||||
* @param app_id Application ID (e.g., "com.example.app")
|
||||
*/
|
||||
virtual std::string GetAppDataDirectory(const std::string& app_id) = 0;
|
||||
|
||||
/**
|
||||
* Get app-specific cache directory.
|
||||
*/
|
||||
virtual std::string GetAppCacheDirectory(const std::string& app_id) = 0;
|
||||
|
||||
/**
|
||||
* Create directory if it doesn't exist.
|
||||
* @return true on success
|
||||
*/
|
||||
virtual bool CreateDirectory(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Check if path exists.
|
||||
*/
|
||||
virtual bool Exists(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Check if path is a directory.
|
||||
*/
|
||||
virtual bool IsDirectory(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Remove file or directory.
|
||||
* @param recursive If true, remove directory contents
|
||||
*/
|
||||
virtual bool Remove(const std::string& path, bool recursive = false) = 0;
|
||||
|
||||
/**
|
||||
* Read file contents.
|
||||
*/
|
||||
virtual std::vector<uint8_t> ReadFile(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Write file contents.
|
||||
*/
|
||||
virtual bool WriteFile(const std::string& path, const std::vector<uint8_t>& data) = 0;
|
||||
|
||||
/**
|
||||
* List directory contents.
|
||||
*/
|
||||
virtual std::vector<std::string> ListDirectory(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Get file size.
|
||||
* @return Size in bytes, or -1 if not found
|
||||
*/
|
||||
virtual int64_t GetFileSize(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* Copy file.
|
||||
*/
|
||||
virtual bool CopyFile(const std::string& src, const std::string& dst) = 0;
|
||||
|
||||
/**
|
||||
* Move/rename file.
|
||||
*/
|
||||
virtual bool MoveFile(const std::string& src, const std::string& dst) = 0;
|
||||
};
|
||||
|
||||
using FilesystemInterfacePtr = std::shared_ptr<IFilesystemInterface>;
|
||||
|
||||
} // namespace mosis
|
||||
Reference in New Issue
Block a user