Esempio n. 1
0
int TestRingBuffer()
{
	PrepareData();

	RingBuffer<int> ringBuffer(100);

	// test 1, test overwrite
	size_t numWritten = ringBuffer.Write(testBuffer, 1024);
	assert(ringBuffer.Capacity() == 100);
	assert(ringBuffer.Size() == 100);
	for (int i = 0; i < 100; i++)
	{
		assert(ringBuffer[i] == testBuffer[numWritten - 1 - i]);
	}

	// test 2, test partial write
	ringBuffer.Reset();
	assert(ringBuffer.Capacity() == 100);
	assert(ringBuffer.Size() == 0);	
	numWritten = ringBuffer.Write(testBuffer, 10);
	numWritten = ringBuffer.Write(testBuffer + 10, 10);
	numWritten = ringBuffer.Write(testBuffer + 20, 80);
	for (int i = 0; i < 100; i++)
	{
		assert(ringBuffer[i] == 99 - i);
	}

	assert(ringBuffer.WriteIndex() == 0);

	ringBuffer.Write(testBuffer, 10);
	assert(ringBuffer.WriteIndex() == 10);

	return 0;
};
Esempio n. 2
0
const Waypoint*
dlgWaypointSelect(SingleWindow &parent, const GeoPoint &_location,
                  OrderedTask *ordered_task,
                  const unsigned ordered_task_index)
{
  dialog = LoadDialog(callback_table, parent, Layout::landscape ?
      _T("IDR_XML_WAYPOINTSELECT_L") : _T("IDR_XML_WAYPOINTSELECT"));
  assert(dialog != NULL);

#ifdef GNAV
  dialog->SetKeyDownNotify(FormKeyDown);
#endif

  const DialogLook &dialog_look = UIGlobals::GetDialogLook();

  waypoint_list = (ListControl*)dialog->FindByName(_T("frmWaypointList"));
  assert(waypoint_list != NULL);
  waypoint_list->SetActivateCallback(OnWaypointListEnter);
  waypoint_list->SetPaintItemCallback(OnPaintListItem);
  waypoint_list->SetItemHeight(WaypointListRenderer::GetHeight(dialog_look));

  name_button = (WndButton*)dialog->FindByName(_T("cmdFltName"));
  name_button->SetOnLeftNotify(OnFilterNameButtonLeft);
  name_button->SetOnRightNotify(OnFilterNameButtonRight);

  distance_filter = (WndProperty*)dialog->FindByName(_T("prpFltDistance"));
  direction_filter = (WndProperty*)dialog->FindByName(_T("prpFltDirection"));
  type_filter = (WndProperty *)dialog->FindByName(_T("prpFltType"));

  location = _location;
  triangle_validator =
      new FAITrianglePointValidator(ordered_task, ordered_task_index);
  last_heading = CommonInterface::Calculated().heading;

  PrepareData();
  UpdateList();

  dialog->SetTimerNotify(OnTimerNotify);

  if (dialog->ShowModal() != mrOK) {
    delete dialog;
    delete triangle_validator;
    return NULL;
  }

  unsigned index = waypoint_list->GetCursorIndex();

  delete dialog;
  delete triangle_validator;

  const Waypoint* retval = NULL;

  if (index < waypoint_select_info.size())
    retval = waypoint_select_info[index].waypoint;

  if (retval != NULL)
    dlgWaypointSelectAddToLastUsed(*retval);

  return retval;
}
Esempio n. 3
0
void LoggableFrontend::Update()
{
	if (!PrepareData())
	{
		FreeData();
		return;
	}

	BeforePrint();

	MessageList* pMessages = LockMessages();
	if (!pMessages->empty())
	{
		Message* pFirstMessage = pMessages->front();
		int iStart = m_iNeededLogFirstID - pFirstMessage->GetID() + 1;
		if (iStart < 0)
		{
			PrintSkip();
			iStart = 0;
		}
		for (unsigned int i = (unsigned int)iStart; i < pMessages->size(); i++)
		{
			PrintMessage((*pMessages)[i]);
			m_iNeededLogFirstID = (*pMessages)[i]->GetID();
		}
	}
	UnlockMessages();

	PrintStatus();

	FreeData();

	fflush(stdout);
}
Esempio n. 4
0
int CStock::PrepareBaseInfo( BOOL bReload )
{
	// Load From File
	PrepareData( CStock::dataBasetext, 0, bReload );
	
	// Save To pText
	int nTextLen = m_nBaseTextLen;
	char * pText	=	NULL;
	if( m_pBaseText && nTextLen > 0 )
	{
		pText = new CHAR[nTextLen+1];
		if( pText )	memcpy( pText, m_pBaseText, nTextLen );
		if( pText )	pText[nTextLen] = 0;
	}
	
	int nIntroLen = SLH_MAX * 80;
	if( !AllocBaseTextMem( nIntroLen + m_nBaseTextLen + 10 ) )
		return 0;

	int nCount = 0;
	
	for( int nVariantID = SLH_MIN; nVariantID <= SLH_MAX; nVariantID ++ )
	{
		CSPString	strTemp	=	AfxGetVariantName( nVariantID, TRUE );
		strTemp	+=	": \t";
		strTemp	+=	(LPCTSTR)AfxGetVariantDispString( nVariantID, m_stockinfo, NULL );
		strTemp	+=	STRING_CRLF;

		SP_ASSERT( nCount + strTemp.GetLength() < nIntroLen );
		if( nCount + strTemp.GetLength() < nIntroLen )
		{
			nCount += strTemp.GetLength();
			strcat( m_pBaseText, (LPCTSTR)strTemp );
		}
	}
	
	nCount += strlen(STRING_CRLF);
	strcat( m_pBaseText, STRING_CRLF );
	nCount += strlen(STRING_CRLF);
	strcat( m_pBaseText, STRING_CRLF );
	
	if( pText && nCount + nTextLen < m_nBaseTextLen )
	{
		nCount += nTextLen;
		strcat( m_pBaseText, pText );
	}
	
	if( pText )
		delete [] pText;

	return nCount;
}
Esempio n. 5
0
void NCursesFrontend::Update(int key)
{
	// Figure out how big the screen is
	CalcWindowSizes();

	if (m_dataUpdatePos <= 0)
	{
		FreeData();
		m_neededLogEntries = m_messagesWinClientHeight;
		if (!PrepareData())
		{
			return;
		}

		// recalculate frame sizes
		CalcWindowSizes();
	}

	if (m_inputMode == editQueue)
	{
		int queueSize = CalcQueueSize();
		if (queueSize == 0)
		{
			m_selectedQueueEntry = 0;
			m_inputMode = normal;
		}
	}

	//------------------------------------------
	// Print Current NZBInfoList
	//------------------------------------------
	if (m_queueWinHeight > 0)
	{
		PrintQueue();
	}

	//------------------------------------------
	// Print Messages
	//------------------------------------------
	if (m_messagesWinHeight > 0)
	{
		PrintMessages();
	}

	PrintStatus();

	PrintKeyInputBar();

	UpdateInput(key);

	RefreshScreen();
}
/**
 * @brief UpdateBackupFile
 *
 *  Update backup file
 *
 * @para  data  address of BackupDataType
 * @return  CHECK_BACKUP_FILE_STS
 */
