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

FiftyoneDegrees::Common::EngineBase Class Referenceabstract

Detailed Description

Encapsulates the engine class to be extended by engine implementations.

Common logic is contained in this base class to be used by any extending classes.

An engine is constructed with a configuration, then used to process evidence in order to return a set of results. It also exposes methods to refresh the data using a new data set, and get properties relating to the data set being used by the engine.

Usage Example

using namespace FiftyoneDegrees::Common;
// Construct the engine
EngineBase *engine = new EngineBase(config, properties);
// Process some evidence
ResultsBase *results = engine->processBase(evidence);
// Do something with the results
// ...
// Delete the results and the engine
delete results;
delete engine;
C++ class wrapper for the fiftyoneDegreesConfigBase configuration structure.
Definition ConfigBase.hpp:61
EngineBase(ConfigBase *config, RequiredPropertiesConfig *properties)
Construct a new instance of the engine class with the configuration and properties provided.
ConfigBase * config
Pointer to the configuration used to build the engine.
Definition EngineBase.hpp:262
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
C++ class wrapper for the fiftyoneDegreesPropertiesRequired structure.
Definition RequiredPropertiesConfig.hpp:59
Encapsulates the results of an engine's processing.
Definition ResultsBase.hpp:97
Shared classes.
Definition Collection.hpp:31
Definition GettingStarted.c:67

Inheritance diagram for FiftyoneDegrees::Common::EngineBase:

[legend]

Collaboration diagram for FiftyoneDegrees::Common::EngineBase:

[legend]

Public Member Functions

Constructors and Destructors

 EngineBase (ConfigBase *config, RequiredPropertiesConfig *properties)
 Construct a new instance of the engine class with the configuration and properties provided.
virtual ~EngineBase ()
 Frees the meta data class and the data set resource created by the extending class.

Engine Methods

virtual ResultsBase * processBase (EvidenceBase *evidence) const =0
 Processes the evidence provided and returns the result.
virtual void refreshData () const =0
 Refresh the data set from the original file location.
virtual void refreshData (const char *fileName) const =0
 Refresh the data set from the file location provided.
virtual void refreshData (void *data, fiftyoneDegreesFileOffset length) const =0
 Refresh the data set from the memory location provided.
virtual void refreshData (unsigned char data[], fiftyoneDegreesFileOffset length) const =0
 Refresh the data set from the memory location provided.

Setters

void setLicenseKey (const string &licenseKey)
 Sets the license key to be used when updating the data set.
void setDataUpdateUrl (const string &updateUrl)
 Sets the URL to be used when updating the data set.

Getters

MetaData * getMetaData () const
 Return the a pointer to the meta data class which contains meta data for the properties, values, profiles and components that exist within the engine.
bool getAutomaticUpdatesEnabled () const
 Gets whether or not automatic updates are enabled.
virtual string getDataFilePath () const =0
 Get the path to the data file the current data set was initialised from.
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 created.
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 Date getPublishedTime () const =0
 Get the date at which the current data set was published.
virtual Date getUpdateAvailableTime () const =0
 Get the date at which a new data file will be available to download from the URL returned by getDataUpdateUrl().
virtual string getProduct () const =0
 Get the name of the data set being used e.g.
virtual string getType () const =0
 Get the tier of the data set being used e.g.
const vector< string > * getKeys () const
 Get the list of keys which the engine accepts as evidence.
vector< string > getRequiredProperties () const
 Get the names of the required properties in required property index order, so position i in the vector is the index a caller passes for that property.
bool getIsThreadSafe () const
 Get whether or not the engine was compiled with thread-safe support.

Protected Member Functions

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.
virtual void appendString (stringstream &stream, fiftyoneDegreesCollection *strings, uint32_t offset) const
 Gets a string from a strings collection, and appends to a stream.
virtual void initHttpHeaderKeys (fiftyoneDegreesHeaders *uniqueHeaders)
 Initialise the HTTP header keys which are used by this engine.
void initOverrideKeys (fiftyoneDegreesOverridePropertyArray *overrideProperties)
 Initialise the override keys which are used by this engine.
void addKey (string key)
 Adds a key to the list of keys which should be added as evidence.

