New logging and more (#446)
- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>` - Changed default timezone to Europe/Amsterdam - Fix for logic bug in unPhone hardware - Fix for init/deinit in DRV2605 driver - Other fixes - Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
committed by
GitHub
parent
719f7bcece
commit
f620255c41
@@ -1,6 +1,6 @@
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/service/ServiceInstance.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
constexpr auto* TAG = "ServiceRegistry";
|
||||
static const auto LOGGER = Logger("ServiceRegistration");
|
||||
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<const ServiceManifest>> ManifestMap;
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<ServiceInstance>> ServiceInstanceMap;
|
||||
@@ -25,13 +25,13 @@ void addService(std::shared_ptr<const ServiceManifest> manifest, bool autoStart)
|
||||
// We'll move the manifest pointer, but we'll need to id later
|
||||
const auto& id = manifest->id;
|
||||
|
||||
TT_LOG_I(TAG, "Adding %s", id.c_str());
|
||||
LOGGER.info("Adding {}", id);
|
||||
|
||||
manifest_mutex.lock();
|
||||
if (service_manifest_map[id] == nullptr) {
|
||||
service_manifest_map[id] = std::move(manifest);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service id in use: %s", id.c_str());
|
||||
LOGGER.error("Service id in use: {}", id);
|
||||
}
|
||||
manifest_mutex.unlock();
|
||||
|
||||
@@ -62,10 +62,10 @@ static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const
|
||||
|
||||
// TODO: Return proper error/status instead of BOOL?
|
||||
bool startService(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Starting %s", id.c_str());
|
||||
LOGGER.info("Starting {}", id);
|
||||
auto manifest = findManifestById(id);
|
||||
if (manifest == nullptr) {
|
||||
TT_LOG_E(TAG, "manifest not found for service %s", id.c_str());
|
||||
LOGGER.error("manifest not found for service {}", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -80,14 +80,14 @@ bool startService(const std::string& id) {
|
||||
if (service_instance->getService()->onStart(*service_instance)) {
|
||||
service_instance->setState(State::Started);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Starting %s failed", id.c_str());
|
||||
LOGGER.error("Starting {} failed", id);
|
||||
service_instance->setState(State::Stopped);
|
||||
instance_mutex.lock();
|
||||
service_instance_map.erase(manifest->id);
|
||||
instance_mutex.unlock();
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Started %s", id.c_str());
|
||||
LOGGER.info("Started {}", id);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -102,10 +102,10 @@ std::shared_ptr<Service> _Nullable findServiceById(const std::string& id) {
|
||||
}
|
||||
|
||||
bool stopService(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Stopping %s", id.c_str());
|
||||
LOGGER.info("Stopping {}", id);
|
||||
auto service_instance = findServiceInstanceById(id);
|
||||
if (service_instance == nullptr) {
|
||||
TT_LOG_W(TAG, "Service not running: %s", id.c_str());
|
||||
LOGGER.warn("Service not running: {}", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ bool stopService(const std::string& id) {
|
||||
instance_mutex.unlock();
|
||||
|
||||
if (service_instance.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "Possible memory leak: service %s still has %ld references", service_instance->getManifest().id.c_str(), service_instance.use_count() - 1);
|
||||
LOGGER.warn("Possible memory leak: service {} still has {} references", service_instance->getManifest().id, service_instance.use_count() - 1);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Stopped %s", id.c_str());
|
||||
LOGGER.info("Stopped {}", id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user