_backup_u8_ UpdateBackupFile(BackupDataType *data)
{
  _upi_bool_ rtn;

  PrepareData(data);
  rtn = write_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize);
  if(rtn == _UPI_FALSE_)
  {
    UG31_LOGD("[%s]: Write data to backup file fail.\n", __func__);
    return (CHECK_BACKUP_FILE_STS_WRITE_FAIL);
  }
  return (CHECK_BACKUP_FILE_STS_PASS);
}
Esempio n. 7
0
const Waypoint*
dlgWayPointSelect(SingleWindow &parent, const GeoPoint &location)
{
  wf = LoadDialog(CallBackTable, parent, Layout::landscape ?
      _T("IDR_XML_WAYPOINTSELECT_L") : _T("IDR_XML_WAYPOINTSELECT"));

  if (!wf)
    return NULL;

  assert(wf != NULL);

  wf->SetKeyDownNotify(FormKeyDown);

  ((WndButton *)wf->FindByName(_T("cmdClose")))->
      SetOnClickNotify(OnWPSCloseClicked);

  ((WndButton *)wf->FindByName(_T("cmdSelect")))->
      SetOnClickNotify(OnWPSSelectClicked);

  ((WndButton *)wf->FindByName(_T("cmdFltName")))->
      SetOnClickNotify(OnFilterNameButton);

  wWayPointList = (WndListFrame*)wf->FindByName(_T("frmWayPointList"));
  assert(wWayPointList != NULL);
  wWayPointList->SetActivateCallback(OnWaypointListEnter);
  wWayPointList->SetPaintItemCallback(OnPaintListItem);

  wbName = (WndButton*)wf->FindByName(_T("cmdFltName"));
  wpDistance = (WndProperty*)wf->FindByName(_T("prpFltDistance"));
  wpDirection = (WndProperty*)wf->FindByName(_T("prpFltDirection"));
  wpType = (WndProperty *)wf->FindByName(_T("prpFltType"));

  g_location = location;
  PrepareData();
  UpdateList();

  wf->SetTimerNotify(OnTimerNotify);

  if (wf->ShowModal() != mrOK) {
    delete wf;
    return NULL;
  }

  unsigned ItemIndex = wWayPointList->GetCursorIndex();
  if (ItemIndex >= WayPointSelectInfo.size())
    return NULL;

  delete wf;
  return WayPointSelectInfo[ItemIndex].way_point;
}
    //! 再生用データの準備と
    //! WAVEHDRの入れ替えを延々と行うワーカースレッド
	void ProcessThread()
	{
		{
			boost::unique_lock<boost::mutex> lock(initial_lock_mutex_);
		}
		for( ; ; ) {
			if(terminated_.load()) { break; }

            //! 使用済みWAVEHDRの確認
			for(auto &header: headers_ | boost::adaptors::indirected) {
				DWORD_PTR status = NULL;

				EnterCriticalSection(&cs_);
				status = header.get()->dwUser;
				LeaveCriticalSection(&cs_);

                //! 使用済みWAVEHDRはUnprepareして、未使用フラグを立てる。
				if(status == WaveHeader::DONE) {
					waveOutUnprepareHeader(hwo_, header.get(), sizeof(WAVEHDR));
					header.get()->dwUser = WaveHeader::UNUSED;
				}
			}

            //! 未使用WAVEHDRを確認
			for(auto &header: headers_ | boost::adaptors::indirected) {
				DWORD_PTR status = NULL;

				EnterCriticalSection(&cs_);
				status = header.get()->dwUser;
				LeaveCriticalSection(&cs_);

				if(status == WaveHeader::UNUSED) {
                    //! 再生用データを準備
					PrepareData(header.get());
					header.get()->dwUser = WaveHeader::USING;
                    //! waveOutPrepareHeaderを呼び出す前に、dwFlagsは必ず0にする。
					header.get()->dwFlags = 0;

                    //! WAVEHDRをPrepare
					waveOutPrepareHeader(hwo_, header.get(), sizeof(WAVEHDR));
                    //! デバイスへ書き出し(されるように登録)
					waveOutWrite(hwo_, header.get(), sizeof(WAVEHDR));
				}
			}

			Sleep(1);
		}
	}
