Esempio n. 1
0
void* sync_engine_main_routine(void* data) {
	
	printf("Starting sync engine main routine...\n");
	delay_sync = get_object_count_from_database(database);
	pthread_mutex_lock(&sync_mutex);
	while(!stop_running) {
		struct timespec   ts;
		struct timeval    tp;
		gettimeofday(&tp, NULL);
		/* Convert from timeval to timespec */
		ts.tv_sec  = tp.tv_sec;
		ts.tv_nsec = tp.tv_usec * 1000;
		ts.tv_sec += WAIT_TIME_SECONDS;
		
		printf("Sync engine blocked for %d seconds...\n",WAIT_TIME_SECONDS);
		pthread_cond_timedwait(&sync_cond, &sync_mutex, &ts);
		printf("Sync engine continues w/ current operations...\n");
	
		if(!delay_sync) {
			if(process_local_changes()) {
				break;
			}
		} else {
			delay_sync = 0;
		}

	}
	pthread_mutex_unlock(&sync_mutex);
	
    return NULL;
}
Esempio n. 2
0
bool CSyncEngine::StartSyncEngine()
{
  ATLTRACE(_T("Starting sync engine\n"));
  char dbpath[MAX_PATH];
  sprintf(dbpath,"%sdb\\syncdb.sqlite",RhoGetRootPath());

  Lock();
  sqlite3_open(dbpath,&m_database);
  Unlock();

  // Set the delay based on records from the database
  m_delaySync = get_object_count_from_database(m_database);
  start_sync_engine(m_database);
  m_bSyncInitialized = true;
  stop_running = 0;

  return true;
}