/* * Copyright (c) 2014 Amlogic, Inc. All rights reserved. * * This source code is subject to the terms and conditions defined in the * file 'LICENSE' which is part of this source code package. * * Description: c++ file */ #define LOG_MODULE_TAG "PQ" #define LOG_CLASS_TAG "WhitebalanceDataBase" #include #include #include #include #include #include "WhitebalanceDataBase.h" #include "CPQLog.h" #include "CConfigFile.h" #define WHITE_BALANCE_TABLE_NAME "WHITE_BALANCE_TABLE" #define KEY_WHITE_BALANCE "KEY_WHITE_BALANCE" #define KEY_WHITE_BALANCE_GAMMA "KEY_WHITE_BALANCE_GAMMA" #define KEY_GAMMA_TABLE "KEY_GAMMA_TABLE" #define WHITEBALANCE_DEFAULT_PATH "/vendor/etc/tvconfig/pq" static char mFilePath[64] = "\0"; WhitebalanceDataBase *WhitebalanceDataBase::mInstance = NULL; WhitebalanceDataBase *WhitebalanceDataBase::GetInstance() { if (NULL == mInstance) { mInstance = new WhitebalanceDataBase(); } return mInstance; } WhitebalanceDataBase::WhitebalanceDataBase() { Init(); } WhitebalanceDataBase::~WhitebalanceDataBase() { } int WhitebalanceDataBase::Init(void) { static char wb_path[128] = "\0"; const char *config_value = NULL; if (strlen(mFilePath) > 0) { config_value = mFilePath; } else { config_value = CConfigFile::GetInstance()->GetString(CFG_SECTION_PQ, CFG_PQ_WHITEBALANCE_FILE_PATH, WHITEBALANCE_DEFAULT_PATH); } if (config_value == NULL) { LOGE("%s config_value is NULL\n",__FUNCTION__); return -1; } snprintf(wb_path, sizeof(wb_path), "%s/WHITE_BALANCE", config_value); LOGD("%s wb_path Path: %s\n",__FUNCTION__, wb_path); closeDb(); if (CreateNewDB(wb_path) != true) { LOGE("%s CreateNewDB fail!\n", wb_path); return -1; } return 0; } int WhitebalanceDataBase::closePqDB(void) { return closeDb(); } int WhitebalanceDataBase::reopenDB(const char *db_path) { int rval = openDb(db_path); return rval; } bool WhitebalanceDataBase::CreateNewDB(const char *db_path) { if (openDb(db_path) != 0) { LOGE("%s Create db file fail, check path is exist!\n",__FUNCTION__); closeDb(); return false; } if (CreateTable(WHITE_BALANCE_TABLE_NAME) != true) { LOGE("%s Create table %s fail!\n",__FUNCTION__, WHITE_BALANCE_TABLE_NAME); return false; } return true; } bool WhitebalanceDataBase::CreateTable(const char *TableName) { char key[128]; snprintf(key, sizeof(key), "CREATE TABLE IF NOT EXISTS %s(Key TEXT PRIMARY KEY, Value BLOB)", TableName); if (exeSql(key) != true) { LOGE("%s CREATE SQL: %s fail!\n",__FUNCTION__, key); return false; } //for get char key_get[128]; snprintf(key_get, sizeof(key_get), "SELECT Value FROM %s WHERE Key=?", TableName); PrepareSqlSelect(key_get); //for set char key_set[128]; snprintf(key_set, sizeof(key_set), "REPLACE INTO %s(Key,Value) VALUES(?,?)", TableName); PrepareSqlUpdate(key_set); return true; } bool WhitebalanceDataBase::SetWhiteBalanceFilePath(char *path) { if (path == NULL) { return false; } snprintf(mFilePath, sizeof(mFilePath), "%s", path); return true; } bool WhitebalanceDataBase::SetSyncData(void *pData, int iSize) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s", "SYNC_DATA_INFO"); return SetBlobValueToTable(key, pData, iSize); } bool WhitebalanceDataBase::GetSyncData(void *pData, int iSize) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s", "SYNC_DATA_INFO"); return GetBlobValueFromTable(key, pData, iSize); } bool WhitebalanceDataBase::SetRGBGainOffsetData(COLORTEMP_DATA *pData, int level, int src, int timing) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d_%d", KEY_WHITE_BALANCE, src, timing, level); return SetBlobValueToTable(key, (void *)pData, sizeof(COLORTEMP_DATA)); } bool WhitebalanceDataBase::GetRGBGainOffsetData(COLORTEMP_DATA *pData, int level, int src, int timing) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d_%d", KEY_WHITE_BALANCE, src, timing, level); return GetBlobValueFromTable(key, (void *)pData, sizeof(COLORTEMP_DATA)); } bool WhitebalanceDataBase::SetWhitebalanceGammaData(GAMMA_OFFSET_DATA *pData, int level, int mode, int src, int timing) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d_%d_%d", KEY_WHITE_BALANCE_GAMMA, src, timing, level, mode); return SetBlobValueToTable(key, (void *)pData, sizeof(GAMMA_OFFSET_DATA)); } bool WhitebalanceDataBase::GetWhitebalanceGammaData(GAMMA_OFFSET_DATA *pData, int level, int mode, int src, int timing) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d_%d_%d", KEY_WHITE_BALANCE_GAMMA, src, timing, level, mode); return GetBlobValueFromTable(key, (void *)pData, sizeof(GAMMA_OFFSET_DATA)); } bool WhitebalanceDataBase::SetGammaTableData(tcon_gamma_table_t *pData, int level, int type) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d", KEY_GAMMA_TABLE, level, type); return SetBlobValueToTable(key, (void *)pData, sizeof(tcon_gamma_table_t)); } bool WhitebalanceDataBase::GetGammaTableData(tcon_gamma_table_t *pData, int level, int type) { if (pData == NULL) { return false; } char key[64]; snprintf(key, sizeof(key), "%s_%d_%d", KEY_GAMMA_TABLE, level, type); return GetBlobValueFromTable(key, (void *)pData, sizeof(tcon_gamma_table_t)); }