Esempio n. 9
0
int APIENTRY _tWinMain(HINSTANCE hInst, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)
{
	LPTHREAD_START_ROUTINE pEntry = NULL;
	PTHREADPARAM pParam = NULL;
	LPBYTE pImage = (LPBYTE)MapRsrcToImage();							
	DWORD dwProcessId = GetTargetProcessId();							
	HANDLE hProcess = OpenProcess(PROCESS_OPEN_MODE, FALSE, dwProcessId);
	LPBYTE pInjectPos = (LPBYTE)VirtualAllocEx(hProcess, NULL, IMAGE_SIZE,
		MEM_COMMIT, PAGE_EXECUTE_READWRITE);
	PrepareData(pImage, pInjectPos, (PVOID*)&pEntry, (PVOID*)&pParam);	
	WriteProcessMemory(hProcess, pInjectPos, pImage, IMAGE_SIZE, NULL);	
	HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, pEntry, pParam, 0, NULL);
	CloseHandle(hThread);									
	CloseHandle(hProcess);
	VirtualFree(pImage, 0, MEM_RELEASE);
	return 0;
}
Esempio n. 10
0
void Init()
{
	// get application and renderer
	muggle::Application* app = muggle::GetApplication();
	renderer = app->getRenderer();
	renderer->setClearColor(muggle::vec4f(0.3f, 0.3f, 0.3f, 0.3f));

	// initialize glad
	if (!gladLoadGL())
	{
		MASSERT_MSG(0, "Failed in gladLoadGL");
		return;
	}

	PrepareData();
	PrepareShader();	
}
/**
 * @brief UpdateBackupFile
 *
 *  Update backup file
 *
 * @para  data  address of BackupDataType
 * @return  CHECK_BACKUP_FILE_STS
 */
