예제 #1
0
void check_mapping(OSyncMappingTable *maptable, int memberid, int mappingid, unsigned int numentries, const char *uid)
{
	unsigned int i = 0;
	osync_trace(TRACE_ENTRY, "%s(%p, %i, %i, %i, %s)", __func__, maptable, memberid, mappingid, numentries, uid);
	
	for (i = 0; i < osync_mapping_table_num_mappings(maptable); i++) {
		OSyncMapping *mapping = osync_mapping_table_nth_mapping(maptable, i);
		OSyncMappingEntry *testentry = osync_mapping_find_entry_by_member_id(mapping, memberid);
		if (testentry) {
			if ((mappingid != -1 && osync_mapping_get_id(mapping) == mappingid) || (mappingid == -1 && !strcmp(osync_mapping_entry_get_uid(testentry), uid))) {
				unsigned int n = 0;
				fail_unless(osync_mapping_num_entries(mapping) == numentries);
				for (n = 0; n < osync_mapping_num_entries(mapping); n++) {
					OSyncMappingEntry *entry = osync_mapping_nth_entry(mapping, n);
					if (osync_mapping_entry_get_member_id(entry) == memberid) {
						fail_unless(!strcmp(osync_mapping_entry_get_uid(entry), uid), NULL);
						goto out;
					}
				}
				fail(NULL);
			}
		}
	}
	fail(NULL);

out:
	osync_trace(TRACE_EXIT, "%s", __func__);
}
예제 #2
0
OSyncMappingTable *mappingtable_load(const char *path, const char *objtype, unsigned int num_mappings)
{
	OSyncError *error = NULL;
	OSyncMappingTable *table = NULL;
	OSyncArchive *archive = NULL;

	osync_trace(TRACE_ENTRY, "%s(%s, %s, %i)", __func__, path, objtype, num_mappings);
	
	table = osync_mapping_table_new(&error);
	fail_unless(table != NULL, NULL);
	fail_unless(error == NULL, NULL);
	
	archive = osync_archive_new(path, &error);
	fail_unless(archive != NULL, NULL);
	fail_unless(error == NULL, NULL);
	
	fail_unless(osync_mapping_table_load(table, archive, objtype, &error), NULL);
	fail_unless(error == NULL, NULL);
	
	osync_archive_unref(archive);
	
	fail_unless(osync_mapping_table_num_mappings(table) == num_mappings, NULL);
	
	osync_trace(TRACE_EXIT, "%s: %p", __func__, table);
	return table;
}
osync_bool osync_obj_engine_initialize(OSyncObjEngine *engine, OSyncError **error)
{
  const char *objtype = NULL;
  int num = 0;
  int i = 0;

  osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, engine, error);

  osync_trace(TRACE_INTERNAL, "Loaded %i mappings", osync_mapping_table_num_mappings(engine->mapping_table));

  objtype = osync_obj_engine_get_objtype(engine);
	
  num = osync_engine_num_proxies(engine->parent);
  for (i = 0; i < num; i++) {
    OSyncClientProxy *proxy = osync_engine_nth_proxy(engine->parent, i);
    OSyncObjTypeSink *sink = osync_client_proxy_find_objtype_sink(proxy, objtype);
    OSyncSinkEngine *sinkengine = NULL; 
    if (!sink) {
      /* "data" sink engine counts also as valid. */
      sink = osync_client_proxy_find_objtype_sink(proxy, "data"); 
      if (!sink)
        continue;
    }
		
    sinkengine = osync_sink_engine_new(i, proxy, engine, error);
    if (!sinkengine)
      goto error;
		
    engine->sink_engines = g_list_append(engine->sink_engines, sinkengine);
  }

  if (engine->archive && engine->slowsync) {
    if (!osync_mapping_table_flush(engine->mapping_table, engine->archive, engine->objtype, error))
      goto error;
  }

  if (engine->archive) {
    if (!osync_mapping_table_load(engine->mapping_table, engine->archive, engine->objtype, error))
      goto error;
  }

  if (!_create_mapping_engines(engine, error))
    goto error;
	
  osync_trace(TRACE_INTERNAL, "Created %i mapping engine", g_list_length(engine->mapping_engines));

  if (engine->archive) {
    /* inject ignored conflicts from previous syncs */
    if (!_inject_changelog_entries(engine, error))
      goto error;
  }

  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;
 error:

  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return FALSE;
}
static osync_bool _create_mapping_engines(OSyncObjEngine *engine, OSyncError **error)
{
  int i = 0;
  osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, engine, error);
	
  for (i = 0; i < osync_mapping_table_num_mappings(engine->mapping_table); i++) {
    OSyncMapping *mapping = osync_mapping_table_nth_mapping(engine->mapping_table, i);
		
    OSyncMappingEngine *mapping_engine = osync_mapping_engine_new(engine, mapping, error);
    if (!mapping_engine)
      goto error;
		
    engine->mapping_engines = g_list_append(engine->mapping_engines, mapping_engine);
  }
	
  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;

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