Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / src / base / FBaseSys.cpp
index a560d93..cde53f6 100644 (file)
  * @brief              This file defines the diagnostics types.
  */
 
-#include <vconf.h>
-#include <dlog.h>
-#include <assert.h>
-#include <stdio.h>
+#include <cassert>
+#include <cstdio>
+#include <cstring>
 #include <unistd.h>
-#include <string.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
-#include <FIoRegistry.h>
-#include <FIoFile.h>
+
+#include <vconf.h>
+#include <dlog.h>
+#include <appinfo.h>
+
 #include <FAppTypes.h>
 #include <FBaseLog.h>
 #include <FBaseSysLog.h>
+
 #include "FBase_Log.h"
 #include "FBase_StringConverter.h"
-#include "FApp_AppInfo.h"
+
+extern "C" {
+#include <iniparser.h>
+}
 
 using namespace Tizen::Base;
-using namespace Tizen::Io;
-using namespace Tizen::Base::Collection;
-using namespace Tizen::App;
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -47,7 +49,11 @@ using namespace Tizen::App;
 #define LOG_TAG_NULL ""
 #endif
 
+void __InitializeLogLevel(dictionary *pDic);
+void __InitializePlatformModule(dictionary *pDic);
+
 static const char LOG_TAG_ASSERT[] = "Assert";
+static const char FILE_DEBUGMODE[] = "/opt/etc/.debugmode";
 
 bool iniLoaded = false;
 
@@ -431,7 +437,7 @@ AppassertInternal(const char* pFunction, int lineNumber)
        char logTag[LOG_MODULE_NAME_LEN_MAX];
 
        vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &appDebug);
-       platformDebug = File::IsFileExist( "/opt/etc/.debugmode");
+       platformDebug = (0 == access(FILE_DEBUGMODE, F_OK));
 
        snprintf(logTag, LOG_MODULE_NAME_LEN_MAX, "%s", appName);
        logTag[LOG_MODULE_NAME_LEN_MAX - 1] = '\0';
@@ -459,7 +465,7 @@ AppassertfInternal(const char* expr, const char* pFunction, int lineNumber, cons
        va_start(args, pFormat);
 
        vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &appDebug);