Protected Attributes

ConfigBase * config
 Pointer to the configuration used to build the engine.
shared_ptr< fiftyoneDegreesResourceManager > manager
 A shared pointer to the manager is passed around and referenced by all instances that hold open a resource handle.
RequiredPropertiesConfig * requiredProperties
 Pointer to the properties which are going to be used.
MetaData * metaData
 Pointer to the meta data relating to the contents of the engine's data set.
string licenceKey
 License key used to update the data set.
string updateUrl
 URL used to update the data set.
string defaultDataKey
 The default key to use when adding the results to a dictionary.
vector< string > keys
 Keys which should be added to evidence.

Constructor & Destructor Documentation

◆ EngineBase()

FiftyoneDegrees::Common::EngineBase::EngineBase ( ConfigBase * config,
RequiredPropertiesConfig * properties )

Construct a new instance of the engine class with the configuration and properties provided.

Parameters
configused to build the engine
propertiesthe properties expected to be fetched from results, or null for every property

Member Function Documentation

◆ addKey()

void FiftyoneDegrees::Common::EngineBase::addKey ( string key)
protected

Adds a key to the list of keys which should be added as evidence.

This is called by the key init methods.

Parameters
keyto add

◆ appendString()

virtual void FiftyoneDegrees::Common::EngineBase::appendString ( stringstream & stream,
fiftyoneDegreesCollection * strings,
uint32_t offset ) const
protectedvirtual

Gets a string from a strings collection, and appends to a stream.

Parameters
streamto append the string to
stringscollection to get the string from
offsetof the string in the collection

◆ appendValue()

virtual void FiftyoneDegrees::Common::EngineBase::appendValue ( stringstream & stream,
fiftyoneDegreesCollection * strings,
uint32_t offset,
fiftyoneDegreesPropertyValueType storedValueType ) const
protectedvirtual

Gets a string from a strings collection, and appends to a stream.

Parameters
streamto append the string to
stringscollection to get the string from
offsetof the string in the collection
storedValueTypeformat of byte array representation.

◆ getAutomaticUpdatesEnabled()

bool FiftyoneDegrees::Common::EngineBase::getAutomaticUpdatesEnabled ( ) const

Gets whether or not automatic updates are enabled.

If they are, then this tells an external service that it should update the data set.

Returns
true if updates are enabled

◆ getDataFilePath()

virtual string FiftyoneDegrees::Common::EngineBase::getDataFilePath ( ) const
pure virtual

Get the path to the data file the current data set was initialised from.

Returns
data file path

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ getDataFileTempPath()

virtual string FiftyoneDegrees::Common::EngineBase::getDataFileTempPath ( ) const
pure virtual

Get the path to the temporary data file created by the engine, or an empty string if one was not created.

Returns
temp data file path or empty string

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ getDataUpdateUrl()

virtual string FiftyoneDegrees::Common::EngineBase::getDataUpdateUrl ( ) const
virtual

Get the URL to be used when updating the data file, or an empty string if this is not set.

Returns
URL to download new data file from

◆ getIsThreadSafe()

bool FiftyoneDegrees::Common::EngineBase::getIsThreadSafe ( ) const

Get whether or not the engine was compiled with thread-safe support.

If it was not then certain precautions should be taken.

Returns
true if the engine is thread-safe

◆ getKeys()

const vector< string > * FiftyoneDegrees::Common::EngineBase::getKeys ( ) const

Get the list of keys which the engine accepts as evidence.

This is a pointer to an internal vector should not (and cannot) be freed.

Returns
pointer to the list of evidence keys

◆ getMetaData()

MetaData * FiftyoneDegrees::Common::EngineBase::getMetaData ( ) const

Return the a pointer to the meta data class which contains meta data for the properties, values, profiles and components that exist within the engine.

Returns
pointer to the meta data class
Examples
Hash/MetaData.cpp.

◆ getProduct()

virtual string FiftyoneDegrees::Common::EngineBase::getProduct ( ) const
pure virtual

Get the name of the data set being used e.g.

Pattern or Hash.

Returns
product name

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ getPublishedTime()

