A device detection library that is used natively or by 51Degrees products

EngineBase.hpp

1/* *********************************************************************
2 * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
4 * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 *
6 * This Original Work is licensed under the European Union Public Licence
7 * (EUPL) v.1.2 and is subject to its terms as set out below.
8 *
9 * If a copy of the EUPL was not distributed with this file, You can obtain
10 * one at https://opensource.org/licenses/EUPL-1.2.
11 *
12 * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 * amended by the European Commission) shall be deemed incompatible for
14 * the purposes of the Work and the provisions of the compatibility
15 * clause in Article 5 of the EUPL shall not apply.
16 *
17 * If using the Work as, or as part of, a network application, by
18 * including the attribution notice(s) required under Article 5 of the EUPL
19 * in the end user terms of the application under an appropriate heading,
20 * such notice(s) shall fulfill the requirements of that article.
21 * ********************************************************************* */
22
23#ifndef FIFTYONE_DEGREES_ENGINE_BASE_HPP
24#define FIFTYONE_DEGREES_ENGINE_BASE_HPP
25
26#include <string>
27#include <vector>
28#include <sstream>
29#include <memory>
30#include <mutex>
31#include <algorithm>
32#include <functional>
33#include "Exceptions.hpp"
34#include "RequiredPropertiesConfig.hpp"
35#include "Date.hpp"
36#include "ConfigBase.hpp"
37#include "MetaData.hpp"
38#include "EvidenceBase.hpp"
39#include "ResultsBase.hpp"
40#include "dataset.h"
41#include "property.h"
42#include "collection.h"
43
44
45namespace FiftyoneDegrees {
46 namespace Common {
47 FIFTYONE_DEGREES_COMMON_CXX_BEGIN
80 class EngineBase {
81 public:
86
96 RequiredPropertiesConfig *properties);
97
102 virtual ~EngineBase();
103
109
118
123 virtual void refreshData() const = 0;
124
129 virtual void refreshData(const char *fileName) const = 0;
130
136 virtual void refreshData(void *data, fiftyoneDegreesFileOffset length) const = 0;
137
143 virtual void refreshData(unsigned char data[], fiftyoneDegreesFileOffset length) const = 0;
144
150
155 void setLicenseKey(const string &licenseKey);
156
161 void setDataUpdateUrl(const string &updateUrl);
162
168
176
184
190 virtual string getDataFilePath() const = 0;
191
197 virtual string getDataFileTempPath() const = 0;
198
204 virtual string getDataUpdateUrl() const;
205
211 virtual Date getPublishedTime() const = 0;
212
219 virtual Date getUpdateAvailableTime() const = 0;
220
225 virtual string getProduct() const = 0;
226
232 virtual string getType() const = 0;
233
242 const vector<string>* getKeys() const;
243
254 vector<string> getRequiredProperties() const;
255
261 bool getIsThreadSafe() const;
262
266 protected:
269
276 shared_ptr<fiftyoneDegreesResourceManager> manager;
277
280
284
287
289 string updateUrl;
290
293
299 mutable vector<std::unique_ptr<const vector<string>>> keyLists;
300
302 mutable std::mutex keysMutex;
303
310 void setKeys(vector<string> &&newKeys) const;
311
319 virtual void appendValue(
320 stringstream &stream,
322 uint32_t offset,
323 fiftyoneDegreesPropertyValueType storedValueType) const;
324
331 virtual void appendString(
332 stringstream &stream,
334 uint32_t offset) const;
335
344 static vector<string> readKeys(
345 const std::function<size_t(char*, size_t, const char*)> &write);
346 };
347 FIFTYONE_DEGREES_COMMON_CXX_END
348 }
349}
350
351#endif
C++ class wrapper for the fiftyoneDegreesConfigBase configuration structure.
Definition ConfigBase.hpp:61
The Date class wraps the C fiftyoneDegreesDate structure and is used to represent dates in engines.
Definition Date.hpp:49
static vector< string > readKeys(const std::function< size_t(char *, size_t, const char *)> &write)
Gets the evidence keys that a C function writes as one string with a separator between them.
virtual void appendString(stringstream &stream, fiftyoneDegreesCollection *strings, uint32_t offset) const
Gets a string from a strings collection, and appends to a stream.
EngineBase(ConfigBase *config, RequiredPropertiesConfig *properties)
Construct a new instance of the engine class with the configuration and properties provided.
virtual void appendValue(stringstream &stream, fiftyoneDegreesCollection *strings, uint32_t offset, fiftyoneDegreesPropertyValueType storedValueType) const
Gets a string from a strings collection, and appends to a stream.
const vector< string > * getKeys() const
Get the list of keys which the engine accepts as evidence.
virtual string getDataFileTempPath() const =0
Get the path to the temporary data file created by the engine, or an empty string if one was not crea...
virtual string getDataFilePath() const =0
Get the path to the data file the current data set was initialised from.
std::mutex keysMutex
Guards keyLists.
Definition EngineBase.hpp:302
vector< string > getRequiredProperties() const
Get the names of the required properties in required property index order, so position i in the vecto...
void setLicenseKey(const string &licenseKey)
Sets the license key to be used when updating the data set.
RequiredPropertiesConfig * requiredProperties
Pointer to the properties which are going to be used.
Definition EngineBase.hpp:279
virtual void refreshData(const char *fileName) const =0
Refresh the data set from the file location provided.
ConfigBase * config
Pointer to the configuration used to build the engine.
Definition EngineBase.hpp:268
virtual Date getPublishedTime() const =0
Get the date at which the current data set was published.
bool getAutomaticUpdatesEnabled() const
Gets whether or not automatic updates are enabled.
vector< std::unique_ptr< const vector< string > > > keyLists
Every list of evidence keys the engine has had, the last being current.
Definition EngineBase.hpp:299
MetaData * metaData
Pointer to the meta data relating to the contents of the engine's data set.
Definition EngineBase.hpp:283
virtual void refreshData(unsigned char data[], fiftyoneDegreesFileOffset length) const =0
Refresh the data set from the memory location provided.
bool getIsThreadSafe() const
Get whether or not the engine was compiled with thread-safe support.
void setKeys(vector< string > &&newKeys) const
Makes a list the engine's evidence keys unless it is the same as the current list.
virtual string getType() const =0
Get the tier of the data set being used e.g.
virtual Date getUpdateAvailableTime() const =0
Get the date at which a new data file will be available to download from the URL returned by getDataU...
string updateUrl
URL used to update the data set.
Definition EngineBase.hpp:289
MetaData * getMetaData() const
Return the a pointer to the meta data class which contains meta data for the properties,...
virtual string getDataUpdateUrl() const
Get the URL to be used when updating the data file, or an empty string if this is not set.
virtual void refreshData(void *data, fiftyoneDegreesFileOffset length) const =0
Refresh the data set from the memory location provided.
shared_ptr< fiftyoneDegreesResourceManager > manager
A shared pointer to the manager is passed around and referenced by all instances that hold open a res...
Definition EngineBase.hpp:276
string licenceKey
License key used to update the data set.
Definition EngineBase.hpp:286
string defaultDataKey
The default key to use when adding the results to a dictionary.
Definition EngineBase.hpp:292
virtual void refreshData() const =0
Refresh the data set from the original file location.
virtual string getProduct() const =0
Get the name of the data set being used e.g.
void setDataUpdateUrl(const string &updateUrl)
Sets the URL to be used when updating the data set.
virtual ~EngineBase()
Frees the meta data class and the data set resource created by the extending class.
virtual ResultsBase * processBase(EvidenceBase *evidence) const =0
Processes the evidence provided and returns the result.
Base evidence class containing evidence to be processed by an engine.
Definition EvidenceBase.hpp:68
Contains meta data for the properties, values, profiles and components that exist within the engine i...
Definition MetaData.hpp:71
C++ class wrapper for the fiftyoneDegreesPropertiesRequired structure.
Definition RequiredPropertiesConfig.hpp:59
Encapsulates the results of an engine's processing.
Definition ResultsBase.hpp:99
long fiftyoneDegreesFileOffset
Type for file offset in API.
Definition fileOffset.h:73
Shared classes.
Definition Collection.hpp:31
A C++ wrapper class for transform.h conversion routines.
Definition ComponentMetaDataBuilderHash.hpp:33
Definition GettingStarted.c:67
All the shared methods and fields required by file, memory and cached collections.
Definition collection.h:410