Beispiel #1
0
void conflict_handler_ignore(OSyncEngine *engine, OSyncMappingEngine *mapping, void *user_data)
{
	OSyncError *error = NULL;
	num_mapping_conflicts++;
	if (user_data)
		fail_unless(osync_mapping_engine_num_changes(mapping) == GPOINTER_TO_UINT(user_data), NULL);
	fail_unless(num_engine_end_conflicts == 0, NULL);
	
	osync_engine_mapping_ignore_conflict(engine, mapping, &error);
	fail_unless(error == NULL, NULL);
}
Beispiel #2
0
void conflict_handler_delay(OSyncEngine *engine, OSyncMappingEngine *mapping, void *user_data)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, engine, mapping, user_data);
	
	num_mapping_conflicts++;
	if (user_data)
		fail_unless(osync_mapping_engine_num_changes(mapping) == GPOINTER_TO_UINT(user_data), NULL);
	fail_unless(num_engine_end_conflicts == 0, NULL);
	gengine = engine;
	g_thread_create ((GThreadFunc)solve_conflict, mapping, TRUE, NULL);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
}
Beispiel #3
0
void conflict_handler_abort(OSyncEngine *engine, OSyncMappingEngine *mapping, void *user_data)
{
	OSyncError *error = NULL;
	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, engine, mapping, user_data);
	
	if (user_data)
		fail_unless(osync_mapping_engine_num_changes(mapping) == GPOINTER_TO_UINT(user_data), NULL);
	fail_unless(num_engine_end_conflicts == 0, NULL);
	
	fail_unless(osync_engine_abort(engine, &error), NULL);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
}
Beispiel #4
0
void conflict_handler_choose_modified(OSyncEngine *engine, OSyncMappingEngine *mapping, void *user_data)
{
	OSyncError *error = NULL;
	unsigned int i;
	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, engine, mapping, user_data);

	num_mapping_conflicts++;
	if (user_data)
		fail_unless(osync_mapping_engine_num_changes(mapping) == GPOINTER_TO_UINT(user_data), NULL);
	fail_unless(num_engine_end_conflicts == 0, NULL);

	for (i = 0; i < osync_mapping_engine_num_changes(mapping); i++) {
		OSyncChange *change = osync_mapping_engine_nth_change(mapping, i);
		if (osync_change_get_changetype(change) == OSYNC_CHANGE_TYPE_MODIFIED) {
			osync_assert(osync_mapping_engine_solve(mapping, change, &error));
			osync_assert(error == NULL);
			osync_trace(TRACE_EXIT, "%s", __func__);
			return;
		}
	}
	fail("");
}
Beispiel #5
0
void conflict_handler_choose_first(OSyncEngine *engine, OSyncMappingEngine *mapping, void *user_data)
{
	OSyncChange *change = NULL;
	OSyncError *error = NULL;

	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, engine, mapping, user_data);
	
	num_mapping_conflicts++;
	if (user_data)
		fail_unless(osync_mapping_engine_num_changes(mapping) == GPOINTER_TO_UINT(user_data), NULL);
	fail_unless(num_engine_end_conflicts == 0, NULL);

	change = osync_mapping_engine_member_change(mapping, 1);
	osync_assert(osync_engine_mapping_solve(engine, mapping, change, &error));
	osync_assert(error == NULL);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
}
static OSyncMappingEntryEngine *_osync_mapping_engine_get_latest_entry(OSyncMappingEngine *engine, OSyncError **error)
{
  OSyncMappingEntryEngine *latest_entry = NULL; 
  OSyncChange *latest_change = NULL;
  time_t latest = 0;
  int i;

  osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, engine, error);
  osync_trace(TRACE_INTERNAL, "mapping number: %i", osync_mapping_engine_num_changes(engine));
  for (i=0; i < osync_mapping_engine_num_changes(engine); i++) {
    OSyncChange *change = osync_mapping_engine_nth_change(engine, i); 
    OSyncData *data = NULL;
    time_t cur = 0;

    if (osync_change_get_changetype(change) == OSYNC_CHANGE_TYPE_UNKNOWN)
      continue;

    data = osync_change_get_data(change);

    if (!osync_data_has_data(data))
      continue;

    cur = osync_data_get_revision(data, error);

    if (cur < 0)
      goto error;
		
    /* If there are several changes/entries having the
       same _and_ the latest revision -> don't declare
       a latest_change. Since it's not guranteed that those are
       equal, even with the _same_ revision.
    */
    if (cur == latest)
      latest_change = NULL;

    if (cur <= latest)
      continue;

    latest = cur;
    latest_change = change;
  }

  if (!latest_change) {
    osync_trace(TRACE_EXIT, "%s: Can't find the latest change.",
                __func__);
    return NULL;
  }

  latest_entry = _osync_mapping_engine_find_entry(engine, latest_change);

  if (!latest_entry) {
    osync_error_set(error, OSYNC_ERROR_GENERIC, "Can't find the latest entry of the latest change.");
    goto error;
  }

  osync_trace(TRACE_EXIT, "%s: %p", __func__, latest_entry);
  return latest_entry;

 error:
  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return NULL;
}