OpenICC Documentation  git-devel
OpenICC provides a simple Color Management configuration API
OpenICC Configuration API Documentation

Descriptive Contents

Introduction | API Documentation | Programming Tutorial | References

License
MIT http://www.opensource.org/licenses/mit-license.php
Author
Kai-Uwe Behrmann and others
Since
September 2011-2018
Development
https://github.com/OpenICC/config



Introduction

OpenICC Configuration API provides a platformindependent C interface to persistently store settings across applications and services.

API Documentation

The OpenICC Configuration API is declared in the openicc_config.h and openicc_db.h header files.

The following API is declared in openicc_core.h.

Tools Documentation

OpenICC comes with a few tools, which use the OpenICC API's.

Programming Tutorial

Frist you have to put a

#include <openicc_config.h>

in your source text, in order to use the OpenICC Configuration API.

int main( int argc, char ** argv ) {
int openicc_version = openiccVersion( );
return 0;
}

Then you can put OpenICC functions in your code and compile with:

cc `pkg-config --cflags --libs openicc`  

to link OpenICC into your application.

The following examples gives more details about parsing JSON and get structured key/value device configurations.

First we init language:
const char * loc = setlocale(LC_ALL,"");
openiccInit( loc );

Then we need to read the JSON by whatever is appropriate and start parsing JSON:

db = openiccConfig_FromMem( text );

Providing debug infos is good behaviour and then the number of devices are available:

openiccConfig_SetInfo ( db, file_name );
devices_n = openiccConfig_DevicesCount(db, NULL);

key/values pairs can be printed with openiccConfig_DeviceGet() or dumped again as JSON:

/* print all found key/value pairs */
if(output == 0)
for(i = 0; i < devices_n; ++i)
{
const char * d = openiccConfig_DeviceGet( db, NULL, i,
&keys, &values, malloc,free );
if(i)
fprintf( stderr,"\n");
n = 0; if(keys) while(keys[n]) ++n;
fprintf( stderr, "[%d] device class:\"%s\" with %d keys/values pairs\n", i, d, n);
for( j = 0; j < n; ++j )
{
fprintf(stderr, "%s:\"%s\"\n", keys[j], values[j]);
free(keys[j]);
free(values[j]);
}
free(keys); free(values);
}
/* get a single JSON device */
i = 1; /* select the second one, we start counting from zero */
d = openiccConfig_DeviceGetJSON ( db, NULL, i, 0,
old_device_class, &json, malloc,free );

For a complete device class the JSON head and trail needs to be masked out appropriately:

/* we want a single device class DB for lets say cameras */
devices_n = openiccConfig_DevicesCount( db, devices_filter );
fprintf(stderr, "Found %d %s devices.\n", devices_n, devices_filter[0] );
old_device_class = NULL;
for(i = 0; i < devices_n; ++i)
{
flags = 0;
if(i != 0) /* not the first */
flags |= OPENICC_CONFIGS_SKIP_HEADER;
if(i != devices_n - 1) /* not the last */
flags |= OPENICC_CONFIGS_SKIP_FOOTER;
d = openiccConfig_DeviceGetJSON( db, devices_filter, i, flags,
old_device_class, &json, malloc,free );
old_device_class = d;
if(output <= 1)
printf( "%s\n", json );
free(json);
}

The complete code can be found in openicc_config_read.c