mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Namespace Record and Kallax
This commit is contained in:
committed by
EmilieNumworks
parent
aa984bca74
commit
f9656fd94f
@@ -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();
|
||||
|
||||
@@ -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<AppsContainer *>(const_cast<Container *>(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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <ion/kallax.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Device {
|
||||
|
||||
class KallaxInfo {
|
||||
public:
|
||||
constexpr KallaxInfo(uint32_t address) :
|
||||
@@ -16,5 +19,8 @@ private:
|
||||
uint32_t m_footer;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user