virtual Date FiftyoneDegrees::Common::EngineBase::getPublishedTime ( ) const
pure virtual

Get the date at which the current data set was published.

Returns
data set published date

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ getRequiredProperties()

vector< string > FiftyoneDegrees::Common::EngineBase::getRequiredProperties ( ) const

Get the names of the required properties in required property index order, so position i in the vector is the index a caller passes for that property.

When the engine named its properties these are the names it was created with, in that order, and a refresh does not change them. When it named none, they are the names of every property the data file loaded has, sorted by name.

Returns
the required property names

◆ getType()

virtual string FiftyoneDegrees::Common::EngineBase::getType ( ) const
pure virtual

Get the tier of the data set being used e.g.

Premium or Enterprise.

Returns
data set type

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ getUpdateAvailableTime()

virtual Date FiftyoneDegrees::Common::EngineBase::getUpdateAvailableTime ( ) const
pure virtual

Get the date at which a new data file will be available to download from the URL returned by getDataUpdateUrl().

Returns
new data set available date

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ initHttpHeaderKeys()

virtual void FiftyoneDegrees::Common::EngineBase::initHttpHeaderKeys ( fiftyoneDegreesHeaders * uniqueHeaders)
protectedvirtual

Initialise the HTTP header keys which are used by this engine.

These are the pieces of evidence which should be passed in if available.

Parameters
uniqueHeadersto get the keys from

◆ initOverrideKeys()

void FiftyoneDegrees::Common::EngineBase::initOverrideKeys ( fiftyoneDegreesOverridePropertyArray * overrideProperties)
protected

Initialise the override keys which are used by this engine.

These are additional pieces of evidence which should be passed in if available.

Parameters
overridePropertiesto get the keys from

◆ processBase()

virtual ResultsBase * FiftyoneDegrees::Common::EngineBase::processBase ( EvidenceBase * evidence) const
pure virtual

Processes the evidence provided and returns the result.

Parameters
evidenceto process. The keys in getKeys() will be the only ones considered by the engine.
Returns
a new results instance with the values for all requested properties

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ refreshData() [1/4]

virtual void FiftyoneDegrees::Common::EngineBase::refreshData ( ) const
pure virtual

Refresh the data set from the original file location.

This should be implemented by the extending class.

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ refreshData() [2/4]

virtual void FiftyoneDegrees::Common::EngineBase::refreshData ( const char * fileName) const
pure virtual

Refresh the data set from the file location provided.

Parameters
fileNameof the new data file

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ refreshData() [3/4]

virtual void FiftyoneDegrees::Common::EngineBase::refreshData ( unsigned char data[],
fiftyoneDegreesFileOffset length ) const
pure virtual

Refresh the data set from the memory location provided.

Parameters
datapointer to the data in memory
lengthof the data in memory

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ refreshData() [4/4]

virtual void FiftyoneDegrees::Common::EngineBase::refreshData ( void * data,
fiftyoneDegreesFileOffset length ) const
pure virtual

Refresh the data set from the memory location provided.

Parameters
datapointer to the data in memory
lengthlength of the data in memory

Implemented in FiftyoneDegrees::DeviceDetection::Hash::EngineHash.

◆ setDataUpdateUrl()

void FiftyoneDegrees::Common::EngineBase::setDataUpdateUrl ( const string & updateUrl)

Sets the URL to be used when updating the data set.

Parameters
updateUrlto set

◆ setLicenseKey()

void FiftyoneDegrees::Common::EngineBase::setLicenseKey ( const string & licenseKey)

Sets the license key to be used when updating the data set.

Parameters
licenseKeyto set

Field Documentation

◆ licenceKey

string FiftyoneDegrees::Common::EngineBase::licenceKey
protected

License key used to update the data set.

May be empty.

◆ manager

shared_ptr<fiftyoneDegreesResourceManager> FiftyoneDegrees::Common::EngineBase::manager
protected

A shared pointer to the manager is passed around and referenced by all instances that hold open a resource handle.

This acts as a counter to ensure that the pointer to the manager remains valid until the last handle is freed. The shared pointer also handles freeing the pointer once no references remain. See resource.h for more information.


The documentation for this class was generated from the following file: