Simplify app and service paths

This commit is contained in:
Ken Van Hoeylandt 2025-09-22 00:10:30 +02:00
parent 1f53302a2a
commit e12fa53403
22 changed files with 164 additions and 172 deletions

View File

@ -7,7 +7,7 @@ namespace tt::app {
// Forward declarations
class App;
class Paths;
class AppPaths;
struct AppManifest;
enum class Result;
@ -32,50 +32,10 @@ public:
virtual const AppManifest& getManifest() const = 0;
virtual std::shared_ptr<const Bundle> getParameters() const = 0;
virtual std::unique_ptr<Paths> getPaths() const = 0;
virtual std::unique_ptr<AppPaths> getPaths() const = 0;
virtual std::shared_ptr<App> getApp() const = 0;
};
class Paths {
public:
Paths() = default;
virtual ~Paths() = default;
/**
* Returns the directory path for the data location for an app.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
virtual std::string getDataDirectory() const = 0;
/**
* Returns the full path for an entry inside the data location for an app.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getDataPath(const std::string& childPath) const = 0;
/**
* Returns the directory path for the system location for an app.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core apps (system/boot/settings type).
*/
virtual std::string getSystemDirectory() const = 0;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getSystemPath(const std::string& childPath) const = 0;
};
}

View File

@ -0,0 +1,53 @@
#pragma once
#include <string>
#include <memory>
namespace tt::app {
// Forward declarations
class AppManifest;
class AppPaths {
const AppManifest& manifest;
public:
explicit AppPaths(const AppManifest& manifest) : manifest(manifest) {}
/**
* Returns the directory path for the data location for an app.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
std::string getDataDirectory() const;
/**
* Returns the full path for an entry inside the data location for an app.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
std::string getDataPath(const std::string& childPath) const;
/**
* Returns the directory path for the system location for an app.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core apps (system/boot/settings type).
*/
std::string getSystemDirectory() const;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
std::string getSystemPath(const std::string& childPath) const;
};
}

View File

@ -1,14 +1,11 @@
#pragma once
#include "ServiceManifest.h"
#include <Tactility/Mutex.h>
#include <memory>
namespace tt::service {
class Paths;
struct ServiceManifest;
class ServicePaths;
/**
* The public representation of a service instance.
@ -26,48 +23,8 @@ public:
virtual const ServiceManifest& getManifest() const = 0;
/** Retrieve the paths that are relevant to this service */
virtual std::unique_ptr<Paths> getPaths() const = 0;
virtual std::unique_ptr<ServicePaths> getPaths() const = 0;
};
class Paths {
public:
Paths() = default;
virtual ~Paths() = default;
/**
* Returns the directory path for the data location for a service.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
virtual std::string getDataDirectory() const = 0;
/**
* Returns the full path for an entry inside the data location for a service.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getDataPath(const std::string& childPath) const = 0;
/**
* Returns the directory path for the system location for a service.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core services.
*/
virtual std::string getSystemDirectory() const = 0;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getSystemPath(const std::string& childPath) const = 0;
};
} // namespace

View File

@ -1,6 +1,6 @@
#pragma once
#include "Tactility/service/Service.h"
#include <Tactility/service/Service.h>
#include <string>

View File

@ -0,0 +1,53 @@
#pragma once
#include <string>
#include <memory>
namespace tt::service {
// Forward declarations
class ServiceManifest;
class ServicePaths {
std::shared_ptr<const ServiceManifest> manifest;
public:
explicit ServicePaths(std::shared_ptr<const ServiceManifest> manifest) : manifest(std::move(manifest)) {}
/**
* Returns the directory path for the data location for a service.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
std::string getDataDirectory() const;
/**
* Returns the full path for an entry inside the data location for a service.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
std::string getDataPath(const std::string& childPath) const;
/**
* Returns the directory path for the system location for a service.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core services.
*/
std::string getSystemDirectory() const;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
std::string getSystemPath(const std::string& childPath) const;
};
}

View File

