Skip to content

Commit

Permalink
Merge pull request #235 from Stivius/feat/notify_status
Browse files Browse the repository at this point in the history
Implement NotifyStatus request
  • Loading branch information
dasgarner authored Feb 1, 2021
2 parents 3717675 + 8e2efdf commit a7d744f
Show file tree
Hide file tree
Showing 29 changed files with 313 additions and 16 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get -y install software-properties-common apt-transport-https ca-certificates libglibmm-2.4-dev libssl-dev
sudo apt-get -y install gnupg curl wget unzip libgtkmm-3.0-dev libwebkitgtk-3.0-dev libxss-dev
sudo apt-get -y install gnupg curl wget unzip libgtkmm-3.0-dev libwebkitgtk-3.0-dev libxss-dev
sudo apt-get -y install gnupg curl libcurl4-gnutls-dev wget unzip libgtkmm-3.0-dev libwebkitgtk-3.0-dev libxss-dev
- name: Installing newer boost
run: |
sudo add-apt-repository ppa:mhier/libboost-latest
Expand Down Expand Up @@ -105,11 +104,17 @@ jobs:
./autogen.sh --disable-gtk-doc
make -j4
sudo make install
- name: Installing date-tz
run: |
curl -o date-tz.tar.gz -SL https://github.com/HowardHinnant/date/archive/v3.0.0.tar.gz
tar -zxvf date-tz.tar.gz
cd date-3.0.0
cmake . -DBUILD_TZ_LIB=ON -DBUILD_SHARED_LIBS=ON -DUSE_SYSTEM_TZ_DB=ON
make -j4
sudo make install
- name: Update ldconfig cache
run: |
ldd /usr/local/lib/gstreamer-1.0/libgstopengl.so
sudo ldconfig
ldd /usr/local/lib/gstreamer-1.0/libgstopengl.so
- name: Building player
run: |
CXX=g++-8 CC=gcc-8 cmake player -Bbuild -DAPP_ENV=AppImage -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
Expand Down
8 changes: 7 additions & 1 deletion player/XiboApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ int XiboApp::run()
screenShotInterval_ = createScreenshotInterval(*xmdsManager_, *mainWindow_);
collectionInterval_ = createCollectionInterval(*xmdsManager_);

collectionInterval_->setCurrentLayoutId(scheduler_->currentLayoutId());

scheduler_->layoutUpdated().connect(
[this]() { collectionInterval_->setCurrentLayoutId(scheduler_->currentLayoutId()); });

scheduler_->reloadSchedule(LayoutSchedule::fromFile(AppConfig::schedulePath()));
scheduler_->scheduleUpdated().connect(
[](const LayoutSchedule& schedule) { schedule.toFile(AppConfig::schedulePath()); });
Expand Down Expand Up @@ -226,7 +231,8 @@ void XiboApp::checkResourceDirectory()