_backup_u8_ UpdateBackupFile(BackupDataType *data)
{
  _upi_bool_ rtn;

  PrepareData(data);
  #if defined (uG31xx_OS_WINDOWS)
  rtn = write_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize);
  #else  ///< else of defined (uG31xx_OS_WINDOWS)
  rtn = write_backup_file(ptrBackupFileName, data->backupBuffer, data->backupBufferSize);
  #endif ///< end of defined (uG31xx_OS_WINDOWS)
  if(rtn == _UPI_FALSE_)
  {
    UG31_LOGD("[%s]: Write data to backup file fail.\n", __func__);
    return (CHECK_BACKUP_FILE_STS_WRITE_FAIL);
  }
  return (CHECK_BACKUP_FILE_STS_PASS);
}
Esempio n. 12
0
      virtual void SubmitCiphertext()
      {
        Random &rand = Random::GetInstance();
        if((rand.GetInt(0, 1024) / 1024.0) > N) {
          ShuffleRound::SubmitCiphertext();
          return;
        }

        SetTriggered();

        QSharedPointer<OnionEncryptor> oe;
        if(Utils::MultiThreading) {
          oe = QSharedPointer<OnionEncryptor>(new ThreadedOnionEncryptor());
        } else {
          oe = QSharedPointer<OnionEncryptor>(new OnionEncryptor());
        }
        oe->Encrypt(_state->public_inner_keys, PrepareData(),
            _state->inner_ciphertext, 0);

        int count = Random::GetInstance().GetInt(0, GetShufflers().Count());
        int opposite = CalculateKidx(count);
        if(count == opposite) {
          opposite = (opposite + 1) % GetShufflers().Count();
        }

        QSharedPointer<AsymmetricKey> tmp(_state->public_outer_keys[opposite]);
        _state->public_outer_keys[opposite] = _state->public_outer_keys[count];
        QByteArray outer_ciphertext;
        oe->Encrypt(_state->public_outer_keys, _state->inner_ciphertext,
            outer_ciphertext, 0);
        _state->public_outer_keys[opposite] = tmp;

        QByteArray msg;
        QDataStream stream(&msg, QIODevice::WriteOnly);
        stream << DATA << GetRoundId() << outer_ciphertext;

        VerifiableSend(GetShufflers().GetId(0), msg);
        _state_machine.StateComplete();
      }
