| |
| |
| |
| |
| |
|
|
|
|
| #ifndef INFRA_SUBSYS_H_
|
| #define INFRA_SUBSYS_H_
|
|
|
| #include "mystring.h"
|
| #include "action.h"
|
| #include "managed_array.h"
|
|
|
| #include "FreeRTOS.h"
|
| #include "task.h"
|
| #include "queue.h"
|
| #include "semphr.h"
|
| #include <stdio.h>
|
|
|
| #include "http_codes.h"
|
|
|
| class SubsysCommand;
|
| class UserInterface;
|
|
|
| #define SUBSYSID_USER_STANDARD 0
|
| #define SUBSYSID_C64 1
|
| #define SUBSYSID_DRIVE_A 2
|
| #define SUBSYSID_DRIVE_B 3
|
| #define SUBSYSID_DRIVE_C 4
|
| #define SUBSYSID_TAPE_PLAYER 5
|
| #define SUBSYSID_TAPE_RECORDER 6
|
| #define SUBSYSID_IEC 7
|
| #define SUBSYSID_CMD_IF 8
|
| #define SUBSYSID_U64 9
|
| #define SUBSYSID_PRINTER 10
|
| #define SUBSYSID_ULTICOPY 11
|
|
|
| #define SORT_ORDER_ASSEMBLY 5
|
| #define SORT_ORDER_CREATE 10
|
| #define SORT_ORDER_C64 20
|
| #define SORT_ORDER_DRIVES 30
|
| #define SORT_ORDER_SOFTIEC 40
|
| #define SORT_ORDER_TAPE 50
|
| #define SORT_ORDER_PRINTER 60
|
| #define SORT_ORDER_CONFIG 70
|
| #define SORT_ORDER_DEVELOPER 999
|
|
|
|
|
| class SubSystem // implements function "executeCommand"
|
| {
|
| int myID;
|
| SemaphoreHandle_t myMutex;
|
| friend class SubsysCommand;
|
|
|
| virtual SubsysResultCode_e executeCommand(SubsysCommand *cmd) { return SSRET_SUBSYS_NO_EXEC; }
|
| public:
|
| SubSystem(int id) {
|
| myID = id;
|
| myMutex = xSemaphoreCreateMutex();
|
| SubSystem :: getSubSystems() -> set(myID, this);
|
| }
|
| virtual ~SubSystem() {
|
| SubSystem :: getSubSystems() -> unset(myID);
|
| vSemaphoreDelete(myMutex);
|
| }
|
|
|
| static ManagedArray<SubSystem *>* getSubSystems() {
|
| static ManagedArray<SubSystem *> subsystem_array(16, NULL);
|
| return &subsystem_array;
|
| }
|
|
|
| virtual const char *identify(void) { return "Unknown Subsystem"; }
|
|
|
| int lock(const char *name) {
|
| int retval = xSemaphoreTake(myMutex, 5000);
|
| if (!retval) {
|
| printf("Lock: %s not available.\n", name);
|
| }
|
| return retval;
|
| }
|
| void unlock() {
|
| xSemaphoreGive(myMutex);
|
| }
|
|
|
| int getID() { return myID; }
|
| };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| class SubsysCommand
|
| {
|
| public:
|
|
|
| SubsysCommand(UserInterface *ui, Action *act, const char *p = NULL, const char *fn = NULL) :
|
| user_interface(ui),
|
| subsysID(act->subsys),
|
| functionID(act->function),
|
| mode(act->mode),
|
| direct_call(act->func),
|
| direct_obj(act->getObject()),
|
| actionName(act->getName()),
|
| path(p), filename(fn) {
|
| buffer = NULL;
|
| bufferSize = 0;
|
| }
|
|
|
|
|
| SubsysCommand(UserInterface *ui, int subID, int funcID, int mode, const char *p = NULL, const char *fn = NULL) :
|
| user_interface(ui),
|
| subsysID(subID),
|
| functionID(funcID),
|
| mode(mode),
|
| direct_call(0),
|
| direct_obj(NULL),
|
| actionName(""),
|
| path(p), filename(fn) {
|
| buffer = NULL;
|
| bufferSize = 0;
|
| }
|
|
|
|
|
| SubsysCommand(UserInterface *ui, int subID, int funcID, int mode, void *buffer, int bufferSize) :
|
| user_interface(ui),
|
| subsysID(subID),
|
| functionID(funcID),
|
| mode(mode),
|
| direct_call(0),
|
| direct_obj(NULL),
|
| actionName(""),
|
| path(""), filename(""),
|
| buffer(buffer),
|
| bufferSize(bufferSize) {
|
| }
|
|
|
| SubsysResultCode_t execute(void);
|
|
|
| void print(void) {
|
| printf("SubsysCommand for system %d:\n", subsysID);
|
| printf(" Function ID: %d\n", functionID);
|
| printf(" Mode: %d\n", mode);
|
| printf(" Path: %s\n", path.c_str());
|
| printf(" Filename: %s\n", filename.c_str());
|
| printf(" Buffer = %p (size: %d)\n", buffer, bufferSize);
|
| }
|
|
|
| static const char *error_string(SubsysResultCode_e resultCode)
|
| {
|
| static const char *error_strings[] = {
|
| NULL,
|
| "Invalid Parameter",
|
| "Call requires user interaction, but no user interface object exists",
|
| "Generic Error",
|
| "Disk Error",
|
| "SubSystem does not exist",
|
| "SubSystem does not implement command executer",
|
| "Could not obtain lock of subsystem",
|
| "Disk has been modified, save first",
|
| "Drive ROM not found",
|
| "Drive ROM is invalid",
|
| "This hardware only supports 1541",
|
| "Drive is in the wrong mode",
|
| "Cannot open file",
|
| "Seek operation on file failed",
|
| "Read operation on file failed",
|
| "Illegal mount mode / drive type",
|
| "Undefined subsystem command",
|
| "Operation aborted by user",
|
| "Save failed",
|
| "EEPROM data is too large",
|
| "EEPROM defined more than once",
|
| "ROM image is too large",
|
| "Error detected in file format",
|
| "This command is not supported on this architecture",
|
| "Out of memory",
|
| "MegaPatch3: Invalid image size",
|
| "MegaPatch3: DNP Image too large",
|
| "Internal Error",
|
| "SID File Memory Rollover",
|
| "Invalid Song Number Requested",
|
| "No Operational Network Interface",
|
| "Network Host Resolve Error",
|
| };
|
| return error_strings[(int)resultCode];
|
| }
|
|
|
| static int http_response_map(SubsysResultCode_e resultCode)
|
| {
|
| static const int codes[] = {
|
| HTTP_OK,
|
| HTTP_BAD_REQUEST,
|
| HTTP_SERVICE_UNAVAILABLE,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_SERVICE_UNAVAILABLE,
|
| HTTP_METHOD_NOT_ALLOWED,
|
| HTTP_LOCKED,
|
| HTTP_FORBIDDEN,
|
| HTTP_PRECONDITION_FAILED,
|
| HTTP_PRECONDITION_FAILED,
|
| HTTP_METHOD_NOT_ALLOWED,
|
| HTTP_UNSUPPORTED_MEDIA_TYPE,
|
| HTTP_NOT_FOUND,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_FAILED_DEPENDENCY,
|
| HTTP_PRECONDITION_FAILED,
|
| HTTP_PRECONDITION_FAILED,
|
| HTTP_PRECONDITION_FAILED,
|
| HTTP_UNSUPPORTED_MEDIA_TYPE,
|
| HTTP_NOT_IMPLEMENTED,
|
| HTTP_INSUFFICIENT_STORAGE,
|
| HTTP_BAD_REQUEST,
|
| HTTP_BAD_REQUEST,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_UNSUPPORTED_MEDIA_TYPE,
|
| HTTP_BAD_REQUEST,
|
| HTTP_INTERNAL_SERVER_ERROR,
|
| HTTP_NOT_FOUND,
|
| };
|
| return codes[(int)resultCode];
|
| }
|
|
|
| UserInterface *user_interface;
|
| int subsysID;
|
| int functionID;
|
| int mode;
|
| actionFunction_t direct_call;
|
| const void *direct_obj;
|
| mstring path;
|
| mstring filename;
|
| mstring actionName;
|
| void *buffer;
|
| int bufferSize;
|
| };
|
|
|
| #endif
|
|
|