\r\n

51Degrees Device Detection C/C++  4.4

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 2023 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 <algorithm>
31 #include "Exceptions.hpp"
32 #include "RequiredPropertiesConfig.hpp"
33 #include "Date.hpp"
34 #include "ConfigBase.hpp"
35 #include "MetaData.hpp"
36 #include "EvidenceBase.hpp"
37 #include "ResultsBase.hpp"
38 #include "dataset.h"
39 #include "property.h"
40 #include "collection.h"
41 
42 
43 namespace FiftyoneDegrees {
44  namespace Common {
77  class EngineBase {
78  public:
91  EngineBase(
93  RequiredPropertiesConfig *properties);
94 
99  virtual ~EngineBase();
100 
114  virtual ResultsBase* processBase(EvidenceBase *evidence) const = 0;
115 
120  virtual void refreshData() const = 0;
121 
126  virtual void refreshData(const char *fileName) const = 0;
127 
133  virtual void refreshData(void *data, long length) const = 0;
134 
140  virtual void refreshData(unsigned char data[], long length) const = 0;
141 
152  void setLicenseKey(const string &licenseKey);
153 
158  void setDataUpdateUrl(const string &updateUrl);
159 
172  MetaData* getMetaData() const;
173 
180  bool getAutomaticUpdatesEnabled() const;
181 
187  virtual string getDataFilePath() const = 0;
188 
194  virtual string getDataFileTempPath() const = 0;
195 
201  virtual string getDataUpdateUrl() const;
202 
207  virtual Date getPublishedTime() const = 0;
208 
214  virtual Date getUpdateAvailableTime() const = 0;
215 
220  virtual string getProduct() const = 0;
221 
227  virtual string getType() const = 0;
228 
235  const vector<string>* getKeys() const;
236 
242  bool getIsThreadSafe() const;
243 
247  protected:
250 
257  shared_ptr<fiftyoneDegreesResourceManager> manager;
258 
261 
265 
267  string licenceKey;
268 
270  string updateUrl;
271 
274 
276  vector<string> keys;
277 
284  virtual void appendString(
285  stringstream &stream,
286  fiftyoneDegreesCollection *strings,
287  uint32_t offset) const;
288 
295  virtual void initHttpHeaderKeys(fiftyoneDegreesHeaders *uniqueHeaders);
296 
303  void initOverrideKeys(
304  fiftyoneDegreesOverridePropertyArray *overrideProperties);
305 
311  void addKey(string key);
312  };
313  }
314 }
315 
316 #endif
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:257
MetaData * metaData
Pointer to the meta data relating to the contents of the engine's data set.
Definition: EngineBase.hpp:264
string licenceKey
License key used to update the data set.
Definition: EngineBase.hpp:267
string defaultDataKey
The default key to use when adding the results to a dictionary.
Definition: EngineBase.hpp:273
Base evidence class containing evidence to be processed by an engine.
Definition: EvidenceBase.hpp:67
Encapsulates the engine class to be extended by engine implementations.
Definition: EngineBase.hpp:77
void setDataUpdateUrl(const string &updateUrl)
Sets the URL to be used when updating the data set.
virtual void refreshData() const =0
Refresh the data set from the original file location.
The Date class wraps the C fiftyoneDegreesDate structure and is used to represent dates in engines.
Definition: Date.hpp:48
virtual string getProduct() const =0
Get the name of the data set being used e.g.
virtual string getDataFilePath() const =0
Get the path to the data file the current data set was initialised from.
51Degrees base namespace.
Definition: ComponentMetaDataBuilderHash.hpp:33
const vector< string > * getKeys() const
Get the list of keys which the engine accepts as evidence.
virtual void initHttpHeaderKeys(fiftyoneDegreesHeaders *uniqueHeaders)
Initialise the HTTP header keys which are used by this engine.
C++ class wrapper for the fiftyoneDegreesConfigBase configuration structure.
Definition: ConfigBase.hpp:60
ConfigBase * config
Pointer to the configuration used to build the engine.
Definition: EngineBase.hpp:249
bool getIsThreadSafe() const
Get whether or not the engine was compiled with thread-safe support.
vector< string > keys
Keys which should be added to evidence.
Definition: EngineBase.hpp:276
bool getAutomaticUpdatesEnabled() const
Gets whether or not automatic updates are enabled.
virtual Date getPublishedTime() const =0
Get the date at which the current data set was published.
string updateUrl
URL used to update the data set.
Definition: EngineBase.hpp:270
MetaData * getMetaData() const
Return the a pointer to the meta data class which contains meta data for the properties,...
Contains meta data for the properties, values, profiles and components that exist within the engine i...
Definition: MetaData.hpp:70
void setLicenseKey(const string &licenseKey)
Sets the license key to be used when updating the data set.
Array of items of type fiftyoneDegreesHeader used to easily access and track the size of the array.
Definition: headers.h:144
C++ class wrapper for the fiftyoneDegreesPropertiesRequired structure.
Definition: RequiredPropertiesConfig.hpp:58
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 getDataUpdateUrl() const
Get the URL to be used when updating the data file, or an empty string if this is not set.
void initOverrideKeys(fiftyoneDegreesOverridePropertyArray *overrideProperties)
Initialise the override keys which are used by this engine.
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...
EngineBase(ConfigBase *config, RequiredPropertiesConfig *properties)
Construct a new instance of the engine class with the configuration and properties provided.
void addKey(string key)
Adds a key to the list of keys which should be added as evidence.
virtual ResultsBase * processBase(EvidenceBase *evidence) const =0
Processes the evidence provided and returns the result.
virtual void appendString(stringstream &stream, fiftyoneDegreesCollection *strings, uint32_t offset) const
Gets a string from a strings collection, and appends to a stream.
Definition: GettingStarted.c:63
virtual ~EngineBase()
Frees the meta data class and the data set resource created by the extending class.
RequiredPropertiesConfig * requiredProperties
Pointer to the properties which are going to be used.
Definition: EngineBase.hpp:260
Array of items of type fiftyoneDegreesOverrideProperty used to easily access and track the size of th...
Definition: overrides.h:103
Encapsulates the results of an engine's processing.
Definition: ResultsBase.hpp:82
All the shared methods and fields required by file, memory and cached collections.
Definition: collection.h:408
virtual string getType() const =0
Get the tier of the data set being used e.g.