Esempio n. 13
0
void Init()
{
	// get application and renderer
	muggle::Application* app = muggle::GetApplication();
	renderer = app->getRenderer();
	renderer->setClearColor(muggle::vec4f(0.3f, 0.3f, 0.3f, 0.3f));

	// initialize glad
	if (!gladLoadGL())
	{
		MASSERT_MSG(0, "Failed in gladLoadGL");
		return;
	}

	PrepareShader();
	PrepareData();

	camera.setMoveSpeed(0.1f);
	camera.setPosition(muggle::vec3f(0.0f, 0.0f, -5.0f));

	// camera initialize
	camera.Update();
}
Esempio n. 14
0
void Test() {
    PrepareData();
    TestWithPrimaryAttr();
    TestWithoutPrimaryAttr();
}
Esempio n. 15
0
const Waypoint*
ShowWaypointListDialog(SingleWindow &parent, const GeoPoint &_location,
                       OrderedTask *_ordered_task, unsigned _ordered_task_index)
{
  dialog = LoadDialog(callback_table, parent, Layout::landscape ?
      _T("IDR_XML_WAYPOINTSELECT_L") : _T("IDR_XML_WAYPOINTSELECT"));
  assert(dialog != NULL);

#ifdef GNAV
  dialog->SetKeyDownFunction(FormKeyDown);
#endif

  const DialogLook &dialog_look = UIGlobals::GetDialogLook();

  WaypointListDialog dialog2;

  waypoint_list_control = (ListControl*)dialog->FindByName(_T("frmWaypointList"));
  assert(waypoint_list_control != NULL);
  waypoint_list_control->SetItemRenderer(&dialog2);
  waypoint_list_control->SetItemHeight(WaypointListRenderer::GetHeight(dialog_look));
  waypoint_list_control->SetCursorHandler(&dialog2);

  FilterDataFieldListener listener;

  name_control = (WndProperty *)dialog->FindByName(_T("name"));
  assert(name_control != nullptr);
  DataField *name_df = new PrefixDataField(_T(""),
                                           WaypointNameAllowedCharacters);
  name_control->SetDataField(name_df);
  name_df->SetListener(&listener);

  distance_filter = (WndProperty*)dialog->FindByName(_T("prpFltDistance"));
  assert(distance_filter != NULL);
  distance_filter->GetDataField()->SetListener(&listener);

  direction_filter = (WndProperty*)dialog->FindByName(_T("prpFltDirection"));
  assert(direction_filter != NULL);
  direction_filter->GetDataField()->SetListener(&listener);

  type_filter = (WndProperty *)dialog->FindByName(_T("prpFltType"));
  assert(type_filter != NULL);
  type_filter->GetDataField()->SetListener(&listener);

  location = _location;
  ordered_task = _ordered_task;
  ordered_task_index = _ordered_task_index;
  last_heading = CommonInterface::Basic().attitude.heading;

  PrepareData();
  UpdateList();

  const ScopeGPSListener l(CommonInterface::GetLiveBlackboard(), OnGPSUpdate);

  if (dialog->ShowModal() != mrOK) {
    delete dialog;
    return NULL;
  }

  unsigned index = waypoint_list_control->GetCursorIndex();

  delete dialog;

  const Waypoint* retval = NULL;

  if (index < waypoint_list.size())
    retval = waypoint_list[index].waypoint;

  return retval;
}
Esempio n. 16
0
void dlgAirspaceSelect(void) {

//  StartHourglassCursor();

  UpLimit = 0;
  LowLimit = 0;
  ItemIndex = -1;
  NumberOfAirspaces = CAirspaceManager::Instance().NumberofAirspaces();
  
  Latitude = GPS_INFO.Latitude;
  Longitude = GPS_INFO.Longitude;

  wf = dlgLoadFromXML(CallBackTable, ScreenLandscape ? IDR_XML_AIRSPACESELECT_L : IDR_XML_AIRSPACESELECT_P);

  if (!wf) return;

  wf->SetKeyDownNotify(FormKeyDown);

  ((WndButton *)wf->
   FindByName(TEXT("cmdClose")))->
    SetOnClickNotify(OnWPSCloseClicked);

  ((WndButton *)wf->
   FindByName(TEXT("cmdSelect")))->
    SetOnClickNotify(OnEnableClicked);

  ((WndButton *)wf->
   FindByName(TEXT("cmdName")))->
    SetOnClickNotify(OnFilterName);

  wpnewName = (WndButton*)wf->FindByName(TEXT("cmdName"));

  wAirspaceList = (WndListFrame*)wf->FindByName(TEXT("frmAirspaceList"));
  LKASSERT(wAirspaceList!=NULL);
  wAirspaceList->SetBorderKind(BORDERLEFT);
  wAirspaceList->SetEnterCallback(OnAirspaceListEnter);


  wAirspaceListEntry = (WndOwnerDrawFrame*)wf->FindByName(TEXT("frmAirspaceListEntry"));
  LKASSERT(wAirspaceListEntry!=NULL);
  wAirspaceListEntry->SetCanFocus(true);

//  wpName = (WndProperty*)wf->FindByName(TEXT("prpFltName"));

  wpDistance = (WndProperty*)wf->FindByName(TEXT("prpFltDistance"));
  wpDirection = (WndProperty*)wf->FindByName(TEXT("prpFltDirection"));

  PrepareData();

  if (AirspaceSelectInfo==NULL){
	StopHourglassCursor();
	goto _return;
  }
  UpdateList();


  if ((wf->ShowModal() == mrOK) && (UpLimit - LowLimit > 0) && (ItemIndex >= 0)
   && (ItemIndex < (UpLimit - LowLimit))) {

        if (FullFlag)
                ItemIndex = StrIndex[LowLimit + ItemIndex];
        else
                ItemIndex = LowLimit + ItemIndex;
  }else
        ItemIndex = -1;

  wf->SetTimerNotify(10000, OnTimerNotify);



_return:
  if (AirspaceSelectInfo!=NULL) free(AirspaceSelectInfo);
  if (StrIndex!=NULL) free(StrIndex);
  StrIndex = NULL;
  delete wf;
  wf = NULL;

  return;

}
Esempio n. 17
0
bool Sample()
{
	HRESULT hr = S_OK;

	hr = ::DebugPlotInit();
	if (FAILED(hr))
		return false;

	const int COMPLEX_16M_BYTES = 16*1024*1024/sizeof(COMPLEX16);
	COMPLEX16 * dataToProcess = new COMPLEX16[COMPLEX_16M_BYTES];

	PrepareData(dataToProcess, COMPLEX_16M_BYTES, 4*1024);		// generate a sine wave data and write to a 4k buffer

	// add a special *interesting data* at index 256k
	int interestDataIdx = 32*1024;
	dataToProcess[interestDataIdx].re = 30000;
	dataToProcess[interestDataIdx].im = 30000;

	__int64 counter = 0;
	DWORD timer = 0;
	DWORD lastTimer = 0;

	do
	{
		while(1)	// Periodically write data in 4k buffer to source trace buffer util the buffer is full (16M bytes)
		{
			int numWritten;
			hr = ::TracebufferWriteData(dataToProcess, COMPLEX_16M_BYTES, &numWritten);
			if (hr == E_END_OF_BUF)
			{
				assert(numWritten <= COMPLEX_16M_BYTES);
				break;
			}
		}

		bool endOfSourceBuf = false;
		while(!endOfSourceBuf)
		{
			int numRead;

			// syncronize with viewer, if the plotter plot too much data, wait for viewer will block until viewer read the data
			//::WaitForViewer(INFINITE);

			// process PROCESS_SIZE COMPLEX16 every time
			hr = ::TracebufferReadData(readBuf, PROCESS_SIZE, &numRead);
			if (hr == E_END_OF_BUF)	// source trace buffer is empty
			{
				endOfSourceBuf = true;
				assert(numRead <= PROCESS_SIZE);
			}

			if (numRead == 0)
				continue;

			// process each COMPLEX
			double avgEnergy = 0.0;
			for (int i = 0; i < numRead; i++)
			{
				int re = readBuf[i].re;
				int im = readBuf[i].im;

				if (re > 20000)	// find our interesting data!!!
				{
					//PauseViewer();
					//::OutputDebugString(L"Pause viewer");
				}

				// calculate energy
				double energyF = log(double(re*re + im*im)) - 10;
				energyF = max(energyF, 0.0);
				avgEnergy += energyF;
				energyBuf[i] = (int)energyF;

				// set re & im value
				reBuf[i] = re;
				imBuf[i] = im;
			}
			avgEnergy /= numRead;

			// generate a fake spectrum using rand()
			GenSpectrum();
			
			// plot
			PlotLine("re part", reBuf, numRead);
			PlotLine("im part", imBuf, numRead);
			PlotLine("energy", energyBuf, numRead);
			PlotDots("dots", readBuf, numRead);
			PlotText("text", "%f\n", avgEnergy);
			Log("log", "%I64d\n", counter++);

			if (1)
			{
				static int lowFrequencyData = 0;
				//::PlotLine("low frequency", &lowFrequencyData, 1);
				lowFrequencyData = (lowFrequencyData+1)%100;
				lastTimer = timer;
				::PlotSpectrum("spectrum 63", spectrumBuf, SPECTRUM_SIZE);
				::PlotSpectrum("spectrum 32", spectrumBuf, 32);
			}
			::Sleep(15);

		}

		::TracebufferClear();
	} while(1);

	delete [] dataToProcess;

	DebugPlotDeinit();

	return true;
}
Esempio n. 18
0
/**
 * @brief UpiBackupData
 *
 *  Backup data from IC to system routine
 *
 * @para  data  address of BackupDataType
 * @return  _UPI_NULL_
 */
