Getting started example of using 51Degrees device detection.
The example shows how to:
- Specify name of the data file and properties the dataset should be
const char* fileName = argv;
const char* properties = "IsMobile";
- Instantiate the 51Degrees provider from the specified data file with
the required properties, number of worksets in the pool and cache of the
fileName, &provider, properties, 4, 1000);
- Retrieve a workset from the pool and use it for a single match.
fiftyoneDegreesWorkset *ws = NULL;
ws = fiftyoneDegreesProviderWorksetGet(&provider);
- Match a single HTTP User-Agent string to retrieve the values
associated with the User-Agent for the selected properties.
- Extract the value of the IsMobile property.
valueName = fiftyoneDegreesGetString(ws->dataSet, ws->values->nameOffset);
isMobile = &(valueName->firstByte);
- Release the workset back into the pool of worksets to be reused in one
of the next matches.
- Finally release the memory taken by the provider.
This example assumes you have compiled with 51Degrees.c and city.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.
The size of the worksets pool parameter should be set to the maximum
(expected) number of concurrent detections to avoid delays related to
waiting for free worksets. Workset pool is thread safe. Initially the
number of created worksets in the pool is zero. When a workset is
retrieved from the pool a new workset is created if no worksets are
currently free and the number of worksets already created is less than
the maximum size of the workset pool.
For more examples see the tutorial pages.