\r\n

51Degrees Device Detection C/C++  4.3

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 #ifdef _DEBUG
30 #ifdef _MSC_VER
31 #define _CRTDBG_MAP_ALLOC
32 #include <crtdbg.h>
33 #else
34 #include "dmalloc.h"
35 #endif
36 #endif
37 
38 #define THREAD_COUNT 4
39 
40 static const char *dataDir = "device-detection-data";
41 
42 static const char *dataFileName = "51Degrees-LiteV4.1.hash";
43 
44 static const char *userAgentFileName = "20000 User Agents.csv";
45 
46 using namespace std;
47 using namespace FiftyoneDegrees::Common;
49 
50 namespace FiftyoneDegrees {
51  namespace Examples {
55  namespace Hash {
59  class ExampleBase {
60  public:
61 
69  ExampleBase(byte *data, long length, ConfigHash *config);
70 
76  ExampleBase(string dataFilePath);
77 
84  ExampleBase(string dataFilePath, ConfigHash *config);
85 
89  virtual ~ExampleBase();
90 
94  virtual void run() = 0;
95 
97  static const char* mobileUserAgent;
98 
100  static const char* desktopUserAgent;
101 
103  static const char* mediaHubUserAgent;
104 
110  static void reportStatus(
112  const char* fileName);
113 
114  protected:
119  class SharedState {
120  public:
127  SharedState(EngineHash *engine, string userAgentFilePath);
128 
133  void startThreads();
134 
139  void joinThreads();
140 
146  void processUserAgentsSingle();
147 
153  static void processUserAgentsMulti(void *state);
154 
156  volatile long threadsFinished;
161  thread threads[THREAD_COUNT];
163  };
164 
169  class ThreadState {
170  public:
176  ThreadState(EngineHash *engine);
178  int hashCode;
181  };
182 
189  static unsigned long getHashCode(ResultsHash *results);
190 
197  static void processUserAgent(const char *userAgent, void *state);
198 
199 
206 
207  private:
213  static unsigned long generateHash(unsigned char *value);
214  };
215  }
216  }
217 }
State for a single thread carrying out processing in order to store a hash of the results.
Definition: ExampleBase.hpp:169
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:82
RequiredPropertiesConfig * properties
Properties to initialise the Engine with.
Definition: ExampleBase.hpp:203
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:100
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:156
string userAgentFilePath
Path to the User-Agents to process.
Definition: ExampleBase.hpp:159
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:119
static const char * mobileUserAgent
Example mobile User-Agent string.
Definition: ExampleBase.hpp:97
Base class extended by all Hash examples.
Definition: ExampleBase.hpp:59
static const char * mediaHubUserAgent
Example media hub User-Agent string.
Definition: ExampleBase.hpp:103
EngineHash * engine
Hash Engine used for the example.
Definition: ExampleBase.hpp:205
ConfigHash * config
Configuration for the Engine.
Definition: ExampleBase.hpp:201
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:155
Shared classes.
Definition: Collection.hpp:32
int hashCode
Running hash code for the processing being carried out.
Definition: ExampleBase.hpp:178
EngineHash * engine
Pointer to the engine.
Definition: ExampleBase.hpp:177