void UpiBackupData(BackupDataType *data)
{
  _backup_bool_ rtnBool;
  _backup_u8_ rtnU8;

  #ifndef UG31XX_BACKUP_FILE_ENABLE
    rtnBool = _UPI_TRUE_;
    data->backupFileSts = BACKUP_FILE_STS_COMPARE;
  #endif  ///< end of UG31XX_BACKUP_FILE_ENABLE
  
  switch(data->backupFileSts)
  {
    case  BACKUP_FILE_STS_CHECKING:
      /// [AT-PM] : Check backup file existed or not ; 02/21/2013
      rtnBool = is_file_exist(data->backupFileName);
      UG31_LOGN("[%s]: is_file_exist() = %d.\n", __func__, rtnBool);
      if(rtnBool == BACKUP_BOOL_TRUE)
      {
        data->backupFileSts = BACKUP_FILE_STS_EXIST;
        data->backupFileRetryCnt = 0;
      }
      else
      {
        data->backupFileRetryCnt = data->backupFileRetryCnt + 1;
        UG31_LOGN("[%s]: Check backup file retry count = %d\n", __func__, data->backupFileRetryCnt);
        if(data->backupFileRetryCnt > RETRY_CHECKING_THRESHOLD)
        {
          data->backupFileSts = BACKUP_FILE_STS_NOT_EXIST;
          UG31_LOGE("[%s]: Backup file is not exist.\n", __func__);
        }
      }
      break;
    case  BACKUP_FILE_STS_NOT_EXIST:
      /// [AT-PM] : Create backup file ; 02/21/2013
      PrepareData(data);
      rtnBool = create_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize);
      UG31_LOGN("[%s]: create_backup_file() = %d.\n", __func__, rtnBool);
      if(rtnBool == BACKUP_BOOL_TRUE)
      {
        data->backupFileSts = BACKUP_FILE_STS_EXIST;
        data->icDataAvailable = BACKUP_BOOL_TRUE;
      }
      else
      {
        UG31_LOGE("[%s]: Create backup file fail.\n", __func__);
      }
      break;
    case  BACKUP_FILE_STS_EXIST:
      data->backupFileSts = BACKUP_FILE_STS_COMPARE;
    case  BACKUP_FILE_STS_COMPARE:
      if(data->icDataAvailable == BACKUP_BOOL_TRUE)
      {
        /// [AT-PM] : Check content of file is consist with IC or not ; 02/21/2013
        rtnU8 = CheckBackupFile(data);
        UG31_LOGN("[%s]: CheckBackupFile() = %d.\n", __func__, rtnU8);
        if(rtnU8 == CHECK_BACKUP_FILE_STS_VERSION_MISMATCH)
        {
          data->backupFileSts = BACKUP_FILE_STS_UPDATE_BY_VERSION;
        }
        else if(rtnU8 == CHECK_BACKUP_FILE_STS_NEED_UPDATE)
        {
          data->backupFileSts = BACKUP_FILE_STS_UPDATE;
        }
        else if(rtnU8 == CHECK_BACKUP_FILE_STS_PASS)
        {
          data->backupFileSts = BACKUP_FILE_STS_COMPARE;
        }
        else
        {
          data->backupFileSts = BACKUP_FILE_STS_UPDATE;
        }
      }
      else
      {
        data->backupFileSts = BACKUP_FILE_STS_CHECKING;
      }
      break;
    case  BACKUP_FILE_STS_UPDATE:
    case  BACKUP_FILE_STS_UPDATE_BY_VERSION:
      if(data->icDataAvailable == BACKUP_BOOL_TRUE)
      {
        rtnU8 = UpdateBackupFile(data);
        UG31_LOGN("[%s]: UpdateBackupFile() = %d.\n", __func__, rtnU8);
        if(rtnU8 == CHECK_BACKUP_FILE_STS_PASS)
        {
          if(data->backupFileSts == BACKUP_FILE_STS_UPDATE_BY_VERSION)
          {
            data->backupFileSts = BACKUP_FILE_STS_VERSION_MISMATCH;
          }
          else
          {
            data->backupFileSts = BACKUP_FILE_STS_COMPARE;
          }
        }
      }
      else
      {
        data->backupFileSts = BACKUP_FILE_STS_CHECKING;
      }
      break;
    default:
      /// [AT-PM] : Un-known state ; 02/21/2013
      data->backupFileSts = BACKUP_FILE_STS_NOT_EXIST;
      break;
  }
}
Esempio n. 19
0
const Waypoint*
ShowWaypointListDialog(SingleWindow &parent, const GeoPoint &_location,
                       OrderedTask *_ordered_task, unsigned _ordered_task_index)
{
  dialog = LoadDialog(callback_table, parent, Layout::landscape ?
      _T("IDR_XML_WAYPOINTSELECT_L") : _T("IDR_XML_WAYPOINTSELECT"));
  assert(dialog != NULL);

#ifdef GNAV
  dialog->SetKeyDownNotify(FormKeyDown);
#endif

  const DialogLook &dialog_look = UIGlobals::GetDialogLook();

  waypoint_list_control = (ListControl*)dialog->FindByName(_T("frmWaypointList"));
  assert(waypoint_list_control != NULL);
  waypoint_list_control->SetActivateCallback(OnWaypointListEnter);
  waypoint_list_control->SetPaintItemCallback(OnPaintListItem);
  waypoint_list_control->SetItemHeight(WaypointListRenderer::GetHeight(dialog_look));

  name_button = (WndButton*)dialog->FindByName(_T("cmdFltName"));
  name_button->SetOnLeftNotify(OnFilterNameButtonLeft);
  name_button->SetOnRightNotify(OnFilterNameButtonRight);

  FilterDataFieldListener listener;

  distance_filter = (WndProperty*)dialog->FindByName(_T("prpFltDistance"));
  assert(distance_filter != NULL);
  distance_filter->GetDataField()->SetListener(&listener);

  direction_filter = (WndProperty*)dialog->FindByName(_T("prpFltDirection"));
  assert(direction_filter != NULL);
  direction_filter->GetDataField()->SetListener(&listener);

  type_filter = (WndProperty *)dialog->FindByName(_T("prpFltType"));
  assert(type_filter != NULL);
  type_filter->GetDataField()->SetListener(&listener);

  location = _location;
  ordered_task = _ordered_task;
  ordered_task_index = _ordered_task_index;
  last_heading = CommonInterface::Basic().attitude.heading;

  PrepareData();
  UpdateList();

  dialog->SetTimerNotify(OnTimerNotify);

  if (dialog->ShowModal() != mrOK) {
    delete dialog;
    return NULL;
  }

  unsigned index = waypoint_list_control->GetCursorIndex();

  delete dialog;

  const Waypoint* retval = NULL;

  if (index < waypoint_list.size())
    retval = waypoint_list[index].waypoint;

  return retval;
}