\r\n

51Degrees Device Detection C/C++  4.3Newer Version 4.4

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

ExampleBase.hpp

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is licensed under the European Union Public Licence (EUPL)
7  * 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 #include <string>
24 #include <iostream>
25 #include <thread>
26 #include "../../../src/hash/EngineHash.hpp"
27 #include "../../../src/common-cxx/textfile.h"
28 
29 #define THREAD_COUNT 4
30 
31 static const char *dataDir = "device-detection-data";
32 
33 static const char *dataFileName = "51Degrees-LiteV4.1.hash";
34 
35 static const char *userAgentFileName = "20000 User Agents.csv";
36 
37 using namespace std;
38 using namespace FiftyoneDegrees::Common;
40 
41 namespace FiftyoneDegrees {
42  namespace Examples {
46  namespace Hash {
50  class ExampleBase {
51  public:
52 
60  ExampleBase(byte *data, long length, ConfigHash *config);
61 
67  ExampleBase(string dataFilePath);
68 
75  ExampleBase(string dataFilePath, ConfigHash *config);
76 
80  virtual ~ExampleBase();
81 
85  virtual void run() = 0;
86 
88  static const char* mobileUserAgent;
89 
91  static const char* desktopUserAgent;
92 
94  static const char* uachPlatform;
95 
97  static const char* uachPlatformVersion;
98 
100  static const char* mediaHubUserAgent;
101 
107  static void reportStatus(
109  const char* fileName);
110 
111  protected:
116  class SharedState {
117  public:
124  SharedState(EngineHash *engine, string userAgentFilePath);
125 
130  void startThreads();
131 
136  void joinThreads();
137 
143  void processUserAgentsSingle();
144 
150  static void processUserAgentsMulti(void *state);
151 
153  volatile long threadsFinished;
158  thread threads[THREAD_COUNT];
160  };
161 
166  class ThreadState {
167  public:
173  ThreadState(EngineHash *engine);
175  int hashCode;
178  };
179 
186  static unsigned long getHashCode(ResultsHash *results);
187 
194  static void processUserAgent(const char *userAgent, void *state);
195 
196 
203 
204  private:
210  static unsigned long generateHash(unsigned char *value);
211  };
212  }
213  }
214 }
static const char * uachPlatform
Example UACH Platform value.
Definition: ExampleBase.hpp:94
State for a single thread carrying out processing in order to store a hash of the results.
Definition: ExampleBase.hpp:166
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:82
RequiredPropertiesConfig * properties
Properties to initialise the Engine with.
Definition: ExampleBase.hpp:200
static const char * uachPlatformVersion
Example UACH Platform Version value.
Definition: ExampleBase.hpp:97
Encapsulates the results of a Hash device detection engine's processing.
Definition: ResultsHash.hpp:65
Encapsulates the Hash engine class which implements EngineDeviceDetection.
Definition: EngineHash.hpp:95
Hash Device Detection specific classes.
Definition: ComponentMetaDataBuilderHash.hpp:36
51Degrees base namespace.
Definition: ComponentMetaDataBuilderHash.hpp:34
static const char * desktopUserAgent
Example desktop User-Agent string.
Definition: ExampleBase.hpp:91
C++ class wrapper for the fiftyoneDegreesConfigHash configuration structure.
Definition: ConfigHash.hpp:72
volatile long threadsFinished
Number of threads that have finished their processing.
Definition: ExampleBase.hpp:153
string userAgentFilePath
Path to the User-Agents to process.
Definition: ExampleBase.hpp:156
C++ class wrapper for the fiftyoneDegreesPropertiesRequired structure.
Definition: RequiredPropertiesConfig.hpp:57
State containing the states for all threads running in a multi-threaded example .
Definition: ExampleBase.hpp:116
static const char * mobileUserAgent
Example mobile User-Agent string.
Definition: ExampleBase.hpp:88
Base class extended by all Hash examples.
Definition: ExampleBase.hpp:50
static const char * mediaHubUserAgent
Example media hub User-Agent string.
Definition: ExampleBase.hpp:100
EngineHash * engine
Hash Engine used for the example.
Definition: ExampleBase.hpp:202
ConfigHash * config
Configuration for the Engine.
Definition: ExampleBase.hpp:198
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:152
Shared classes.
Definition: Collection.hpp:32
int hashCode
Running hash code for the processing being carried out.
Definition: ExampleBase.hpp:175
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:174