@ -24,7 +24,7 @@ class GpsService final : public Service {
Mutex stateMutex;
std::vector<GpsDeviceRecord> deviceRecords;
std::shared_ptr<PubSub<State>> statePubSub = std::make_shared<PubSub<State>>();
std::unique_ptr<Paths> paths;
std::unique_ptr<ServicePaths> paths;
State state = State::Off;
bool startGpsDevice(GpsDeviceRecord& deviceRecord);

View File

@ -88,7 +88,7 @@ public:
std::shared_ptr<const Bundle> getParameters() const override;
std::unique_ptr<Paths> getPaths() const override;
std::unique_ptr<AppPaths> getPaths() const override;
std::shared_ptr<App> getApp() const override { return app; }
};

View File

@ -1,22 +0,0 @@
#pragma once
#include "Tactility/app/AppInstance.h"
namespace tt::app {
class AppInstancePaths final : public Paths {
const AppManifest& manifest;
public:
explicit AppInstancePaths(const AppManifest& manifest) : manifest(manifest) {}
~AppInstancePaths() override = default;
std::string getDataDirectory() const override;
std::string getDataPath(const std::string& childPath) const override;
std::string getSystemDirectory() const override;
std::string getSystemPath(const std::string& childPath) const override;
};
}

View File

@ -4,6 +4,7 @@
#include "./State.h"
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppPaths.h>
#include <lvgl.h>
@ -13,7 +14,7 @@ class View final {
Bindings* bindings;
State* state;
std::unique_ptr<Paths> paths;
std::unique_ptr<AppPaths> paths;
lv_obj_t* root = nullptr;
lv_obj_t* enable_switch = nullptr;
lv_obj_t* enable_on_boot_switch = nullptr;

View File

@ -1,7 +1,10 @@
#pragma once
#include "Tactility/service/ServiceContext.h"
#include "Tactility/service/Service.h"
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/Service.h>
#include <Tactility/Mutex.h>
#include <memory>
namespace tt::service {
@ -21,7 +24,7 @@ public:
const ServiceManifest& getManifest() const override;
/** Retrieve the paths that are relevant to this service */
std::unique_ptr<Paths> getPaths() const override;
std::unique_ptr<ServicePaths> getPaths() const override;
std::shared_ptr<Service> getService() const { return service; }

View File

@ -1,22 +0,0 @@
#pragma once
#include "Tactility/service/ServiceInstance.h"
namespace tt::service {
class ServiceInstancePaths final : public Paths {
std::shared_ptr<const ServiceManifest> manifest;
public:
explicit ServiceInstancePaths(std::shared_ptr<const ServiceManifest> manifest) : manifest(std::move(manifest)) {}
~ServiceInstancePaths() override = default;
std::string getDataDirectory() const override;
std::string getDataPath(const std::string& childPath) const override;
std::string getSystemDirectory() const override;
std::string getSystemPath(const std::string& childPath) const override;
};
}

View File

@ -1,5 +1,5 @@
#include "Tactility/app/AppInstance.h"
#include "Tactility/app/AppInstancePaths.h"
#include <Tactility/app/AppInstance.h>
#include <Tactility/app/AppPaths.h>
namespace tt::app {
@ -49,9 +49,9 @@ std::shared_ptr<const Bundle> AppInstance::getParameters() const {
return result;
}
std::unique_ptr<Paths> AppInstance::getPaths() const {
std::unique_ptr<AppPaths> AppInstance::getPaths() const {
assert(manifest != nullptr);
return std::make_unique<AppInstancePaths>(*manifest);
return std::make_unique<AppPaths>(*manifest);
}
} // namespace

View File

@ -1,5 +1,6 @@
#include "Tactility/app/AppInstancePaths.h"
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/MountPoints.h>
#define LVGL_PATH_PREFIX std::string("A:/")
@ -11,24 +12,24 @@
namespace tt::app {
std::string AppInstancePaths::getDataDirectory() const {
std::string AppPaths::getDataDirectory() const {
if (manifest.appLocation.isInternal()) {
}
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.appId;
}
std::string AppInstancePaths::getDataPath(const std::string& childPath) const {
std::string AppPaths::getDataPath(const std::string& childPath) const {
assert(!childPath.starts_with('/'));
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/app/" + manifest.appId + '/' + childPath;
}
std::string AppInstancePaths::getSystemDirectory() const {
std::string AppPaths::getSystemDirectory() const {
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.appId;
}
std::string AppInstancePaths::getSystemPath(const std::string& childPath) const {
std::string AppPaths::getSystemPath(const std::string& childPath) const {
assert(!childPath.starts_with('/'));
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/app/" + manifest.appId + '/' + childPath;
}

View File

@ -1,6 +1,7 @@
#include <Tactility/TactilityCore.h>
#include <Tactility/TactilityPrivate.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppPaths.h>
#include <Tactility/CpuAffinity.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/usb/Usb.h>

View File

@ -1,6 +1,7 @@
#include <Tactility/Tactility.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/service/loader/Loader.h>

View File

@ -1,5 +1,6 @@
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/timezone/TimeZone.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>

View File

@ -1,17 +1,19 @@
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceInstancePaths.h"
#include <Tactility/service/ServiceInstance.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServicePaths.h>
namespace tt::service {
ServiceInstance::ServiceInstance(std::shared_ptr<const service::ServiceManifest> manifest) :
ServiceInstance::ServiceInstance(std::shared_ptr<const ServiceManifest> manifest) :
manifest(manifest),
service(manifest->createService())
{}
const service::ServiceManifest& ServiceInstance::getManifest() const { return *manifest; }
const ServiceManifest& ServiceInstance::getManifest() const { return *manifest; }
std::unique_ptr<Paths> ServiceInstance::getPaths() const {
return std::make_unique<ServiceInstancePaths>(manifest);
std::unique_ptr<ServicePaths> ServiceInstance::getPaths() const {
return std::make_unique<ServicePaths>(manifest);
}
}

View File

@ -1,6 +1,7 @@
#include "Tactility/service/ServiceInstancePaths.h"
#include <Tactility/service/ServicePaths.h>
#include "Tactility/MountPoints.h"
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/MountPoints.h>
#define LVGL_PATH_PREFIX std::string("A:/")
@ -12,20 +13,20 @@
namespace tt::service {
std::string ServiceInstancePaths::getDataDirectory() const {
std::string ServicePaths::getDataDirectory() const {
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/service/" + manifest->id;
}
std::string ServiceInstancePaths::getDataPath(const std::string& childPath) const {
std::string ServicePaths::getDataPath(const std::string& childPath) const {
assert(!childPath.starts_with('/'));
return PARTITION_PREFIX + file::DATA_PARTITION_NAME + "/service/" + manifest->id + '/' + childPath;
}
std::string ServiceInstancePaths::getSystemDirectory() const {
std::string ServicePaths::getSystemDirectory() const {
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/service/" + manifest->id;
}
std::string ServiceInstancePaths::getSystemPath(const std::string& childPath) const {
std::string ServicePaths::getSystemPath(const std::string& childPath) const {
assert(!childPath.starts_with('/'));
return PARTITION_PREFIX + file::SYSTEM_PARTITION_NAME + "/service/" + manifest->id + '/' + childPath;
}

View File

@ -1,6 +1,6 @@
#include "Tactility/service/gps/GpsService.h"
#include "Tactility/file/ObjectFile.h"
#include <Tactility/file/ObjectFile.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/service/ServicePaths.h>
#include <cstring>
#include <unistd.h>

View File

@ -1,9 +1,10 @@
#include "Tactility/service/gps/GpsService.h"
#include "Tactility/service/ServiceManifest.h"
#include "Tactility/service/ServiceRegistration.h"
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/Log.h>
#include <Tactility/file/File.h>
#include <Tactility/Log.h>
#include <Tactility/service/ServicePaths.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
using tt::hal::gps::GpsDevice;

View File

@ -1,16 +1,16 @@
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/Mutex.h>
#include <Tactility/Tactility.h>
#include <Tactility/Timer.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/ServicePaths.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/Timer.h>
namespace tt::service::statusbar {
@ -148,7 +148,7 @@ class StatusbarService final : public Service {
int8_t power_icon_id;
const char* power_last_icon = nullptr;
std::unique_ptr<Paths> paths;
std::unique_ptr<ServicePaths> paths;
void lock() const {
mutex.lock();

View File

@ -1,5 +1,6 @@
#include "tt_app.h"
#include <Tactility/app/App.h>
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/AppContext.h>
extern "C" {