51Degrees Device Detection C/C++  4.1

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* mediaHubUserAgent;
95 
101  static void reportStatus(
103  const char* fileName);
104 
105  protected:
110  class SharedState {
111  public:
118  SharedState(EngineHash *engine, string userAgentFilePath);
119 
124  void startThreads();
125 
130  void joinThreads();
131 
137  void processUserAgentsSingle();
138 
144  static void processUserAgentsMulti(void *state);
145 
147  volatile long threadsFinished;
152  thread threads[THREAD_COUNT];
154  };
155 
160  class ThreadState {
161  public:
167  ThreadState(EngineHash *engine);
169  int hashCode;
172  };
173 
180  static unsigned long getHashCode(ResultsHash *results);
181 
188  static void processUserAgent(const char *userAgent, void *state);
189 
190 
197 
198  private:
204  static unsigned long generateHash(unsigned char *value);
205  };
206  }
207  }
208 }
State for a single thread carrying out processing in order to store a hash of the results.
Definition: ExampleBase.hpp:160
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:82
RequiredPropertiesConfig * properties
Properties to initialise the Engine with.
Definition: ExampleBase.hpp:194
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:147
string userAgentFilePath
Path to the User-Agents to process.
Definition: ExampleBase.hpp:150
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:110
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:94
EngineHash * engine
Hash Engine used for the example.
Definition: ExampleBase.hpp:196
ConfigHash * config
Configuration for the Engine.
Definition: ExampleBase.hpp:192
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:146
Shared classes.
Definition: Collection.hpp:32
int hashCode
Running hash code for the processing being carried out.
Definition: ExampleBase.hpp:169
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:168