logic: Added update checker connecting to online API

* connects to https://www.sourcetrail.com/api/v1/versions/latest
* sends information about OS, platform, license type, current version and a unique user token
* Automatic update check is enabled via Startscreen and performed once every 24 hours on window focus
* Update check can be forced by clicking on "check for new version" on start screen
* renamed TimePoint to TimeStamp

fortune cookie message = In Träumen und im Leben ist nichts unmöglich.
This commit is contained in:
Eberhard Graether
2017-08-08 14:18:14 +02:00
parent db1c3b3f40
commit ff65a3f285
67 changed files with 680 additions and 251 deletions
+13 -2
View File
@@ -13,10 +13,10 @@
#include "utility/utilityUuid.h"
#include "utility/Version.h"
#include "component/controller/IDECommunicationController.h"
#include "component/NetworkFactory.h"
#include "component/view/DialogView.h"
#include "component/view/GraphViewStyle.h"
#include "component/controller/NetworkFactory.h"
#include "component/controller/IDECommunicationController.h"
#include "component/view/MainView.h"
#include "component/view/ViewFactory.h"
#include "data/storage/StorageCache.h"
@@ -24,6 +24,7 @@
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "settings/ColorScheme.h"
#include "UpdateChecker.h"
std::shared_ptr<Application> Application::s_instance;
std::string Application::s_uuid;
@@ -61,6 +62,8 @@ void Application::createInstance(
s_instance->m_ideCommunicationController =
networkFactory->createIDECommunicationController(s_instance->m_storageCache.get());
s_instance->m_ideCommunicationController->startListening();
s_instance->m_updateChecker = networkFactory->createUpdateChecker();
}
s_instance->startMessagingAndScheduling();
@@ -309,6 +312,14 @@ void Application::handleMessage(MessageSwitchColorScheme* message)
MessageRefresh().refreshUiOnly().noReloadStyle().dispatch();
}
void Application::handleMessage(MessageWindowFocus* message)
{
if (message->focusIn && ApplicationSettings::getInstance()->getAutomaticUpdateCheck())
{
m_updateChecker->checkUpdate();
}
}
void Application::startMessagingAndScheduling()
{
TaskScheduler::getInstance()->startSchedulerLoopThreaded();
+5
View File
@@ -12,6 +12,7 @@
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "utility/messaging/type/MessageWindowFocus.h"
class Bookmark;
class DialogView;
@@ -19,6 +20,7 @@ class IDECommunicationController;
class MainView;
class NetworkFactory;
class StorageCache;
class UpdateChecker;
class Version;
class ViewFactory;
@@ -29,6 +31,7 @@ class Application
, public MessageListener<MessageLoadProject>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageSwitchColorScheme>
, public MessageListener<MessageWindowFocus>
{
public:
static void createInstance(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory);
@@ -69,6 +72,7 @@ private:
virtual void handleMessage(MessageLoadProject* message);
virtual void handleMessage(MessageRefresh* message);
virtual void handleMessage(MessageSwitchColorScheme* message);
virtual void handleMessage(MessageWindowFocus* message);
void startMessagingAndScheduling();
@@ -86,6 +90,7 @@ private:
std::shared_ptr<ComponentManager> m_componentManager;
std::shared_ptr<IDECommunicationController> m_ideCommunicationController;
std::shared_ptr<UpdateChecker> m_updateChecker;
MessageEnteredLicense::LicenseType m_licenseType;
};
+5 -4
View File
@@ -31,8 +31,6 @@ add_files(
component/controller/IDECommunicationController.h
component/controller/LogController.cpp
component/controller/LogController.h
component/controller/NetworkFactory.cpp
component/controller/NetworkFactory.h
component/controller/RefreshController.cpp
component/controller/RefreshController.h
component/controller/SearchController.cpp
@@ -96,6 +94,8 @@ add_files(
component/ComponentFactory.h
component/ComponentManager.cpp
component/ComponentManager.h
component/NetworkFactory.cpp
component/NetworkFactory.h
data/access/StorageAccess.cpp
data/access/StorageAccess.h
@@ -488,8 +488,8 @@ add_files(
utility/ScopedFunctor.cpp
utility/ScopedFunctor.h
utility/ScopedSwitcher.h
utility/TimePoint.cpp
utility/TimePoint.h
utility/TimeStamp.cpp
utility/TimeStamp.h
utility/tracing.cpp
utility/tracing.h
utility/types.h
@@ -509,4 +509,5 @@ add_files(
Application.h
LicenseChecker.cpp
LicenseChecker.h
UpdateChecker.h
)
+12
View File
@@ -0,0 +1,12 @@
#ifndef UPDATE_CHECKER_H
#define UPDATE_CHECKER_H
class UpdateChecker
{
public:
virtual ~UpdateChecker() {}
virtual void checkUpdate() = 0;
};
#endif // UPDATE_CHECKER_H
-2
View File
@@ -1,7 +1,5 @@
#include "component/ComponentManager.h"
#include "component/controller/NetworkFactory.h"
#include "component/controller/Controller.h"
#include "component/view/CompositeView.h"
#include "component/view/DialogView.h"
-1
View File
@@ -9,7 +9,6 @@
class CompositeView;
class DialogView;
class NetworkFactory;
class StorageAccess;
class TabbedView;
class View;
@@ -1,4 +1,4 @@
#include "component/controller/NetworkFactory.h"
#include "component/NetworkFactory.h"
NetworkFactory::NetworkFactory()
{
@@ -6,4 +6,4 @@ NetworkFactory::NetworkFactory()
NetworkFactory::~NetworkFactory()
{
}
}
@@ -5,6 +5,7 @@
class IDECommunicationController;
class StorageAccess;
class UpdateChecker;
class NetworkFactory
{
@@ -13,6 +14,7 @@ public:
virtual ~NetworkFactory();
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const = 0;
virtual std::shared_ptr<UpdateChecker> createUpdateChecker() const = 0;
};
#endif // NETWORK_FACTORY_H
#endif // NETWORK_FACTORY_H
@@ -249,7 +249,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
EdgeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
EdgeBookmark bookmark(0, message->displayName, message->comment, TimeStamp::now(), category);
bookmark.setEdgeIds(m_activeEdgeIds);
if (!m_activeNodeIds.empty())
@@ -267,7 +267,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Node Bookmark");
NodeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
NodeBookmark bookmark(0, message->displayName, message->comment, TimeStamp::now(), category);
if (message->nodeId)
{
bookmark.addNodeId(message->nodeId);
@@ -3,7 +3,7 @@
#include <memory>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
class SourceLocationFile;
@@ -25,7 +25,7 @@ struct CodeSnippetParams
Id titleId;
Id footerId;
TimePoint modificationTime;
TimeStamp modificationTime;
std::shared_ptr<SourceLocationFile> locationFile;
+2 -2
View File
@@ -4,7 +4,7 @@
#include <vector>
#include "utility/scheduling/Task.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class DialogView;
class FilePath;
@@ -28,7 +28,7 @@ private:
PersistentStorage* m_storage;
std::vector<FilePath> m_filePaths;
TimePoint m_start;
TimeStamp m_start;
};
#endif // TASK_CLEAN_STORAGE_H
+1 -1
View File
@@ -28,7 +28,7 @@ void TaskFinishParsing::doEnter(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
TimePoint start = utility::durationStart();
TimeStamp start = utility::durationStart();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
+3 -3
View File
@@ -1,6 +1,6 @@
#include "Bookmark.h"
Bookmark::Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
Bookmark::Bookmark(const Id id, const std::string& name, const std::string& comment, const TimeStamp& timeStamp, const BookmarkCategory& category)
: m_id(id)
, m_name(name)
, m_comment(comment)
@@ -44,12 +44,12 @@ void Bookmark::setComment(const std::string& comment)
m_comment = comment;
}
TimePoint Bookmark::getTimeStamp() const
TimeStamp Bookmark::getTimeStamp() const
{
return m_timeStamp;
}
void Bookmark::setTimeStamp(const TimePoint& timeStamp)
void Bookmark::setTimeStamp(const TimeStamp& timeStamp)
{
m_timeStamp = timeStamp;
}
+5 -5
View File
@@ -4,7 +4,7 @@
#include <vector>
#include <string>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
#include "BookmarkCategory.h"
@@ -12,7 +12,7 @@
class Bookmark
{
public:
Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
Bookmark(const Id id, const std::string& name, const std::string& comment, const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~Bookmark();
Id getId() const;
@@ -24,8 +24,8 @@ public:
std::string getComment() const;
void setComment(const std::string& comment);
TimePoint getTimeStamp() const;
void setTimeStamp(const TimePoint& timeStamp);
TimeStamp getTimeStamp() const;
void setTimeStamp(const TimeStamp& timeStamp);
BookmarkCategory getCategory() const;
void setCategory(const BookmarkCategory& category);
@@ -37,7 +37,7 @@ private:
Id m_id;
std::string m_name;
std::string m_comment;
TimePoint m_timeStamp;
TimeStamp m_timeStamp;
BookmarkCategory m_category;
bool m_isValid;
};
+4 -1
View File
@@ -1,6 +1,9 @@
#include "EdgeBookmark.h"
EdgeBookmark::EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
EdgeBookmark::EdgeBookmark(
const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category
)
: Bookmark(id, name, comment, timeStamp, category)
{
}
+2 -1
View File
@@ -7,7 +7,8 @@ class EdgeBookmark
: public Bookmark
{
public:
EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
EdgeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~EdgeBookmark();
void addEdgeId(const Id edgeId);
+3 -1
View File
@@ -1,6 +1,8 @@
#include "NodeBookmark.h"
NodeBookmark::NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
NodeBookmark::NodeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category
)
: Bookmark(id, name, comment, timeStamp, category)
{
}
+2 -1
View File
@@ -7,7 +7,8 @@ class NodeBookmark
: public Bookmark
{
public:
NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
NodeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~NodeBookmark();
void addNodeId(const Id nodeId);
+2 -2
View File
@@ -6,7 +6,7 @@
#include "utility/scheduling/Task.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/scheduling/TaskDecorator.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class DialogView;
class FileRegister;
@@ -27,7 +27,7 @@ private:
PersistentStorage* m_storage;
TimePoint m_start;
TimeStamp m_start;
};
#endif // TASK_PARSE_WRAPPER_H
+1 -1
View File
@@ -10,7 +10,7 @@
#include "utility/messaging/type/MessageNewErrors.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/tracing.h"
#include "utility/utility.h"
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef STORAGE_STATS_H
#define STORAGE_STATS_H
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
struct StorageStats
{
@@ -20,7 +20,7 @@ struct StorageStats
size_t completedFileCount;
size_t fileLOCCount;
TimePoint timestamp;
TimeStamp timestamp;
};
#endif // STORAGE_STATS_H
@@ -1,7 +1,7 @@
#include "data/storage/sqlite/SqliteStorage.h"
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
: m_dbFilePath(dbFilePath.canonical())
@@ -127,12 +127,12 @@ bool SqliteStorage::isIncompatible() const
void SqliteStorage::setTime()
{
insertOrUpdateMetaValue("timestamp", TimePoint::now().toString());
insertOrUpdateMetaValue("timestamp", TimeStamp::now().toString());
}
TimePoint SqliteStorage::getTime() const
TimeStamp SqliteStorage::getTime() const
{
return TimePoint(getMetaValue("timestamp"));
return TimeStamp(getMetaValue("timestamp"));
}
void SqliteStorage::setupMetaTable()
+2 -2
View File
@@ -7,7 +7,7 @@
#include "utility/file/FilePath.h"
class SqliteStorageMigration;
class TimePoint;
class TimeStamp;
class SqliteStorage
{
@@ -43,7 +43,7 @@ public:
bool isIncompatible() const;
void setTime();
TimePoint getTime() const;
TimeStamp getTime() const;
protected:
void setupMetaTable();
+31
View File
@@ -4,6 +4,7 @@
#include "settings/migration/SettingsMigrationMoveKey.h"
#include "utility/ResourcePaths.h"
#include "utility/Status.h"
#include "utility/TimeStamp.h"
#include "utility/utility.h"
#include "utility/UserPaths.h"
@@ -405,6 +406,36 @@ void ApplicationSettings::setAcceptedEulaVersion(int version)
setValue<int>("user/accepted_eula_version", version);
}
std::string ApplicationSettings::getUserToken() const
{
return getValue<std::string>("user/token", "");
}
void ApplicationSettings::setUserToken(std::string token)
{
setValue<std::string>("user/token", token);
}
bool ApplicationSettings::getAutomaticUpdateCheck() const
{
return getValue<bool>("user/update_check/automatic", false);
}
void ApplicationSettings::setAutomaticUpdateCheck(bool automaticUpdates)
{
setValue<bool>("user/update_check/automatic", automaticUpdates);
}
TimeStamp ApplicationSettings::getLastUpdateCheck() const
{
return TimeStamp(getValue<std::string>("user/update_check/last", ""));
}
void ApplicationSettings::setLastUpdateCheck(const TimeStamp& time)
{
setValue<std::string>("user/update_check/last", time.toString());
}
int ApplicationSettings::getPluginPort() const
{
return getValue<int>("network/plugin_port", 6666);
+11
View File
@@ -5,6 +5,8 @@
#include "settings/Settings.h"
class TimeStamp;
class ApplicationSettings
: public Settings
{
@@ -117,6 +119,15 @@ public:
int getAcceptedEulaVersion() const;
void setAcceptedEulaVersion(int version);
std::string getUserToken() const;
void setUserToken(std::string token);
bool getAutomaticUpdateCheck() const;
void setAutomaticUpdateCheck(bool automaticUpdates);
TimeStamp getLastUpdateCheck() const;
void setLastUpdateCheck(const TimeStamp& time);
// network
int getPluginPort() const;
void setPluginPort(const int pluginPort);
-40
View File
@@ -1,40 +0,0 @@
#ifndef TIME_POINT_H
#define TIME_POINT_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimePoint // that name sounds pretty silly, was time stamp not ok?
{
public:
static TimePoint now();
TimePoint();
TimePoint(boost::posix_time::ptime t);
//TimePoint(time_t t);
TimePoint(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
inline bool operator<(const TimePoint& rhs){ return m_time < rhs.m_time; }
inline bool operator>(const TimePoint& rhs){ return m_time > rhs.m_time; }
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
inline float operator-(const TimePoint& rhs){ return deltaMS(rhs) / 1000.0f; }
size_t deltaMS(const TimePoint& other) const;
size_t deltaS(const TimePoint& other) const;
bool isSameDay(const TimePoint& other) const;
size_t deltaDays(const TimePoint& other) const; // days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_POINT_H
@@ -1,26 +1,21 @@
#include "TimePoint.h"
#include "TimeStamp.h"
TimePoint TimePoint::now()
TimeStamp TimeStamp::now()
{
return TimePoint(boost::posix_time::microsec_clock::local_time());
return TimeStamp(boost::posix_time::microsec_clock::local_time());
}
TimePoint::TimePoint()
TimeStamp::TimeStamp()
: m_time(boost::posix_time::not_a_date_time)
{
}
TimePoint::TimePoint(boost::posix_time::ptime t)
TimeStamp::TimeStamp(boost::posix_time::ptime t)
: m_time(t)
{
}
//TimePoint::TimePoint(time_t t)
//{
// needs an implementation
//}
TimePoint::TimePoint(std::string s)
TimeStamp::TimeStamp(std::string s)
: m_time(boost::posix_time::not_a_date_time)
{
if (s.size())
@@ -29,12 +24,12 @@ TimePoint::TimePoint(std::string s)
}
}
bool TimePoint::isValid() const
bool TimeStamp::isValid() const
{
return m_time != boost::posix_time::not_a_date_time;
}
std::string TimePoint::toString() const
std::string TimeStamp::toString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -44,7 +39,7 @@ std::string TimePoint::toString() const
return stream.str();
}
std::string TimePoint::getDDMMYYYYString() const
std::string TimeStamp::getDDMMYYYYString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -54,17 +49,17 @@ std::string TimePoint::getDDMMYYYYString() const
return stream.str();
}
size_t TimePoint::deltaMS(const TimePoint& other) const
size_t TimeStamp::deltaMS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_milliseconds();
}
size_t TimePoint::deltaS(const TimePoint& other) const
size_t TimeStamp::deltaS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_seconds();
}
bool TimePoint::isSameDay(const TimePoint& other) const
bool TimeStamp::isSameDay(const TimeStamp& other) const
{
if (m_time.date().day() == other.m_time.date().day() &&
m_time.date().month() == other.m_time.date().month() &&
@@ -76,8 +71,14 @@ bool TimePoint::isSameDay(const TimePoint& other) const
return false;
}
size_t TimePoint::deltaDays(const TimePoint& other) const
size_t TimeStamp::deltaDays(const TimeStamp& other) const
{
boost::gregorian::date_duration deltaDate = m_time.date() - other.m_time.date();
return size_t(std::abs(deltaDate.days()));
}
long TimeStamp::deltaHours(const TimeStamp& other) const
{
boost::posix_time::time_duration delta = m_time - other.m_time;
return delta.total_seconds() / 3600;
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef TIME_STAMP_H
#define TIME_STAMP_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimeStamp
{
public:
static TimeStamp now();
TimeStamp();
TimeStamp(boost::posix_time::ptime t);
TimeStamp(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimeStamp& rhs) { return m_time == rhs.m_time; }
inline bool operator!=(const TimeStamp& rhs) { return m_time != rhs.m_time; }
inline bool operator<(const TimeStamp& rhs) { return m_time < rhs.m_time; }
inline bool operator>(const TimeStamp& rhs) { return m_time > rhs.m_time; }
inline bool operator<=(const TimeStamp& rhs) { return m_time <= rhs.m_time; }
inline bool operator>=(const TimeStamp& rhs) { return m_time >= rhs.m_time; }
size_t deltaMS(const TimeStamp& other) const;
size_t deltaS(const TimeStamp& other) const;
bool isSameDay(const TimeStamp& other) const;
// days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
size_t deltaDays(const TimeStamp& other) const;
long deltaHours(const TimeStamp& other) const;
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_STAMP_H
+1 -1
View File
@@ -10,7 +10,7 @@ FileInfo::FileInfo(const FilePath& path)
{
}
FileInfo::FileInfo(const FilePath& path, const TimePoint& lastWriteTime)
FileInfo::FileInfo(const FilePath& path, const TimeStamp& lastWriteTime)
: path(path)
, lastWriteTime(lastWriteTime)
{
+3 -3
View File
@@ -6,16 +6,16 @@
#include "boost/date_time.hpp"
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
struct FileInfo
{
FileInfo();
FileInfo(const FilePath& path);
FileInfo(const FilePath& path, const TimePoint& lastWriteTime);
FileInfo(const FilePath& path, const TimeStamp& lastWriteTime);
FilePath path;
TimePoint lastWriteTime;
TimeStamp lastWriteTime;
};
#endif // FILE_INFO_H
+2 -2
View File
@@ -143,7 +143,7 @@ unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
return boost::filesystem::file_size(filePath.path());
}
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
TimeStamp FileSystem::getLastWriteTime(const FilePath& filePath)
{
boost::posix_time::ptime lastWriteTime;
if (filePath.exists())
@@ -151,7 +151,7 @@ TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
std::time_t t = boost::filesystem::last_write_time(filePath.path());
lastWriteTime = boost::posix_time::from_time_t(t);
}
return TimePoint(lastWriteTime);
return TimeStamp(lastWriteTime);
}
std::string FileSystem::getTimeStringNow() // TODO: move to utility
+2 -2
View File
@@ -5,7 +5,7 @@
#include <vector>
#include "utility/file/FileInfo.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class FileSystem
{
@@ -20,7 +20,7 @@ public:
static unsigned long long getFileByteSize(const FilePath& filePath);
static TimePoint getLastWriteTime(const FilePath& filePath);
static TimeStamp getLastWriteTime(const FilePath& filePath);
static std::string getTimeStringNow();
static bool exists(const FilePath& path);
@@ -3,7 +3,7 @@
#include <thread>
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/utility.h"
std::string SharedMemoryGarbageCollector::s_memoryNamePrefix = "grbg_cllctr_";
@@ -101,11 +101,11 @@ void SharedMemoryGarbageCollector::stop()
}
bool otherRunningInstances = false;
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = instances->begin();
it != instances->end(); it++)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) <= s_deleteThresholdSeconds)
{
otherRunningInstances = true;
@@ -163,7 +163,7 @@ void SharedMemoryGarbageCollector::update()
}
SharedMemory::String t(access.getAllocator());
t = TimePoint::now().toString().c_str();
t = TimeStamp::now().toString().c_str();
// update instances
{
@@ -231,11 +231,11 @@ void SharedMemoryGarbageCollector::update()
}
// delete old shared memories
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = timeStamps->begin();
it != timeStamps->end();)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) > s_deleteThresholdSeconds)
{
LOG_INFO_STREAM(<< "collect garbage: " << it->first.c_str());
@@ -10,7 +10,7 @@ TaskDecoratorDelay::TaskDecoratorDelay(size_t delayMS)
void TaskDecoratorDelay::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_start = TimePoint::now();
m_start = TimeStamp::now();
}
Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackboard)
@@ -23,7 +23,7 @@ Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackbo
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
m_delayComplete = (TimePoint::now().deltaMS(m_start) >= m_delayMS);
m_delayComplete = (TimeStamp::now().deltaMS(m_start) >= m_delayMS);
return Task::STATE_HOLD;
}
@@ -5,7 +5,7 @@
#include "utility/scheduling/TaskDecorator.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class TaskDecoratorDelay
: public TaskDecorator
@@ -22,7 +22,7 @@ private:
const size_t m_delayMS;
TimePoint m_start;
TimeStamp m_start;
bool m_delayComplete;
};
+2 -2
View File
@@ -173,11 +173,11 @@ ScopedTrace::ScopedTrace(
m_event->functionName = functionName;
m_event->locationName = FilePath(fileName).fileName() + ":" + std::to_string(lineNumber);
m_timePoint = utility::durationStart();
m_TimeStamp = utility::durationStart();
}
ScopedTrace::~ScopedTrace()
{
m_event->time = utility::duration(m_timePoint);
m_event->time = utility::duration(m_TimeStamp);
Tracer::getInstance()->finishEvent(m_event);
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include <stack>
#include <thread>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
struct TraceEvent
@@ -63,7 +63,7 @@ public:
private:
TraceEvent* m_event;
TimePoint m_timePoint;
TimeStamp m_TimeStamp;
};
+7 -7
View File
@@ -16,20 +16,20 @@ ApplicationArchitectureType utility::getApplicationArchitectureType()
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
TimePoint utility::durationStart()
TimeStamp utility::durationStart()
{
return TimePoint::now();
return TimeStamp::now();
}
float utility::duration(const TimePoint& start)
float utility::duration(const TimeStamp& start)
{
TimePoint now = durationStart();
return now - start;
TimeStamp now = durationStart();
return float(now.deltaMS(start)) / 1000.0f;
}
float utility::duration(std::function<void()> func)
{
const TimePoint start = durationStart();
const TimeStamp start = durationStart();
func();
@@ -45,7 +45,7 @@ std::string utility::timeToString(const time_t time)
std::string utility::timeToString(const boost::posix_time::ptime time)
{
return TimePoint(time).toString();
return TimeStamp(time).toString();
}
std::string utility::timeToString(float secondsTotal)
+3 -3
View File
@@ -15,12 +15,12 @@
#include "utility/ApplicationArchitectureType.h"
#include "utility/file/FilePath.h"
#include "utility/math/Vector2.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
namespace utility
{
TimePoint durationStart();
float duration(const TimePoint& start);
TimeStamp durationStart();
float duration(const TimeStamp& start);
float duration(std::function<void()> func);
std::string timeToString(const time_t time);