Mantid
Loading...
Searching...
No Matches
UsageService.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2015 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidKernel/DllConfig.h"
12#include "MantidTypes/Core/DateAndTime.h"
13
14#include <json/value.h>
15
16#include <Poco/ActiveMethod.h>
17#include <Poco/Timer.h>
18
19#include <mutex>
20#include <queue>
21
22namespace Mantid {
23namespace Kernel {
24
29
42public:
44 FeatureUsage(const FeatureType &type, std::string name, const bool internal, std::string application);
45 bool operator<(const FeatureUsage &r) const;
46
47 ::Json::Value asJson() const;
48
50 std::string name;
52 std::string application;
53
54protected:
55 std::string featureTypeToString() const;
56};
57
58class MANTID_KERNEL_DLL UsageServiceImpl {
59public:
61 void setApplicationName(const std::string &name);
63 std::string getApplicationName() const;
65 void setInterval(const uint32_t seconds = 60);
67 void registerStartup();
72 void registerFeatureUsage(const FeatureType &type, const std::vector<std::string> &name, const bool internal);
74 void registerFeatureUsage(const FeatureType &type, const std::string &name, const bool internal);
79 void registerFeatureUsage(const FeatureType &type, std::initializer_list<std::string> name, const bool internal);
80
82 bool isEnabled() const;
84 void setEnabled(const bool enabled);
86 void clear();
88 void flush();
89 void shutdown();
91 Types::Core::time_duration getUpTime();
93 Types::Core::DateAndTime getStartTime() { return m_startTime; }
94
95protected:
99 virtual ~UsageServiceImpl() = default;
101 virtual std::string generateStartupMessage();
103 virtual std::string generateFeatureUsageMessage();
105 virtual Kernel::InternetHelper::HTTPStatus sendReport(const std::string &message, const std::string &url);
106
107private:
113
115 void sendStartupReport();
117 void sendFeatureUsageReport(const bool synchronous);
118
119 InternetHelper::HTTPStatus sendStartupAsyncImpl(const std::string &message);
120 InternetHelper::HTTPStatus sendFeatureAsyncImpl(const std::string &message);
121
123 void timerCallback(Poco::Timer &);
124
125 // generate Json header for feature calls
126 ::Json::Value generateFeatureHeader();
127
129 Poco::Timer m_timer;
130
132 uint32_t m_timerTicks;
135
136 std::queue<FeatureUsage> m_FeatureQueue;
139 mutable std::mutex m_mutex;
140 std::string m_application;
141 Types::Core::DateAndTime m_startTime;
142
147
149 std::string m_url;
150};
151
152EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<UsageServiceImpl>;
154
155} // namespace Kernel
156} // namespace Mantid
UsageReporter : The Usage reporter is responsible for collating, and sending all usage data.
Definition: UsageService.h:41
std::string featureTypeToString() const
Convert the stored feature type enum to a string.
::Json::Value asJson() const
bool operator<(const FeatureUsage &r) const
Manage the lifetime of a class intended to be a singleton.
Poco::ActiveMethod< InternetHelper::HTTPStatus, std::string, UsageServiceImpl > m_featureActiveMethod
Async method for sending feature notifications.
Definition: UsageService.h:146
virtual ~UsageServiceImpl()=default
Destructor.
std::queue< FeatureUsage > m_FeatureQueue
Definition: UsageService.h:136
uint32_t m_timerTicksTarget
The number of timer ticks at which to reset.
Definition: UsageService.h:134
Types::Core::DateAndTime m_startTime
Definition: UsageService.h:141
UsageServiceImpl & operator=(const UsageServiceImpl &)
Private, unimplemented copy assignment operator.
uint32_t m_timerTicks
The number of timer ticks since the last reset.
Definition: UsageService.h:132
Poco::ActiveMethod< InternetHelper::HTTPStatus, std::string, UsageServiceImpl > m_startupActiveMethod
Async method for sending startup notifications.
Definition: UsageService.h:144
UsageServiceImpl(const UsageServiceImpl &)
Private, unimplemented copy constructor.
std::string m_url
Stores the base url of the usage system.
Definition: UsageService.h:149
Types::Core::DateAndTime getStartTime()
Gets the start time of this mantid instance.
Definition: UsageService.h:93
FeatureType
An enum specifying the 4 possible features types that can be logged in the usage service.
Definition: UsageService.h:28
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...