diff --git a/apps/code/editor_controller.cpp b/apps/code/editor_controller.cpp index 561337f45..31462e707 100644 --- a/apps/code/editor_controller.cpp +++ b/apps/code/editor_controller.cpp @@ -11,7 +11,7 @@ EditorController::EditorController(MenuController * menuController) : ViewController(nullptr), m_textArea(this), m_areaBuffer(nullptr), - m_script(Record()), + m_script(Ion::Record()), m_menuController(menuController) { m_textArea.setDelegate(this); @@ -26,7 +26,7 @@ void EditorController::setScript(Script script) { m_script = script; const char * scriptBody = m_script.readContent(); size_t scriptBodySize = strlen(scriptBody)+1; - size_t availableScriptSize = scriptBodySize + Kallax::sharedKallax()->availableSize(); + size_t availableScriptSize = scriptBodySize + Ion::Kallax::sharedKallax()->availableSize(); assert(m_areaBuffer == nullptr); m_areaBuffer = new char[availableScriptSize]; strlcpy(m_areaBuffer, scriptBody, scriptBodySize); @@ -36,8 +36,8 @@ void EditorController::setScript(Script script) { // TODO: this should be done in textAreaDidFinishEditing maybe?? bool EditorController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::Back) { - Record::ErrorStatus err = m_script.writeContent(m_areaBuffer, strlen(m_areaBuffer)+1); - if (err == Record::ErrorStatus::NoEnoughSpaceAvailable) { + Script::ErrorStatus err = m_script.writeContent(m_areaBuffer, strlen(m_areaBuffer)+1); + if (err == Script::ErrorStatus::NoEnoughSpaceAvailable) { assert(false); // This should not happen as we set the text area according to the available space in the Kallax } else { stackController()->pop(); diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index 26a4279cf..985dd0e62 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -302,8 +302,8 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char } else { newName = text; } - Record::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(newName); - if (error == Record::ErrorStatus::None) { + Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(newName); + if (error == Script::ErrorStatus::None) { updateAddScriptRowDisplay(); textField->setText(newName); int currentRow = m_selectableTableView.selectedRow(); @@ -318,7 +318,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char static_cast(const_cast(app()->container()))->setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::Default); return true; } else { - assert(error == Record::ErrorStatus::NameTaken); + assert(error == Script::ErrorStatus::NameTaken); // The name cannot be to long as the text field size was set accordingly // TODO: @@ -337,8 +337,8 @@ bool MenuController::textFieldDidAbortEditing(TextField * textField, const char // The previous text was an empty name. Use a numbered default script name. char numberedDefaultName[k_defaultScriptNameMaxSize]; numberedDefaultScriptName(numberedDefaultName); - Record::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(numberedDefaultName); - assert(error == Record::ErrorStatus::None); + Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(numberedDefaultName); + assert(error == Script::ErrorStatus::None); updateAddScriptRowDisplay(); m_selectableTableView.reloadData(); } diff --git a/apps/code/script.cpp b/apps/code/script.cpp index 4c0f7bf89..9c8fe7b69 100644 --- a/apps/code/script.cpp +++ b/apps/code/script.cpp @@ -23,9 +23,9 @@ const char * Script::readContent() const { return body+k_importationStatusSize; } -Record::ErrorStatus Script::writeContent(const char * data, size_t size) { +Script::ErrorStatus Script::writeContent(const char * data, size_t size) { int deltaSize = (int)size+k_importationStatusSize - (int)bodySize(); - if (Kallax::sharedKallax()->moveNextRecord(start(), deltaSize)) { + if (Ion::Kallax::sharedKallax()->moveNextRecord(start(), deltaSize)) { *m_size += deltaSize; strlcpy(m_body+k_importationStatusSize, data, size); return ErrorStatus::None; diff --git a/apps/code/script.h b/apps/code/script.h index da37f9ef0..5dfbde559 100644 --- a/apps/code/script.h +++ b/apps/code/script.h @@ -8,10 +8,10 @@ namespace Code { /* Record : | Total Size | Type | Name | Body | * Script: | AutoImportationStatus | Content |*/ -class Script : public Record { +class Script : public Ion::Record { friend class ScriptStore; public: - Script(Record f); + Script(Ion::Record f); bool importationStatus() const; void toggleImportationStatus(); diff --git a/apps/code/script_parameter_controller.cpp b/apps/code/script_parameter_controller.cpp index 7ee75d107..cce0c4d89 100644 --- a/apps/code/script_parameter_controller.cpp +++ b/apps/code/script_parameter_controller.cpp @@ -12,7 +12,7 @@ ScriptParameterController::ScriptParameterController(Responder * parentResponder m_deleteScript(I18n::Message::DeleteScript), m_selectableTableView(this, this, 0, 1, Metric::CommonTopMargin, Metric::CommonRightMargin, Metric::CommonBottomMargin, Metric::CommonLeftMargin, this), - m_script(Record()), + m_script(Ion::Record()), m_menuController(menuController) { } @@ -22,7 +22,7 @@ void ScriptParameterController::setScript(Script script){ } void ScriptParameterController::dismissScriptParameterController() { - m_script = Script(Record()); + m_script = Script(Ion::Record()); stackViewController()->pop(); } diff --git a/apps/code/script_store.cpp b/apps/code/script_store.cpp index e5b8b32fc..4b352f87a 100644 --- a/apps/code/script_store.cpp +++ b/apps/code/script_store.cpp @@ -20,17 +20,17 @@ ScriptStore::ScriptStore() } Script ScriptStore::scriptAtIndex(int index) { - Record f = Kallax::sharedKallax()->recordOfTypeAtIndex(Record::Type::Script, index); + Ion::Record f = Ion::Kallax::sharedKallax()->recordOfTypeAtIndex(Ion::Record::Type::Script, index); return Script(f); } Script ScriptStore::scriptNamed(const char * name) { - Record f = Kallax::sharedKallax()->getRecord(Record::Type::Script, name); + Ion::Record f = Ion::Kallax::sharedKallax()->getRecord(Ion::Record::Type::Script, name); return Script(f); } int ScriptStore::numberOfScripts() { - return Kallax::sharedKallax()->numberOfRecordOfType(Record::Type::Script); + return Ion::Kallax::sharedKallax()->numberOfRecordOfType(Ion::Record::Type::Script); } bool ScriptStore::addNewScript() { @@ -44,7 +44,7 @@ void ScriptStore::deleteAllScripts() { } bool ScriptStore::isFull() { - return (numberOfScripts() >= k_maxNumberOfScripts || Kallax::sharedKallax()->availableSize() < k_fullFreeSpaceSizeLimit); + return (numberOfScripts() >= k_maxNumberOfScripts || Ion::Kallax::sharedKallax()->availableSize() < k_fullFreeSpaceSizeLimit); } void ScriptStore::scanScriptsForFunctionsAndVariables(void * context, ScanCallback storeFunction, ScanCallback storeVariable) { @@ -143,8 +143,8 @@ bool ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) { body[0] = 1; strlcpy(body+1, scriptTemplate->content(), scriptSize); bool result = false; - if (Kallax::sharedKallax()->sizeOfRecordWithBody(body) <= Kallax::sharedKallax()->availableSize()) { - Kallax::sharedKallax()->addRecord(scriptTemplate->name(), Record::Type::Script, body); + if (Ion::Kallax::sharedKallax()->sizeOfRecordWithBody(body) <= Ion::Kallax::sharedKallax()->availableSize()) { + Ion::Kallax::sharedKallax()->addRecord(scriptTemplate->name(), Ion::Record::Type::Script, body); result = true; } delete[] body; diff --git a/apps/code/script_store.h b/apps/code/script_store.h index 072aef6e2..4ef5b0042 100644 --- a/apps/code/script_store.h +++ b/apps/code/script_store.h @@ -35,7 +35,7 @@ public: private: // If the kallax free space has a size smaller than // k_fullFreeSpaceSizeLimit, we consider the script store as full. - static constexpr int k_fullFreeSpaceSizeLimit = Record::k_sizeSize+Record::k_nameSize+Record::k_typeSize+10; + static constexpr int k_fullFreeSpaceSizeLimit = Ion::Record::k_sizeSize+Ion::Record::k_nameSize+Ion::Record::k_typeSize+10; static constexpr size_t k_fileInput2ParseNodeStructKind = 1; static constexpr size_t k_functionDefinitionParseNodeStructKind = 3; static constexpr size_t k_expressionStatementParseNodeStructKind = 5; diff --git a/ion/include/ion/kallax.h b/ion/include/ion/kallax.h index 507a8ca08..ef56c6dca 100644 --- a/ion/include/ion/kallax.h +++ b/ion/include/ion/kallax.h @@ -6,6 +6,8 @@ /* Kallax : | Magic | Record1 | Record2 | ... | MagicĀ | * | Magic | Size1 | Type1 | Name1 | BodySize1 | Body1 | Size2 | Type2 | Name2 | BodySize2 | Body2 | ... | Magic */ +namespace Ion { + class Kallax { public: Kallax(); @@ -37,5 +39,6 @@ private: uint32_t m_dataFooter; }; -#endif +} +#endif diff --git a/ion/include/ion/record.h b/ion/include/ion/record.h index ab5091a65..570f47e4a 100644 --- a/ion/include/ion/record.h +++ b/ion/include/ion/record.h @@ -6,6 +6,8 @@ /* Record : | Total Size | Type | Name | Body | */ +namespace Ion { + class Record { public: enum class Type : uint8_t { @@ -44,4 +46,6 @@ private: Type m_type; }; +} + #endif diff --git a/ion/src/device/kallax_info.cpp b/ion/src/device/kallax_info.cpp index 442d25c3e..e0d6d2b82 100644 --- a/ion/src/device/kallax_info.cpp +++ b/ion/src/device/kallax_info.cpp @@ -8,5 +8,11 @@ #define FORCE_LINK #endif +namespace Ion { +namespace Device { + extern Kallax f; constexpr KallaxInfo HEADER_SECTION FORCE_LINK kallax_infos((uint32_t)(&f)); + +} +} diff --git a/ion/src/device/kallax_info.h b/ion/src/device/kallax_info.h index c2d508e0c..4c3ca2f5c 100644 --- a/ion/src/device/kallax_info.h +++ b/ion/src/device/kallax_info.h @@ -3,6 +3,9 @@ #include +namespace Ion { +namespace Device { + class KallaxInfo { public: constexpr KallaxInfo(uint32_t address) : @@ -16,5 +19,8 @@ private: uint32_t m_footer; }; +} +} + #endif diff --git a/ion/src/shared/kallax.cpp b/ion/src/shared/kallax.cpp index 2a7f50656..79adae710 100644 --- a/ion/src/shared/kallax.cpp +++ b/ion/src/shared/kallax.cpp @@ -10,6 +10,8 @@ #define FORCE_LINK #endif +namespace Ion { + Kallax f; Kallax::Kallax() : @@ -158,3 +160,5 @@ char * Kallax::bodyOfRecordStarting(char * start) { size_t Kallax::sizeOfRecordWithBody(const char * body) const { return Record::k_sizeSize+Record::k_typeSize+Record::k_nameSize+strlen(body)+1; } + +} diff --git a/ion/src/shared/record.cpp b/ion/src/shared/record.cpp index 8c818acaa..2f240bf45 100644 --- a/ion/src/shared/record.cpp +++ b/ion/src/shared/record.cpp @@ -3,6 +3,8 @@ #include #include +namespace Ion { + Record::Record(size_t * size, char * name, Type type, char * body) : m_body(body), m_size(size), @@ -65,3 +67,5 @@ char * Record::start() { size_t Record::bodySize() const { return *m_size - k_nameSize - k_typeSize - k_sizeSize; } + +}