std::unique_ptr<CollectionInterval> XiboApp::createCollectionInterval(XmdsRequestSender& xmdsManager)
{
auto interval = std::make_unique<CollectionInterval>(xmdsManager, *statsRecorder_, *fileCache_);
auto interval =
std::make_unique<CollectionInterval>(xmdsManager, *statsRecorder_, *fileCache_, cmsSettings_.resourcesPath());

interval->updateInterval(playerSettings_.collectInterval());
playerSettings_.collectInterval().valueChanged().connect(
Expand Down
2 changes: 2 additions & 0 deletions player/cms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ add_library(${PROJECT_NAME}
RequiredFilesDownloader.cpp
RequiredFilesDownloader.hpp
CmsStatus.hpp
NotifyStatusInfo.cpp
NotifyStatusInfo.hpp
${XMDS_SOURCES}
)

Expand Down
28 changes: 24 additions & 4 deletions player/cms/CollectionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include "MainLoop.hpp"

#include "NotifyStatusInfo.hpp"
#include "common/dt/DateTime.hpp"
#include "common/dt/Timer.hpp"
#include "common/fs/FileSystem.hpp"
#include "common/fs/StorageUsageInfo.hpp"
#include "common/logger/Logging.hpp"
#include "common/logger/XmlLogsRetriever.hpp"
#include "common/storage/FileCache.hpp"
#include "common/system/System.hpp"
#include "config/AppConfig.hpp"

#include "cms/xmds/XmdsRequestSender.hpp"
Expand All @@ -17,14 +21,17 @@ namespace ph = std::placeholders;

CollectionInterval::CollectionInterval(XmdsRequestSender& xmdsSender,
StatsRecorder& statsRecorder,
FileCache& fileCache) :
FileCache& fileCache,
const FilePath& resourceDirectory) :
xmdsSender_{xmdsSender},
statsRecorder_{statsRecorder},
fileCache_{fileCache},
intervalTimer_{std::make_unique<Timer>()},
collectInterval_{DefaultInterval},
running_{false},
status_{}
status_{},
currentLayoutId_{EmptyLayoutId},
resourceDirectory_{resourceDirectory}
{
assert(intervalTimer_);
}
Expand Down Expand Up @@ -95,11 +102,19 @@ void CollectionInterval::onDisplayRegistered(const ResponseResult<RegisterDispla

if (!statsRecorder_.empty())
{
StatsFormatter formatter;
auto submitStatsResult = xmdsSender_.submitStats(formatter.toXml(statsRecorder_.records())).get();
auto submitStatsResult = xmdsSender_.submitStats(statsRecorder_.records().string()).get();
statsRecorder_.clear();
onSubmitted("SubmitStats", submitStatsResult);
}

NotifyStatusInfo notifyInfo;
// FIXME: store it in collection interval until XMDS refactoring
notifyInfo.currentLayoutId = currentLayoutId_;
notifyInfo.deviceName = System::hostname();
notifyInfo.spaceUsageInfo = FileSystem::storageUsageFor(resourceDirectory_);
notifyInfo.timezone = DateTime::currentTimezone();
auto notifyStatusResult = xmdsSender_.notifyStatus(notifyInfo.string()).get();
onSubmitted("NotifyStatus", notifyStatusResult);
}
sessionFinished(displayError);
}
Expand All @@ -109,6 +124,11 @@ void CollectionInterval::onDisplayRegistered(const ResponseResult<RegisterDispla
}
}

void CollectionInterval::setCurrentLayoutId(const LayoutId& currentLayoutId)
{
currentLayoutId_ = currentLayoutId;
}

