Example #1
0
TEST_FIXTURE(FileFixture, GetFileValue_SetFileValue)
{
    int v1 = 11;
    int v2 = INT_MAX;
    int v3 = INT_MIN;
    int res = 0;

    /*-- 정상적인 데이터 저장 --*/
    CHECK_EQUAL(1, SetFileValue(validFile, v1));
    CHECK_EQUAL(1, GetFileValue(validFile, &res));
    CHECK_EQUAL(v1, res);

    /*-- 잘못된 파일에 저장 안되야 함 --*/
    CHECK_EQUAL(0, SetFileValue(invalidFile, v1));
    CHECK_EQUAL(0, GetFileValue(invalidFile, &res));

    /*-- 디렉토리에서 읽기가 실패해야 함  --*/
    CHECK_EQUAL(0, SetFileValue(validDirectory, v1));
    CHECK_EQUAL(0, GetFileValue(validDirectory, &res));

    CHECK_EQUAL(1, SetFileValue(validFile, v2));
    CHECK_EQUAL(1, GetFileValue(validFile, &res));
    CHECK_EQUAL(v2, res);

    CHECK_EQUAL(1, SetFileValue(validFile, v3));
    CHECK_EQUAL(1, GetFileValue(validFile, &res));
    CHECK_EQUAL(v3, res);
}
BOOL CLauncherService::LoadSetting()
{
    FILE    *fp;

    fp = fopen(VARCONF_FILENAME, "rb");
    if (fp == NULL)
    {

        fp = fopen(VARCONF_OLD_FILENAME, "rb");
        if (fp == NULL)
        {
            system("rm -rf /app/data/*");
            system("rm -rf /app/sensor/*");
            system("rm -rf /app/member/*");
            system("rm -rf /app/log/*");

            SetFileValue("/app/conf/ethernet.type", ETHER_TYPE_PPP);
            SetFileValue("/app/conf/mobile.type", MOBILE_TYPE_GSM);
            SetFileValue("/app/conf/mobile.mode", MOBILE_MODE_CSD);
            SetFileString("/app/conf/server.addr", "0.0.0.0");    // Server address

        }
        else
        {
            fclose(fp);
        }
    }
    else
    {
        fclose(fp);
    }


    GetVersionString(fullVersionString);

    SetFileString("/app/conf/version", fullVersionString);
    GetFileValue("/app/conf/ethernet.type", &m_nEthernetType);
    GetFileValue("/app/conf/mobile.type", &m_nMobileType);
    GetFileValue("/app/conf/mobile.mode", &m_nMobileMode);
    GetFileValue("/app/conf/mobile.vendor", &m_nMobileVendor);
    GetFileString("/app/conf/server.addr", m_szServer, sizeof(m_szServer));
    GetFileValue("/app/conf/powertype.mcu", (int *)&m_nPowerType);

    /** Issue #109 
     *  Database 관련 정리를 위한 Script 실행 
     */
    system("/app/sw/script/RunAllTask.script 2> /dev/null");
    system("/app/sw/script/CheckTask.script & 2> /dev/null");

    return TRUE;
}
Example #3
0
void CAgentService::LoadVariable()
{
	VAROBJECT 	*pObject;
	ENVENTRY	env_t;
	char		szBuffer[100];
	long		addr=0;
	int			n;

	// Initialize Variable
	VARAPI_Initialize(VARCONF_FILENAME, m_Root_node, TRUE);

	GetLocalAddress(szBuffer);
	addr = inet_addr(szBuffer);
	pObject = VARAPI_GetObjectByName("ethIpAddr");
	if (pObject != NULL) memcpy(pObject->var.stream.p, &addr, sizeof(IPADDR));

	memset(&env_t, 0, sizeof(ENVENTRY));
	GetEnvInfo(env_t.envKernelVersion, env_t.envGccVersion, env_t.envCpuName, &env_t.envCpuMips);

	pObject = VARAPI_GetObjectByName("envKernelVersion");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envKernelVersion);

	pObject = VARAPI_GetObjectByName("envGccVersion");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envGccVersion);

	pObject = VARAPI_GetObjectByName("envCpuName");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envCpuName);

	pObject = VARAPI_GetObjectByName("envCpuMips");
	if (pObject != NULL) pObject->var.stream.u32 = HostToLittleShort(env_t.envCpuMips);

    /** Rewriter(Q) : testmode가 무엇인지 확인해야 함 */
	GetFileValue("/app/conf/testmode", &n);
	m_bGprsPerfTestMode = (n > 0) ? TRUE : FALSE;

    if(GetFileString("/app/conf/mcusystype", szBuffer, sizeof(szBuffer), "OUTDOOR", TRUE)
            && strncasecmp(szBuffer,"INDOOR",strlen("INDOOR"))==0) {
        m_nSystemType = MCU_TYPE_INDOOR;
    }

    /*-- Pulse Meter Type을 읽어온다 --*/
    LoadSensorType();

    /*-- Patch 정보를 읽어온다 --*/
    LoadPatchList();

    /*-- Patch 5-1949 --*/
