\r\n

51Degrees Device Detection C/C++  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 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 #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 std::cout;
38 using std::thread;
39 using namespace FiftyoneDegrees::Common;
41 
42 namespace FiftyoneDegrees {
43  namespace Examples {
47  namespace Hash {
51  class ExampleBase {
52  public:
53 
61  ExampleBase(byte *data, long length, ConfigHash *config);
62 
68  ExampleBase(string dataFilePath);
69 
76  ExampleBase(string dataFilePath, ConfigHash *config);
77 
81  virtual ~ExampleBase();
82 
86  virtual void run() = 0;
87 
89  static const char* mobileUserAgent;
90 
92  static const char* desktopUserAgent;
93 
95  static const char* uachPlatform;
96 
98  static const char* uachPlatformVersion;
99 
101  static const char* mediaHubUserAgent;
102 
108  static void reportStatus(
110  const char* fileName);
111 
112  protected:
117  class SharedState {
118  public:
125  SharedState(EngineHash *engine, string userAgentFilePath);
126 
131  void startThreads();
132 
137  void joinThreads();
138 
144  void processUserAgentsSingle();
145 
151  static void processUserAgentsMulti(void *state);
152 
154  volatile long threadsFinished;
159  thread threads[THREAD_COUNT];
161  };
162 
167  class ThreadState {
168  public:
174  ThreadState(EngineHash *engine);
176  int hashCode;
179  };
180 
187  static unsigned long getHashCode(ResultsHash *results);
188 
195  static void processUserAgent(const char *userAgent, void *state);
196 
197 
204 
205  private:
211  static unsigned long generateHash(unsigned char *value);
212  };
213  }
214  }
215 }
static const char * uachPlatform
Example UACH Platform value.
Definition: ExampleBase.hpp:95
State for a single thread carrying out processing in order to store a hash of the results.
Definition: ExampleBase.hpp:167
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:77
RequiredPropertiesConfig * properties
Properties to initialise the Engine with.
Definition: ExampleBase.hpp:201
static const char * uachPlatformVersion
Example UACH Platform Version value.
Definition: ExampleBase.hpp:98
Encapsulates the results of a Hash device detection engine's processing.
Definition: ResultsHash.hpp:64
Encapsulates the Hash engine class which implements EngineDeviceDetection.
Definition: EngineHash.hpp:94
Hash Device Detection specific classes.
Definition: ComponentMetaDataBuilderHash.hpp:35
51Degrees base namespace.
Definition: ComponentMetaDataBuilderHash.hpp:33
static const char * desktopUserAgent
Example desktop User-Agent string.
Definition: ExampleBase.hpp:92
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:154
string userAgentFilePath
Path to the User-Agents to process.
Definition: ExampleBase.hpp:157
C++ class wrapper for the fiftyoneDegreesPropertiesRequired structure.
Definition: RequiredPropertiesConfig.hpp:58
State containing the states for all threads running in a multi-threaded example .
Definition: ExampleBase.hpp:117
static const char * mobileUserAgent
Example mobile User-Agent string.
Definition: ExampleBase.hpp:89
Base class extended by all Hash examples.
Definition: ExampleBase.hpp:51
static const char * mediaHubUserAgent
Example media hub User-Agent string.
Definition: ExampleBase.hpp:101
EngineHash * engine
Hash Engine used for the example.
Definition: ExampleBase.hpp:203
ConfigHash * config
Configuration for the Engine.
Definition: ExampleBase.hpp:199
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:153
Shared classes.
Definition: Collection.hpp:31
int hashCode
Running hash code for the processing being carried out.
Definition: ExampleBase.hpp:176
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:175