PlayerError CollectionInterval::displayStatus(const RegisterDisplay::Result::Status& status)
{
using DisplayCode = RegisterDisplay::Result::Status::Code;
Expand Down
12 changes: 10 additions & 2 deletions player/cms/CollectionInterval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CmsStatus.hpp"
#include "RequiredFilesDownloader.hpp"

#include "cms/xmds/NotifyStatus.hpp"
#include "cms/xmds/RegisterDisplay.hpp"
#include "cms/xmds/RequiredFiles.hpp"
#include "cms/xmds/Schedule.hpp"
Expand All @@ -13,6 +14,7 @@

#include "common/JoinableThread.hpp"
#include "common/dt/Timer.hpp"
#include "common/fs/FilePath.hpp"

#include <boost/signals2/signal.hpp>

Expand All @@ -31,7 +33,10 @@ class CollectionInterval
static constexpr const uint DefaultInterval = 900;

public:
CollectionInterval(XmdsRequestSender& xmdsSender, StatsRecorder& statsRecorder, FileCache& fileCache);
CollectionInterval(XmdsRequestSender& xmdsSender,
StatsRecorder& statsRecorder,
FileCache& fileCache,
const FilePath& resourceDirectory);

bool running() const;
void stop();
Expand All @@ -44,6 +49,8 @@ class CollectionInterval
SignalCollectionFinished& collectionFinished();
SignalFilesDownloaded& filesDownloaded();

void setCurrentLayoutId(const LayoutId& currentLayoutId);

private:
void startTimer();
void sessionFinished(const PlayerError& = {});
Expand All @@ -53,7 +60,6 @@ class CollectionInterval
void onRequiredFiles(const ResponseResult<RequiredFiles::Result>& requiredFiles);
void updateMediaInventory(const RequiredFiles::Result& requiredFilesResult);
void onSchedule(const ResponseResult<Schedule::Result>& schedule);
void onSubmitted(const ResponseResult<SubmitLog::Result>& logResult);
void onSubmitStats(const ResponseResult<SubmitStats::Result>& statsResult);
template <typename Result>
void onSubmitted(std::string_view requestName, const ResponseResult<Result>& submitResult);
Expand All @@ -67,6 +73,8 @@ class CollectionInterval
std::atomic_int collectInterval_;
std::atomic_bool running_;
CmsStatus status_;
LayoutId currentLayoutId_;
FilePath resourceDirectory_;
SignalSettingsUpdated settingsUpdated_;
SignalScheduleAvailable scheduleAvailable_;
SignalCollectionFinished collectionFinished_;
Expand Down
15 changes: 15 additions & 0 deletions player/cms/NotifyStatusInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "NotifyStatusInfo.hpp"

#include "common/parsing/Parsing.hpp"

std::string NotifyStatusInfo::string() const
{
JsonNode tree;
tree.put("currentLayoutId", currentLayoutId);
tree.put("availableSpace", spaceUsageInfo.available);
tree.put("totalSpace", spaceUsageInfo.total);
// tree.put("lastCommandSuccess", ""); TODO: implement when commands will be available
tree.put("deviceName", static_cast<std::string>(deviceName));
tree.put("timeZone", timezone);
return Parsing::jsonToString(tree);
}
15 changes: 15 additions & 0 deletions player/cms/NotifyStatusInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "common/fs/StorageUsageInfo.hpp"
#include "common/system/Hostname.hpp"
#include "schedule/ScheduleItem.hpp"

struct NotifyStatusInfo
{
std::string string() const;

LayoutId currentLayoutId;
StorageUsageInfo spaceUsageInfo;
Hostname deviceName;
std::string timezone;
};
27 changes: 27 additions & 0 deletions player/cms/xmds/NotifyStatus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "NotifyStatus.hpp"

#include "cms/xmds/Resources.hpp"

namespace Resources = XmdsResources::NotifyStatus;

Soap::RequestSerializer<NotifyStatus::Request>::RequestSerializer(const NotifyStatus::Request& request) :
BaseRequestSerializer(request)
{
}

std::string Soap::RequestSerializer<NotifyStatus::Request>::string()
{
return createRequest(Resources::Name, request().serverKey, request().hardwareKey, request().status);
}

Soap::ResponseParser<NotifyStatus::Result>::ResponseParser(const std::string& soapResponse) :
BaseResponseParser(soapResponse)
{
}

NotifyStatus::Result Soap::ResponseParser<NotifyStatus::Result>::parseBody(const XmlNode& node)
{
NotifyStatus::Result result;
result.success = node.get<bool>(Resources::Success);
return result;
}
40 changes: 40 additions & 0 deletions player/cms/xmds/NotifyStatus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include "cms/xmds/BaseRequestSerializer.hpp"
#include "cms/xmds/BaseResponseParser.hpp"
#include "cms/xmds/Soap.hpp"

#include "common/SoapField.hpp"

namespace NotifyStatus
{
struct Result
{
bool success;
};

struct Request
{
SoapField<std::string> serverKey{"serverKey"};
SoapField<std::string> hardwareKey{"hardwareKey"};
SoapField<std::string> status{"status"};
};
}

template <>
class Soap::RequestSerializer<NotifyStatus::Request> : public BaseRequestSerializer<NotifyStatus::Request>
{
public:
RequestSerializer(const NotifyStatus::Request& request);
std::string string();
};

template <>
class Soap::ResponseParser<NotifyStatus::Result> : public BaseResponseParser<NotifyStatus::Result>
{
public:
ResponseParser(const std::string& soapResponse);

protected:
NotifyStatus::Result parseBody(const XmlNode& node) override;
};
6 changes: 6 additions & 0 deletions player/cms/xmds/Resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ namespace XmdsResources
const std::string Success = "success";
}

namespace NotifyStatus
{
const std::string_view Name = "NotifyStatus";
const std::string Success = "success";
}

