|
wiRedPanda
Logic Circuit Simulator
|
Abstract base class for MCP command handlers. More...
#include <BaseHandler.h>
Public Member Functions | |
| QString | availableInputPorts (GraphicElement *element) const |
| QString | availableOutputPorts (GraphicElement *element) const |
| BaseHandler (MainWindow *mainWindow, const MCPValidator *validator) | |
| QJsonObject | createErrorResponse (const QString &error, const QJsonValue &requestId=QJsonValue(), int code=JsonRpcError::InternalError) const |
| QJsonObject | createSuccessResponse (const QJsonObject &result={}, const QJsonValue &requestId=QJsonValue()) const |
| Scene * | currentScene () |
| const Scene * | currentScene () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| virtual QJsonObject | handleCommand (const QString &command, const QJsonObject ¶ms, const QJsonValue &requestId)=0 |
| bool | inputPortByLabel (GraphicElement *element, const QString &label, int &portIndex, QString &errorMsg) const |
| bool | outputPortByLabel (GraphicElement *element, const QString &label, int &portIndex, QString &errorMsg) const |
| template<typename Fn> | |
| QJsonObject | tryCommand (Fn &&fn, const QString &action, const QJsonValue &requestId=QJsonValue()) |
| Wraps fn in a try/catch, returning an error response on exception. | |
| GraphicElement * | validatedElement (const QJsonObject ¶ms, const QString ¶mName, QString &errorMsg) |
| Validates paramName in params, looks up the element, and returns it. | |
| bool | validateElementId (int elementId, const QString ¶mName, QString &errorMsg) const |
| bool | validateNonEmptyString (const QJsonValue &value, const QString ¶mName, QString &errorMsg) const |
| bool | validateNonNegativeInteger (const QJsonValue &value, const QString ¶mName, QString &errorMsg) const |
| bool | validateNumeric (const QJsonValue &value, const QString ¶mName, QString &errorMsg) const |
| bool | validateParameters (const QJsonObject ¶ms, const QStringList &required) const |
| bool | validatePortRange (GraphicElement *element, int portIndex, bool isOutput, const QString ¶mName, QString &errorMsg) const |
| bool | validatePositiveInteger (const QJsonValue &value, const QString ¶mName, QString &errorMsg) const |
| virtual | ~BaseHandler ()=default |
Protected Member Functions | |
| QString | availablePorts (GraphicElement *element, bool isOutput) const |
Protected Attributes | |
| MainWindow * | m_mainWindow |
| const MCPValidator * | m_validator |
Abstract base class for MCP command handlers.
Provides common functionality and interface for all MCP command handlers. Each handler is responsible for a specific domain of MCP commands.
Definition at line 23 of file BaseHandler.h.
|
explicit |
Definition at line 17 of file BaseHandler.cpp.
References m_mainWindow, and m_validator.
Referenced by ConnectionHandler::ConnectionHandler(), ElementHandler::ElementHandler(), FileHandler::FileHandler(), HistoryHandler::HistoryHandler(), ICHandler::ICHandler(), ServerInfoHandler::ServerInfoHandler(), SimulationHandler::SimulationHandler(), and ThemeHandler::ThemeHandler().
|
virtualdefault |
| QString BaseHandler::availableInputPorts | ( | GraphicElement * | element | ) | const |
Definition at line 289 of file BaseHandler.cpp.
References availablePorts().
Referenced by inputPortByLabel().
| QString BaseHandler::availableOutputPorts | ( | GraphicElement * | element | ) | const |
Definition at line 294 of file BaseHandler.cpp.
References availablePorts().
Referenced by outputPortByLabel().
|
protected |
Definition at line 262 of file BaseHandler.cpp.
References GraphicElement::inputPort(), GraphicElement::inputSize(), GraphicElement::outputPort(), and GraphicElement::outputSize().
Referenced by availableInputPorts(), and availableOutputPorts().
| QJsonObject BaseHandler::createErrorResponse | ( | const QString & | error, |
| const QJsonValue & | requestId = QJsonValue(), | ||
| int | code = JsonRpcError::InternalError ) const |
Definition at line 34 of file BaseHandler.cpp.
Referenced by ConnectionHandler::handleCommand(), ElementHandler::handleCommand(), FileHandler::handleCommand(), HistoryHandler::handleCommand(), ICHandler::handleCommand(), ServerInfoHandler::handleCommand(), SimulationHandler::handleCommand(), ThemeHandler::handleCommand(), and tryCommand().
| QJsonObject BaseHandler::createSuccessResponse | ( | const QJsonObject & | result = {}, |
| const QJsonValue & | requestId = QJsonValue() ) const |
Definition at line 23 of file BaseHandler.cpp.
| Scene * BaseHandler::currentScene | ( | ) |
Definition at line 60 of file BaseHandler.cpp.
References m_mainWindow, and WorkSpace::scene().
Referenced by validatedElement(), and validateElementId().
| const Scene * BaseHandler::currentScene | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 74 of file BaseHandler.cpp.
References m_mainWindow, and WorkSpace::scene().
|
pure virtual |
Implemented in ConnectionHandler, ElementHandler, FileHandler, HistoryHandler, ICHandler, ServerInfoHandler, SimulationHandler, and ThemeHandler.
References JsonRpcError::InternalError.
| bool BaseHandler::inputPortByLabel | ( | GraphicElement * | element, |
| const QString & | label, | ||
| int & | portIndex, | ||
| QString & | errorMsg ) const |
Definition at line 220 of file BaseHandler.cpp.
References availableInputPorts(), GraphicElement::inputPort(), and GraphicElement::inputSize().
| bool BaseHandler::outputPortByLabel | ( | GraphicElement * | element, |
| const QString & | label, | ||
| int & | portIndex, | ||
| QString & | errorMsg ) const |
Definition at line 241 of file BaseHandler.cpp.
References availableOutputPorts(), GraphicElement::outputPort(), and GraphicElement::outputSize().
|
inline |
Wraps fn in a try/catch, returning an error response on exception.
Calls fn() inside a try block. On std::exception or unknown exception, returns createErrorResponse("Failed to \<action\>: ..."). Use this to eliminate repetitive try/catch boilerplate in handler methods.
Definition at line 55 of file BaseHandler.h.
References createErrorResponse(), and JsonRpcError::OperationFailed.
| GraphicElement * BaseHandler::validatedElement | ( | const QJsonObject & | params, |
| const QString & | paramName, | ||
| QString & | errorMsg ) |
Validates paramName in params, looks up the element, and returns it.
Combines validatePositiveInteger() + validateElementId() + itemById() + dynamic_cast in one call. On failure sets errorMsg and returns nullptr. Typical use: auto *e = validatedElement(params, "element_id", errorMsg); if (!e) return createErrorResponse(errorMsg, requestId);
Definition at line 202 of file BaseHandler.cpp.
References currentScene(), Scene::itemById(), validateElementId(), and validatePositiveInteger().
| bool BaseHandler::validateElementId | ( | int | elementId, |
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 136 of file BaseHandler.cpp.
References currentScene(), and Scene::itemById().
Referenced by validatedElement().
| bool BaseHandler::validateNonEmptyString | ( | const QJsonValue & | value, |
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 120 of file BaseHandler.cpp.
| bool BaseHandler::validateNonNegativeInteger | ( | const QJsonValue & | value, |
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 104 of file BaseHandler.cpp.
| bool BaseHandler::validateNumeric | ( | const QJsonValue & | value, |
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 158 of file BaseHandler.cpp.
| bool BaseHandler::validateParameters | ( | const QJsonObject & | params, |
| const QStringList & | required ) const |
Definition at line 50 of file BaseHandler.cpp.
| bool BaseHandler::validatePortRange | ( | GraphicElement * | element, |
| int | portIndex, | ||
| bool | isOutput, | ||
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 174 of file BaseHandler.cpp.
References GraphicElement::inputs(), and GraphicElement::outputs().
| bool BaseHandler::validatePositiveInteger | ( | const QJsonValue & | value, |
| const QString & | paramName, | ||
| QString & | errorMsg ) const |
Definition at line 88 of file BaseHandler.cpp.
Referenced by validatedElement().
|
protected |
Definition at line 85 of file BaseHandler.h.
Referenced by BaseHandler(), currentScene(), and currentScene().
|
protected |
Definition at line 86 of file BaseHandler.h.
Referenced by BaseHandler().