-       platformDebug = File::IsFileExist( "/opt/etc/.debugmode");
+       platformDebug = (0 == access(FILE_DEBUGMODE, F_OK));
 
        if( (platformDebug == false) && (appDebug == 0) )
        {
@@ -599,7 +605,7 @@ SysAssertInternal(const char* pFileName, int lineNumber, const char* pFunction)
        bool platformDebug;
        char logBody[LOG_LEN_MAX];
 
-       platformDebug = File::IsFileExist( "/opt/etc/.debugmode");
+       platformDebug = (0 == access(FILE_DEBUGMODE, F_OK));
 
        if(!platformDebug)
        {
@@ -620,7 +626,7 @@ SysAssertfInternal(const char* expr, const char* pFunction, int lineNumber, cons
        bool platformDebug;
        va_list args;
 
-       platformDebug = File::IsFileExist( "/opt/etc/.debugmode");
+       platformDebug = (0 == access(FILE_DEBUGMODE, F_OK));
 
        if(!platformDebug)
        {
@@ -709,9 +715,7 @@ __PrintLog(_LogType type, const char* pFunction, int lineNumber, const char* pFo
        if (unlikely(!appNameLoaded))
        {
                appNameLoaded = true;
-               char* pAppName = _StringConverter::CopyToCharArrayN(_AppInfo::GetAppExecutableName());
-               strncpy(appName, pAppName, LOG_MODULE_NAME_LEN_MAX);
-               delete [] pAppName;
+               strncpy(appName, appinfo_get_execname(), LOG_MODULE_NAME_LEN_MAX);
        }
        snprintf(logTag, LOG_MODULE_NAME_LEN_MAX, "%s", appName);
 
@@ -892,110 +896,119 @@ __InitializeLogInfo()
 {
        iniLoaded = true;
 
-       Registry reg;
-
-       const String regPath(L"/opt/usr/etc/system-log.ini");
-
-       result r;
+       dictionary *pDic;
+       pDic = iniparser_load("/opt/usr/etc/system-log.ini");
 
-       r = reg.Construct(regPath, REG_OPEN_READ_ONLY, 0);
-
-       if (IsFailed(r))
+       if (pDic == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION] opening ini file failed.\n");
                return;
        }
 
-       __InitializeLogLevel(reg);
-       __InitializePlatformModule(reg);
+       __InitializeLogLevel(pDic);
+       __InitializePlatformModule(pDic);
+
+       iniparser_freedict(pDic);
 }
 
 void
-__InitializeLogLevel(const Registry& reg)
+__InitializeLogLevel(dictionary *pDic)
 {
-       const String sectApp(L"Application");
-       const String sectPlatform(L"Platform");
+       char sectApp[]="Application";
+       char sectPlatform[]="Platform";
 
-       const String entryInfo(L"INFO");
-       const String entryDebug(L"DEBUG");
-       const String entryException(L"EXCEPTION");
+       char entryInfo[]="INFO";
+       char entryDebug[]="DEBUG";
+       char entryException[]="EXCEPTION";
 
-       const String strYes(L"YES");
-       String retString;
+       char strYes[]="YES";
+       char *pVal;
 
-       result r;
+       char keyString[LOG_MODULE_NAME_LEN_MAX*2];
+       int retVal;
 
-       r = reg.GetValue(sectApp, entryInfo, retString);
-       if (IsFailed(r))
+       sprintf(keyString, "%s:%s", sectApp, entryInfo);
+       keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+       pVal = iniparser_getstring(pDic, keyString, NULL);
+       if (pVal == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION]  finding Application/INFO failed.\n");
                return;
        }
-       logInfo.applicationInfoEnabled = retString.Equals(strYes);
-       retString.Clear();
+       retVal = strcmp(strYes, pVal);
+       logInfo.applicationInfoEnabled = (retVal == 0);
 
-       r = reg.GetValue(sectApp, entryDebug, retString);
-       if (IsFailed(r))
+       sprintf(keyString, "%s:%s", sectApp, entryDebug);
+       keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+       pVal = iniparser_getstring(pDic, keyString, NULL);
+       if (pVal == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION]  finding Application/DEBUG failed.\n");
                return;
        }
-       logInfo.applicationDebugEnabled = retString.Equals(strYes);
-       retString.Clear();
+       retVal = strcmp(strYes, pVal);
+       logInfo.applicationDebugEnabled = (retVal == 0);
 
-       r = reg.GetValue(sectApp, entryException, retString);
-       if (IsFailed(r))
+       sprintf(keyString, "%s:%s", sectApp, entryException);
+       keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+       pVal = iniparser_getstring(pDic, keyString, NULL);
+       if (pVal == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION]  finding Application/EXCEPTION failed.\n");
                return;
        }
-       logInfo.applicationExceptionEnabled = retString.Equals(strYes);
-       retString.Clear();
+       retVal = strcmp(strYes, pVal);
+       logInfo.applicationExceptionEnabled = (retVal == 0);
 
-       r = reg.GetValue(sectPlatform, entryInfo, retString);
-       if (IsFailed(r))
+       sprintf(keyString, "%s:%s", sectPlatform, entryInfo);
+       keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+       pVal = iniparser_getstring(pDic, keyString, NULL);
+       if (pVal == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION]  finding Platform/INFO failed.\n");
                return;
        }
-       logInfo.platformInfoEnabled = retString.Equals(strYes);
-       retString.Clear();
+       retVal = strcmp(strYes, pVal);
+       logInfo.platformInfoEnabled = (retVal == 0);
 
-       r = reg.GetValue(sectPlatform, entryException, retString);
-       if (IsFailed(r))
+       sprintf(keyString, "%s:%s", sectPlatform, entryException);
+       keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+       pVal = iniparser_getstring(pDic, keyString, NULL);
+       if (pVal == NULL)
        {
                ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION]  finding Platform/EXCEPTION failed.\n");
                return;
        }
-       logInfo.platformExceptionEnabled = retString.Equals(strYes);
-       retString.Clear();
+       retVal = strcmp(strYes, pVal);
+       logInfo.platformExceptionEnabled = (retVal == 0);
 }
 
 void
-__InitializePlatformModule(const Registry& reg)
+__InitializePlatformModule(dictionary *pDic)
 {
-       const String strYes(L"YES");
-       String retString;
+       char sectModule[]="PlatformModules";
+       char strYes[]="YES";
 
-       const String sectModule(L"PlatformModules");
+       char *pVal;
+       int retVal;
 
-       result r;
+       char keyString[LOG_MODULE_NAME_LEN_MAX*2];
 
        for (int i = 0; i < NID_MAX; i++)
        {
-               String strEntry(logInfo.logTable[i].logIDName);
-               r = reg.GetValue(sectModule, strEntry, retString);
-               if (IsFailed(r))
+
+               sprintf(keyString, "%s:%s", sectModule, logInfo.logTable[i].logIDName);
+               keyString[LOG_MODULE_NAME_LEN_MAX*2-1] = '\0';
+               pVal = iniparser_getstring(pDic, keyString, NULL);
+               if (pVal == NULL)
                {
-                       ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION] finding PlatformModules/%ls failed.\n", strEntry.GetPointer());
+                       ALOG(LOG_ERROR, LOG_TAG, "[EXCEPTION] finding PlatformModules/%ls failed.\n", logInfo.logTable[i].logIDName);
                }
                else
                {
-                       logInfo.logTable[i].loggingEnabled = retString.Equals(strYes);
+                       retVal = strcmp(strYes, pVal);
+                       logInfo.logTable[i].loggingEnabled = (retVal == 0);
                }
-
-               strEntry.Clear();
-               retString.Clear();
        }
 }