Preference
D.I.T
#include "Device/Preference.h"
#include "Interface/Log.h"
#include "dit.h"
void Preference_use ()
{
Preference p = NewPreference ();
p->setInt ("DIT", 123);
LOGINFO("DIT", "%d", p->GetInt ("DIT", 0));
p->setDouble ("DIT", 1.2);
LOGINFO("DIT", "%lf", p->GetDouble ("DIT", 0.0));
p->setBoolean ("DIT", true);
LOGINFO("DIT", "%s", p->getBoolean ("DIT", false) ? "TRUE" : "FALSE");
p->setString ("DIT", "TestMessage");
String ret = NULL;
ret = p->getString ("DIT", NULL);
LOGINFO("DIT", "%s", ret);
free (ret);
DestroyPreference (p);
}
Native
#include <stdlib.h>
#include <string.h>
#include <app_preference.h>
#include <dlog.h>
void Preference_use ()
{
preference_error_e;
preference_set_int ("DIT", 123);
int ret_int;
error = preference_get_int ("DIT", &ret_int);
if ( error == PREFERENCE_ERROR_NONE )
{
dlog_print (DLOG_INFO, "DIT", "%d", ret);
}
else
{
dlog_print (DLOG_INFO, "DIT", "%d", 0);
}
preference_set_double ("DIT", 1.2);
double ret_double;
error = preference_get_double ("DIT", &ret_double);
if ( error == PREFERENCE_ERROR_NONE )
{
dlog_print (DLOG_INFO, "DIT", "%lf", ret_double);
}
else
{
dlog_print (DLOG_INFO, "DIT", "%lf", 0.0);
}
preference_set_boolean ("DIT", true);
bool ret_bool;
error = preference_get_boolean ("DIT", &ret_bool);
if ( error == PREFERENCE_ERROR_NONE )
{
dlog_print (DLOG_INFO, "DIT", "%s", ret_bool ? "TRUE" : "FALSE");
}
else
{
dlog_print (DLOG_INFO, "DIT", "%s", "FALSE");
}
setPreferenceString ("DIT", "TestMessage");
char * ret_string = NULL;
error = preference_get_string (key, &ret_string);
if ( error == PREFERENCE_ERROR_NONE )
{
dlog_print (DLOG_INFO, "DIT", "%s", ret_string);
}
else
{
dlog_print (DLOG_INFO, "DIT", "%s", "");
}
free (ret_string);
}