#if     defined(__PATCH_5_1949__)
    m_nDebugLevel &= (*m_pbPatch_5_1949 ? 0x00 : 0xFF);
#endif
    
}
Example #4
0
void CStatusMonitor::GpioNotify(int nNotify, int nState, void *pParam, void *pArgment)
{
	CStatusMonitor	*pThis;
#if     defined(__SUPPORT_NZC1__) || defined(__SUPPORT_NZC2__)   // Issue #959
#if     defined(__INCLUDE_GPIO__)
	int		nType, dcd;
	int		pid;
#if     !defined(__EXCLUDE_LOW_BATTERY__)
	int		batt;
#endif
#else
	int		nType;
	int		pid;
#endif
#endif // __TI_AM335X__

	pThis = (CStatusMonitor *)pParam;
	switch(nNotify) {
	  case GPIONOTIFY_PWR :
           if(!(m_nNzcPowerType & NZC_POWER_TYPE_SOLAR)) {
		       if (nState == 1)
		       {
			       pThis->m_Locker.Lock();
	               time(&pThis->m_nLastPowerFail);
		   	       pThis->m_nErrorMask |= nNotify;
			       pThis->m_Locker.Unlock();
		       }
		       else
		       {
			       pThis->m_Locker.Lock();
                   if(pThis->m_nLastPowerFail) {
                        pThis->m_nLastPowerFail = 0;
                        pThis->m_nLastPowerRestore = 0;
                   }
	               else time(&pThis->m_nLastPowerRestore);
			       pThis->m_nErrorMask &= ~nNotify;
			       pThis->m_Locker.Unlock();
		       }
		       pThis->ActiveThread();
           }
		   break;
#if     defined(__TI_AM335X__)
      case GPIONOTIFY_DOOR:
           if(pThis->m_nCaseOpen != nState)
           {
                if(nState) // Case Open
                {
                    pThis->m_nErrorMask |= GPIONOTIFY_DOOR;
                    mcuCoverOpenEvent();
                }
                else
                {
                    pThis->m_nErrorMask &= ~GPIONOTIFY_DOOR;
                    mcuCoverCloseEvent();
                }
                pThis->m_nCaseOpen = nState;
           }
           break;
#endif

#if     !defined(__EXCLUDE_LOW_BATTERY__)
	  case GPIONOTIFY_LOWBAT :
		   if (nState == 0)
		   {
			   pThis->m_Locker.Lock();
			   time(&pThis->m_nLastLowBattery);
		   	   pThis->m_nErrorMask |= nNotify;
			   pThis->m_Locker.Unlock();

			   mcuLowBatteryEvent();
		   }
		   else
		   {
               /*-- LOW Battery가 Restore 되어도 특별한 GPIO Handling을 하지 않느다.
                *-- 이미 Shutdown 절차를 수행중이라면 Shutdown이 되게 되고
                *-- 그렇지 않다면 GPIO를 변경하지 않았기 때문에 변경할 부분이 없다. --*/
			   pThis->m_Locker.Lock();
			   pThis->m_nErrorMask &= ~nNotify;
			   pThis->m_Locker.Unlock();

			   mcuLowBatteryRestoreEvent();
		   }
		   pThis->ActiveThread();
		   break;
#endif
      case GPIONOTIFY_BATTERY_CHARG:
		   if (nState == 0)
           {
		   	   pThis->m_nErrorMask |= nNotify;
           }
           else
           {
			   pThis->m_nErrorMask &= ~nNotify;
           }
           break;

#if     defined(__SUPPORT_NZC1__) || defined(__SUPPORT_NZC2__)   // Issue #959
           /** TODO : RING을 Catch 하지 못할 경우 Packet Mode 및 CSD Mode를 사용할 수 없다.
             * TI + AMTelecom 사용시 어떻게 처리할지 여부를 고민해야 한다
             */
	  case GPIONOTIFY_RING :
#if     defined(__INCLUDE_GPIO__)
		   dcd = GPIOAPI_ReadGpio(GP_GSM_DCD_INPUT);
#if     !defined(__EXCLUDE_LOW_BATTERY__)
		   batt = GPIOAPI_ReadGpio(GP_LOW_BATT_INPUT);
#endif

		   XDEBUG("MOBILE: -------- RING(RI) --------\r\n");
#if     !defined(__EXCLUDE_LOW_BATTERY__)
		   XDEBUG("GPIO: BATT=%d, RING=%0d, DCD=%d (%s)\r\n", batt, nState, dcd, dcd == 1 ? "OFF" : "ACTIVE");
#else
		   XDEBUG("GPIO: RING=%0d, DCD=%d (%s)\r\n", nState, dcd, dcd == 1 ? "OFF" : "ACTIVE");
#endif

		   // RING OFF
		   if (nState == 1)
			   break;

           /** Issue #1991: 사용중인 CDMA 모듈이 데이터 통신 이외의 용도로는 사용할 수 없어서
             *     RING만 울리고 DCD는 셋팅되지 않기 때문에 CDMA RING은 무시한다 
             *     구현을 DCD가 Off 가 되는 상태이기 때문에 그 값을 검사하도록 수정한다.
             */
           if(dcd) break;

		   // Send data active
		   if (m_pSystemMonitor->GetCount() != 0)
		   {
			   XDEBUG("MOBILE: ------ Busy (Count) ------\r\n");
			   break;
		   }

		   if (MOBILE_IsBusy())
		   {
			   XDEBUG("MOBILE: ------ Mobile Busy ------\r\n");
			   break;
		   }

		   if (FindProcess("pppd") > 0)
		   {
			   XDEBUG("MOBILE: ------ Busy (ppp) ------\r\n");
			   break;
		   }

		   if (FindProcess("mserver") > 0)
		   {
			   XDEBUG("MOBILE: mserver active. (DCD=%s)\r\n", dcd == 1 ? "OFF" : "ACTIVE");

			   if (dcd == 1)
			   {
			   	   XDEBUG("------ Kill mserver ------\r\n");
			   	   KillProcess("mserver");
				   usleep(3000000);
			   }
			   else
			   {
			   	   XDEBUG("MOBILE: ------ Busy (mserver) ------\r\n");
			   	   break;
			   }
		   }

		   if (FindProcess("send") > 0)
		   {
			   XDEBUG("MOBILE: ------ Busy (send) ------\r\n");
			   break;
		   }

		   XDEBUG("\r\nOAM-MOBILE: ----- circuit call -----\r\n");
		   pid = fork();
		   if (pid < 0)
		   {
			   XDEBUG("fork: fork error!!\r\n");
			   break;
		   }
   	 	   else if (pid == 0)
    	   {
               setsid();
		       GetFileValue("/app/conf/mobile.type", &nType);
			   execl("/app/sw/mserver", "mserver", (nType == MOBILE_TYPE_CDMA) ? "-cdma" : "-gsm", NULL);
        	   exit(0);
		   }
           waitpid(pid,NULL,0);
		   break;
#endif      // Include GPIO

	  case GPIONOTIFY_DCD :
		   pThis->m_Locker.Lock();
		   pThis->m_nDcdState = nState;
		   pThis->m_Locker.Unlock();

		   XDEBUG("MOBILE: ------ Carrier DCD=%0d (%s) ------\r\n", nState, nState == 1 ? "OFF" : "ACTIVE");

		   // DCD Off
		   if (nState == 1)
			   break;

		   // CDMA를 사용중인 경우
		   if (MOBILE_IsBusy())
			   break;

		   // CDMA인 경우에만 DCD 시그널을 이용한다.
		   // CDMA는 RI 시그널이 오지 않으므로 DCD 시그널만으로 동작한다. (M2M의 경우)
		   GetFileValue("/app/conf/mobile.type", &nType);
		   if (nType != MOBILE_TYPE_CDMA)
				break;

		   // Send data active
		   if (m_pSystemMonitor->GetCount() != 0)
		   {
			   XDEBUG("MOBILE: ------ Busy (Count) ------\r\n");
			   break;
		   }

		   // PPP is active
		   if (FindProcess("send") > 0)
		   {
			   XDEBUG("MOBILE: ------ SEND Active ------\r\n");
			   break;
		   }

		   // PPP is active
		   if (FindProcess("pppd") > 0)
		   {
			   XDEBUG("MOBILE: ------ PPP Active ------\r\n");
			   break;
		   }

		   XDEBUG("\r\nOAM-MOBILE: Answer a circuit call.\r\n");
		   pid = fork();
		   if (pid < 0)
		   {
			   XDEBUG("fork: fork error!!\r\n");
			   break;
		   }
   	 	   else if (pid == 0)
    	   {
               setsid();
			   execl("/app/sw/mserver", "mserver", (nType == MOBILE_TYPE_CDMA) ? "-cdma" : "-gsm", NULL);
        	   exit(0);
		   }
           waitpid(pid,NULL,0);
		   break;
#else       // __TI_AM335X__
      case GPIONOTIFY_BATT_ADC:
           pThis->m_nAdcBattVolt = nState;
           break;
      case GPIONOTIFY_MAIN_ADC:
           pThis->m_nAdcMainVolt = nState;
           break;
#endif      // End of Core
	}
}
nsresult
nsNetscapeProfileMigratorBase::CopyMailFolderPrefs(PBStructArray &aMailServers,
                                                   nsIPrefService* aPrefService)
{
  // Each server has a .directory pref which points to the location of the
  // mail data for that server. We need to do two things for that case...
  // (1) Fix up the directory path for the new profile
  // (2) copy the mail folder data from the source directory pref to the
  //     destination directory pref
  CopyFile(FILE_NAME_VIRTUALFOLDERS, FILE_NAME_VIRTUALFOLDERS);

  int32_t count = aMailServers.Length();
  for (int32_t i = 0; i < count; ++i) {
    PrefBranchStruct* pref = aMailServers.ElementAt(i);
    nsDependentCString prefName(pref->prefName);

    if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory"))) {
      // let's try to get a branch for this particular server to simplify things
      prefName.Cut(prefName.Length() - strlen("directory"),
                   strlen("directory"));
      prefName.Insert("mail.server.", 0);

      nsCOMPtr<nsIPrefBranch> serverBranch;
      aPrefService->GetBranch(prefName.get(), getter_AddRefs(serverBranch));

      if (!serverBranch)
        break; // should we clear out this server pref from aMailServers?

      nsCString serverType;
      serverBranch->GetCharPref("type", getter_Copies(serverType));

      nsCOMPtr<nsIFile> sourceMailFolder;
      nsresult rv = GetFileValue(serverBranch, "directory-rel", "directory",
                                 getter_AddRefs(sourceMailFolder));
      NS_ENSURE_SUCCESS(rv, rv);

      // now based on type, we need to build a new destination path for the
      // mail folders for this server
      nsCOMPtr<nsIFile> targetMailFolder;
      if (serverType.Equals("imap")) {
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(IMAP_MAIL_DIR_50_NAME);
      }
      else if (serverType.Equals("none") || serverType.Equals("pop3") ||
               serverType.Equals("movemail")) {
        // local folders and POP3 servers go under <profile>\Mail
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(MAIL_DIR_50_NAME);
      }
      else if (serverType.Equals("nntp")) {
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(NEWS_DIR_50_NAME);
      }

      if (targetMailFolder) {
        // for all of our server types, append the host name to the directory
        // as part of the new location
        nsCString hostName;
        serverBranch->GetCharPref("hostname", getter_Copies(hostName));
        targetMailFolder->Append(NS_ConvertASCIItoUTF16(hostName));

        // we should make sure the host name based directory we are going to
        // migrate the accounts into is unique. This protects against the
        // case where the user has multiple servers with the same host name.
        targetMailFolder->CreateUnique(nsIFile::DIRECTORY_TYPE, 0777);

        RecursiveCopy(sourceMailFolder, targetMailFolder);
        // now we want to make sure the actual directory pref that gets
        // transformed into the new profile's pref.js has the right file
        // location.
        nsAutoCString descriptorString;
        targetMailFolder->GetPersistentDescriptor(descriptorString);
        NS_Free(pref->stringValue);
        pref->stringValue = ToNewCString(descriptorString);
      }
    }
    else if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".newsrc.file"))) {
      // copy the news RC file into \News. this won't work if the user has
      // different newsrc files for each account I don't know what to do in
      // that situation.
      nsCOMPtr<nsIFile> targetNewsRCFile;
      mTargetProfile->Clone(getter_AddRefs(targetNewsRCFile));
      targetNewsRCFile->Append(NEWS_DIR_50_NAME);

      // turn the pref into a nsIFile
      nsCOMPtr<nsIFile> srcNewsRCFile =
        do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
      srcNewsRCFile->SetPersistentDescriptor(
        nsDependentCString(pref->stringValue));

      // now make the copy
      bool exists;
      srcNewsRCFile->Exists(&exists);
      if (exists) {
        nsAutoString leafName;
        srcNewsRCFile->GetLeafName(leafName);
        // will fail if we've already copied a newsrc file here
        srcNewsRCFile->CopyTo(targetNewsRCFile,leafName);
        targetNewsRCFile->Append(leafName);

        // now write out the new descriptor
        nsAutoCString descriptorString;
        targetNewsRCFile->GetPersistentDescriptor(descriptorString);
        NS_Free(pref->stringValue);
        pref->stringValue = ToNewCString(descriptorString);
      }
    }
  }

  // Remove all .directory-rel prefs as those might have changed; MailNews
  // will create those prefs again on first use
  for (int32_t i = count; i-- > 0; ) {
    PrefBranchStruct* pref = aMailServers.ElementAt(i);
    nsDependentCString prefName(pref->prefName);

    if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory-rel"))) {
      if (pref->type == nsIPrefBranch::PREF_STRING)
        NS_Free(pref->stringValue);

      aMailServers.RemoveElementAt(i);
    }
  }

  return NS_OK;
}