namespace SubmitScreenShot
{
const std::string_view Name = "SubmitScreenShot";
Expand Down
10 changes: 10 additions & 0 deletions player/cms/xmds/XmdsRequestSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ FutureResponseResult<SubmitScreenShot::Result> XmdsRequestSender::submitScreenSh

return SoapRequestHelper::sendRequest<SubmitScreenShot::Result>(uri_, request);
}

FutureResponseResult<NotifyStatus::Result> XmdsRequestSender::notifyStatus(const std::string& status)
{
NotifyStatus::Request request;
request.serverKey = serverKey_;
request.hardwareKey = hardwareKey_;
request.status = status;

return SoapRequestHelper::sendRequest<NotifyStatus::Result>(uri_, request);
}
4 changes: 3 additions & 1 deletion player/cms/xmds/XmdsRequestSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cms/xmds/GetFile.hpp"
#include "cms/xmds/GetResource.hpp"
#include "cms/xmds/MediaInventory.hpp"
#include "cms/xmds/NotifyStatus.hpp"
#include "cms/xmds/RegisterDisplay.hpp"
#include "cms/xmds/RequiredFiles.hpp"
#include "cms/xmds/Schedule.hpp"
Expand Down Expand Up @@ -36,7 +37,8 @@ class XmdsRequestSender
FutureResponseResult<MediaInventory::Result> mediaInventory(MediaInventoryItems&& items);
FutureResponseResult<SubmitLog::Result> submitLogs(const std::string& logXml);
FutureResponseResult<SubmitStats::Result> submitStats(const std::string& statXml);
FutureResponseResult<SubmitScreenShot::Result> submitScreenShot(const std::string& screenShot);
FutureResponseResult<SubmitScreenShot::Result> submitScreenShot(const std::string& screenshot);
FutureResponseResult<NotifyStatus::Result> notifyStatus(const std::string& status);

private:
Uri uri_;
Expand Down
8 changes: 8 additions & 0 deletions player/common/dt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ add_library(${PROJECT_NAME}
Timer.hpp
)

find_library(DATE_TZ_LINK_LIBRARY NAMES date-tz)
find_path(DATE_TZ_INCLUDE_DIR NAMES date)

message("DATE_TZ_LINK_LIBRARY ${DATE_TZ_LINK_LIBRARY}")
message("DATE_TZ_INCLUDE_DIR ${DATE_INCLUDE_DIR}")

target_link_libraries(${PROJECT_NAME}
Boost::date_time
${GLIBMM_LINK_LIBRARIES}
${DATE_TZ_LINK_LIBRARY}
)

target_include_directories(${PROJECT_NAME}
PUBLIC ${GLIBMM_INCLUDE_DIRS} # TODO remove with workaround
PRIVATE ${DATE_TZ_INCLUDE_DIR}
)
7 changes: 7 additions & 0 deletions player/common/dt/DateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <boost/date_time/c_local_time_adjustor.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#include "date/tz.h"

DateTime::DateTime(const DateTime::Date& date, const DateTime::Time& td) : ptime_{date, td} {}

DateTime::DateTime(const boost::posix_time::ptime& ptime) : ptime_(ptime) {}
Expand Down Expand Up @@ -71,6 +73,11 @@ DateTime DateTime::fromIsoExtendedString(const std::string& str)
return DateTime{dt};
}

std::string DateTime::currentTimezone()
{
return date::current_zone()->name();
}

bool DateTime::valid() const
{
return !ptime_.is_not_a_date_time();
Expand Down
2 changes: 2 additions & 0 deletions player/common/dt/DateTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DateTime
static DateTime fromString(const std::string& str);
static DateTime fromIsoExtendedString(const std::string& str);

static std::string currentTimezone();

std::string string(const char* format) const;
std::string string() const;
std::time_t timestamp() const;
Expand Down
1 change: 1 addition & 0 deletions player/common/fs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(${PROJECT_NAME}
FileSystem.cpp
FileSystem.hpp
Resource.hpp
StorageUsageInfo.hpp
)

target_link_libraries(${PROJECT_NAME}
Expand Down
Loading

0 comments on commit a7d744f

Please sign in to comment.