Tactiliest/Tactility/Source/app/AppInstance.cpp
Ken Van Hoeylandt ff4287e2ce
Filesystem improvements and more (#148)
- Rename `assets` and `config` partitions to `system` and `data`
- Change partition type from `spiffs` to `fat`, so we can have sub-directories
- Fix crash when doing WiFi scan: Increased system event task size to 3kB. 
- Free up IRAM on ESP32 (it was required for the Core2, but I also freed up the same amount for Yellow Board)
- Introduced `Paths` objects that can be retrieved by `AppContext` and `ServiceContext`. Apps and services now have their own relative paths. Assets were re-arranged into the correct paths.
- Rename simulator window title to "Tactility"
- Refactored statusbar widget so it persists icon paths properly (it kept a const char* reference, but didn't copy it, so it crashed when the related std::string was destroyed)
- Created `Partitions.h` to expose some useful variables
- Moved USB config in various `sdkconfig`  (it was part of the "default" section, but it shouldn't be)
- Updated domain name
2025-01-05 20:44:33 +01:00

90 lines
2.3 KiB
C++

#include "app/AppInstance.h"
#include "app/AppInstancePaths.h"
namespace tt::app {
#define TAG "app"
void AppInstance::setState(State newState) {
mutex.acquire(TtWaitForever);
state = newState;
mutex.release();
}
State AppInstance::getState() const {
mutex.acquire(TtWaitForever);
auto result = state;
mutex.release();
return result;
}
/** TODO: Make this thread-safe.
* In practice, the bundle is writeable, so someone could be writing to it
* while it is being accessed from another thread.
* Consider creating MutableBundle vs Bundle.
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
*/
const AppManifest& AppInstance::getManifest() const {
return manifest;
}
Flags AppInstance::getFlags() const {
mutex.acquire(TtWaitForever);
auto result = flags;
mutex.release();
return result;
}
void AppInstance::setFlags(Flags newFlags) {
mutex.acquire(TtWaitForever);
flags = newFlags;
mutex.release();
}
std::shared_ptr<void> _Nullable AppInstance::getData() const {
mutex.acquire(TtWaitForever);
auto result = data;
mutex.release();
return result;
}
void AppInstance::setData(std::shared_ptr<void> newData) {
mutex.acquire(TtWaitForever);
data = newData;
mutex.release();
}
std::shared_ptr<const Bundle> AppInstance::getParameters() const {
mutex.acquire(TtWaitForever);
std::shared_ptr<const Bundle> result = parameters;
mutex.release();
return result;
}
void AppInstance::setResult(Result result) {
std::unique_ptr<ResultHolder> new_holder(new ResultHolder(result));
mutex.acquire(TtWaitForever);
resultHolder = std::move(new_holder);
mutex.release();
}
void AppInstance::setResult(Result result, std::shared_ptr<const Bundle> bundle) {
std::unique_ptr<ResultHolder> new_holder(new ResultHolder(result, std::move(bundle)));
mutex.acquire(TtWaitForever);
resultHolder = std::move(new_holder);
mutex.release();
}
bool AppInstance::hasResult() const {
mutex.acquire(TtWaitForever);
bool has_result = resultHolder != nullptr;
mutex.release();
return has_result;
}
std::unique_ptr<Paths> AppInstance::getPaths() const {
return std::make_unique<AppInstancePaths>(manifest);
}
} // namespace