Getting started example of using 51Degrees device detection.
The example shows how to:
Instantiate the 51Degrees provider from the specified data file with
the required properties.
- Specify name of the data file and properties the dataset should be
const char* fileName = argv;
const char* properties = "IsMobile";
fileName, &provider, properties);
Create a new device offsets structure and use it for a single match.
fiftyoneDegreesDeviceOffsets *offsets = NULL;
offsets = fiftyoneDegreesCreateDeviceOffsets;
Match a single HTTP User-Agent string to retrieve the values
associated with the User-Agent for the selected properties.
fiftyoneDegreesSetDeviceOffsets(&provider->dataSet, offsets, userAgent);
Extract the value of the IsMobile property.
requiredPropertyIndex = fiftyoneDegreesGetRequiredPropertyIndex(
isMobile = fiftyoneDegreesGetValuePtrFromOffsets(
Free the offsets used for the match.
Finally release the memory taken by the provider.
This example assumes you have compiled with 51Degrees.c.
This will happen automatically if you are compiling as part of the
Visual Studio solution. Additionally, when running the program, the
location of a 51Degrees data file must be passed as a command line
argument if you wish to use Premium or Enterprise data files.
This, and any other Trie example can be built to stream from file to reduce
memory overhead by defining FIFTYONEDEGREES_INDIRECT at compile time. This
encurs a performance penalty due to disk read and cache locking. Currently
the caching used for an indirect (file stream) data set does not reserve an
entity it has given out, so care should be taken to ensure an entity is not
removed from the cache while another thread is using it. This can be done by
defining FIFTYONEDEGREES_NO_THREADING and using the provider in a single
threaded environment. Alternatively, for a multi threaded environment, the
stream caches should be set to a higher number of entries than you expect to
be handed out to threads at any one time. This is done by defining: