committed by
GitHub
parent
cca7224252
commit
f4f91f81d6
@@ -1,15 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/service/service_instance.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
enum class State {
|
||||
Starting,
|
||||
Started,
|
||||
Stopping,
|
||||
Stopped
|
||||
};
|
||||
using State = ::ServiceState;
|
||||
|
||||
// Forward declaration
|
||||
class ServiceContext;
|
||||
@@ -26,6 +23,6 @@ public:
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<Service> create() { return std::shared_ptr<T>(new T); }
|
||||
void* create(const ::ServiceManifest* /*manifest*/) { return new std::shared_ptr<Service>(std::shared_ptr<T>(new T)); }
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <tactility/service/service_manifest.h>
|
||||
|
||||
struct ServiceInstance;
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
@@ -8,23 +11,23 @@ struct ServiceManifest;
|
||||
class ServicePaths;
|
||||
|
||||
/**
|
||||
* The public representation of a service instance.
|
||||
* Thin, non-owning wrapper around the running TactilityKernel service instance
|
||||
* (ServiceInstance, which the kernel API also calls ServiceContext).
|
||||
* @warning Do not store references or pointers to these! You can retrieve them via the Loader service.
|
||||
*/
|
||||
class ServiceContext {
|
||||
class ServiceContext final {
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ServiceContext() = default;
|
||||
::ServiceInstance* service_instance;
|
||||
|
||||
public:
|
||||
|
||||
explicit ServiceContext(::ServiceInstance* instance) : service_instance(instance) {}
|
||||
|
||||
/** @return a reference to the service's manifest */
|
||||
virtual const ServiceManifest& getManifest() const = 0;
|
||||
const ::ServiceManifest* getManifest() const;
|
||||
|
||||
/** Retrieve the paths that are relevant to this service */
|
||||
virtual std::unique_ptr<ServicePaths> getPaths() const = 0;
|
||||
std::unique_ptr<ServicePaths> getPaths() const;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace tt::service {
|
||||
// Forward declarations
|
||||
class ServiceContext;
|
||||
|
||||
typedef std::shared_ptr<Service>(*CreateService)();
|
||||
using CreateService = ::ServiceCreate;
|
||||
|
||||
/** A ledger that describes the main parts of a service. */
|
||||
struct ServiceManifest {
|
||||
|
||||
@@ -1,45 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/service/service_manifest.h>
|
||||
#include <tactility/service/service_paths.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
// Forward declarations
|
||||
class ServiceManifest;
|
||||
constexpr size_t PATH_BUFFER_SIZE = 255;
|
||||
|
||||
class ServicePaths {
|
||||
|
||||
std::shared_ptr<const ServiceManifest> manifest;
|
||||
const ::ServiceManifest* manifest;
|
||||
|
||||
public:
|
||||
|
||||
explicit ServicePaths(std::shared_ptr<const ServiceManifest> manifest) : manifest(std::move(manifest)) {}
|
||||
explicit ServicePaths(const ::ServiceManifest* manifest) : manifest(manifest) {}
|
||||
|
||||
/**
|
||||
* The user data directory is intended to survive OS upgrades.
|
||||
* The path will not end with a "/".
|
||||
*/
|
||||
std::string getUserDataDirectory() const;
|
||||
std::string getUserDataDirectory() const {
|
||||
char buffer[PATH_BUFFER_SIZE];
|
||||
check(service_paths_get_user_data_directory(manifest->id, buffer, sizeof(buffer)) == ERROR_NONE);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* The user data directory is intended to survive OS upgrades.
|
||||
* Configuration data should be stored here.
|
||||
* @param[in] childPath the path without a "/" prefix
|
||||
*/
|
||||
std::string getUserDataPath(const std::string& childPath) const;
|
||||
std::string getUserDataPath(const std::string& childPath) const {
|
||||
assert(!childPath.starts_with('/'));
|
||||
char buffer[PATH_BUFFER_SIZE];
|
||||
check(service_paths_get_user_data_path(manifest->id, childPath.c_str(), buffer, sizeof(buffer)) == ERROR_NONE);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* You should not store configuration data here.
|
||||
* The path will not end with a "/".
|
||||
*/
|
||||
std::string getAssetsDirectory() const;
|
||||
std::string getAssetsDirectory() const {
|
||||
char buffer[PATH_BUFFER_SIZE];
|
||||
check(service_paths_get_assets_directory(manifest->id, buffer, sizeof(buffer)) == ERROR_NONE);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* You should not store configuration data here.
|
||||
* @param[in] childPath the path without a "/" prefix
|
||||
*/
|
||||
std::string getAssetsPath(const std::string& childPath) const;
|
||||
std::string getAssetsPath(const std::string& childPath) const {
|
||||
assert(!childPath.starts_with('/'));
|
||||
char buffer[PATH_BUFFER_SIZE];
|
||||
check(service_paths_get_assets_path(manifest->id, childPath.c_str(), buffer, sizeof(buffer)) == ERROR_NONE);
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ State getState(const std::string& id);
|
||||
* @param[in] id the id as defined in the manifest
|
||||
* @return the matching manifest or nullptr when it wasn't found
|
||||
*/
|
||||
std::shared_ptr<const ServiceManifest> findManifestById(const std::string& id);
|
||||
const ::ServiceManifest* findManifestById(const std::string& id);
|
||||
|
||||
/** Find a ServiceContext by its manifest id.
|
||||
* @param[in] id the id as defined in the manifest
|
||||
|
||||
Reference in New Issue
Block a user