Changeset 3300
- Timestamp:
- 04/27/08 15:52:30 (5 months ago)
- Files:
-
- plugins/gnokii-sync/src/gnokii_calendar.c (modified) (11 diffs)
- plugins/gnokii-sync/src/gnokii_contact.c (modified) (8 diffs)
- plugins/gnokii-sync/src/gnokii_sync.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/gnokii-sync/src/gnokii_calendar.c
r3164 r3300 355 355 gnokii_environment *env = (gnokii_environment *) plugindata; 356 356 357 // reset reports internal hashtable list, to discover deleted entries358 osync_hashtable_reset_reports(sinkenv->hashtable);359 360 357 // check for slowsync and prepare the "event" hashtable if needed 361 358 if (osync_objtype_sink_get_slowsync(sink)) { … … 373 370 374 371 calnote = gnokii_calendar_get_calnote(i, caldata, env->state, error_note); 375 376 372 if (calnote == NULL) 377 373 break; 378 374 379 // prepare UID with gnokii-calendar-<memory location> 375 OSyncChange *change = osync_change_new(&error); 376 377 /* prepare UID with gnokii-calendar-<memory location> */ 380 378 uid = g_strdup_printf ("gnokii-calendar-%i", calnote->location); 381 osync_hashtable_report(sinkenv->hashtable, uid); 379 osync_change_set_uid(change, uid); 380 g_free(uid); 382 381 383 382 hash = gnokii_calendar_hash(calnote); 384 OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, uid, hash); 383 osync_change_set_hash(change, hash); 384 g_free(hash); 385 386 OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, change); 387 osync_change_set_changetype(change, type); 388 389 /* Once hash and uid is set to change object - report it! 390 Otherwise the hashtable will declare it as deleted. */ 391 //osync_hashtable_report(sinkenv->hashtable, change); 392 osync_hashtable_update_change(sinkenv->hashtable, change); 385 393 386 394 if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { 387 g_free(hash); 388 g_free(uid); 395 /* Nothing to do. */ 389 396 g_free(calnote); 390 397 continue; 391 398 } 392 399 393 osync_hashtable_update_hash(sinkenv->hashtable, type, uid, hash); 394 395 OSyncChange *change = osync_change_new(&error); 396 397 osync_change_set_uid(change, uid); 398 osync_change_set_hash(change, hash); 399 osync_change_set_changetype(change, type); 400 401 // set data 400 /* set data */ 402 401 osync_trace(TRACE_INTERNAL, "objformat: %p", sinkenv->objformat); 403 402 OSyncData *odata = osync_data_new((char *) calnote, sizeof(gn_calnote), sinkenv->objformat, &error); … … 406 405 osync_context_report_osyncwarning(ctx, error); 407 406 osync_error_unref(&error); 408 g_free(hash);409 g_free(uid);410 g_free(calnote);411 407 continue; 412 408 } … … 421 417 422 418 osync_change_unref(change); 423 424 g_free(hash); 425 g_free(uid); 419 g_free(calnote); 426 420 } 427 421 … … 429 423 430 424 assert(sinkenv->hashtable); 431 char **uids = osync_hashtable_get_deleted(sinkenv->hashtable);432 for ( i = 0; uids[i]; i++) {425 OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable); 426 for (u = uids; u; u = u->next) { 433 427 OSyncChange *change = osync_change_new(&error); 434 428 if (!change) { 435 g_free(uids[i]);436 429 osync_context_report_osyncwarning(ctx, error); 437 430 osync_error_unref(&error); … … 439 432 } 440 433 441 osync_change_set_uid(change, uids[i]); 434 const char *uid = u->data; 435 436 osync_change_set_uid(change, uid); 442 437 osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); 443 438 444 439 OSyncData *odata = osync_data_new(NULL, 0, sinkenv->objformat, &error); 445 440 if (!odata) { 446 g_free(uids[i]);447 441 osync_change_unref(change); 448 442 osync_context_report_osyncwarning(ctx, error); … … 455 449 osync_data_unref(odata); 456 450 451 osync_hashtable_update_change(sinkenv->hashtable, change); 452 457 453 osync_context_report_change(ctx, change); 458 454 459 osync_hashtable_update_hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), NULL);460 461 455 osync_change_unref(change); 462 g_free(uids[i]);463 456 } 464 g_free(uids);465 466 457 467 458 g_free(caldata); … … 538 529 539 530 /////////// WORKAROUND for "dirty" modify /////////// 540 /* 541 542 // fake a delete change to remove the old hash 543 OSyncChange *delete_change = osync_change_new(&error); 544 545 // the old uid will be set for this "fake" change 546 osync_change_set_uid(delete_change, osync_change_get_uid(change)); 547 osync_change_set_changetype(delete_change, OSYNC_CHANGE_TYPE_DELETED); 548 osync_hashtable_update_hash(sinkenv->hashtable, OSYNC_CHANGE_TYPE_DELETED, osync_change_get_uid(change), delete_change); 549 */ 550 551 osync_hashtable_delete(sinkenv->hashtable, osync_change_get_uid(change)); 531 osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); 532 osync_hashtable_update_change(sinkenv->hashtable, change); 552 533 553 534 // update the old UID with the followed UID for the hashtable … … 555 536 uid = gnokii_calendar_memory_uid(calnote->location); 556 537 osync_change_set_uid(change, uid); 557 538 g_free(uid); 558 539 559 540 // set modified changetype for calendar entry … … 563 544 hash = gnokii_calendar_hash(calnote); 564 545 osync_change_set_hash(change, hash); 565 566 osync_hashtable_write(sinkenv->hashtable, uid, hash);567 568 546 g_free(hash); 569 g_free(uid); 547 548 //osync_hashtable_update_change(sinkenv->hashtable, change); 570 549 571 550 /* … … 587 566 588 567 // update hashtable 589 osync_hashtable_update_ hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), osync_change_get_hash(change));568 osync_hashtable_update_change(sinkenv->hashtable, change); 590 569 591 570 osync_trace(TRACE_EXIT, "%s", __func__); plugins/gnokii-sync/src/gnokii_contact.c
r3164 r3300 398 398 osync_trace(TRACE_INTERNAL, "sinkenv: %p", sinkenv); 399 399 400 // reset reports internal hashtable list, to discover deleted entries401 osync_hashtable_reset_reports(sinkenv->hashtable);402 403 400 // check for slowsync and prepare the "contact" hashtable if needed 404 401 if (osync_objtype_sink_get_slowsync(sink)) { … … 459 456 continue; 460 457 461 // prepare UID with gnokii-contact-<memory type>-<memory location> 458 OSyncChange *change = osync_change_new(&error); 459 460 /* prepare UID with gnokii-contact-<memory type>-<memory location> */ 462 461 uid = gnokii_contact_uid(contact); 463 osync_hashtable_report(sinkenv->hashtable, uid); 464 462 osync_change_set_uid(change, uid); 463 g_free(uid); 464 465 /* set hash */ 465 466 hash = gnokii_contact_hash(contact); 466 OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, uid, hash); 467 osync_change_set_hash(change, hash); 468 g_free(hash); 469 470 /* Once UID and HASH got set - report it! */ 471 //osync_hashtable_report(sinkenv->hashtable, change); 472 473 OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, change); 474 osync_change_set_changetype(change, type); 475 476 osync_hashtable_update_change(sinkenv->hashtable, change); 467 477 468 478 if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { 469 g_free(hash); 470 g_free(uid); 479 /* Nothing to do. */ 471 480 g_free(contact); 472 481 continue; 473 482 } 474 483 475 osync_hashtable_update_hash(sinkenv->hashtable, type, uid, hash); 476 477 OSyncChange *change = osync_change_new(&error); 478 479 480 osync_change_set_uid(change, uid); 481 osync_change_set_hash(change, hash); 482 osync_change_set_changetype(change, type); 483 484 // set data 484 /* set data */ 485 485 osync_trace(TRACE_INTERNAL, "objformat: %p", sinkenv->objformat); 486 486 OSyncData *odata = osync_data_new((char *) contact, sizeof(gn_phonebook_entry), sinkenv->objformat, &error); … … 489 489 osync_context_report_osyncwarning(ctx, error); 490 490 osync_error_unref(&error); 491 g_free(hash);492 g_free(uid);493 g_free(contact);494 491 continue; 495 492 } … … 505 502 506 503 osync_change_unref(change); 507 508 g_free(hash);509 g_free(uid);510 504 } 511 505 } … … 514 508 515 509 int i; 516 char **uids = osync_hashtable_get_deleted(sinkenv->hashtable);517 for ( i = 0; uids[i]; i++) {510 OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable); 511 for (u = uids; u; u = u->next) { 518 512 OSyncChange *change = osync_change_new(&error); 519 513 if (!change) { 520 g_free(uids[i]);521 514 osync_context_report_osyncwarning(ctx, error); 522 515 osync_error_unref(&error); … … 524 517 } 525 518 526 osync_change_set_uid(change, uids[i]); 519 const char *uid = u->data; 520 521 osync_change_set_uid(change, uid); 527 522 osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); 528 523 529 524 OSyncData *odata = osync_data_new(NULL, 0, sinkenv->objformat, &error); 530 525 if (!odata) { 531 g_free(uids[i]);532 526 osync_change_unref(change); 533 527 osync_context_report_osyncwarning(ctx, error); … … 542 536 osync_context_report_change(ctx, change); 543 537 544 osync_hashtable_update_ hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), NULL);538 osync_hashtable_update_change(sinkenv->hashtable, change); 545 539 546 540 osync_change_unref(change); 547 g_free(uids[i]);548 541 } 549 g_free(uids);550 542 551 543 osync_context_report_success(ctx); … … 628 620 629 621 // update hashtable 630 osync_hashtable_update_ hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), osync_change_get_hash(change));622 osync_hashtable_update_change(sinkenv->hashtable, change); 631 623 632 624 plugins/gnokii-sync/src/gnokii_sync.c
r3068 r3300 29 29 // close the hashtable 30 30 if (sinkenv->hashtable) { 31 osync_hashtable_ free(sinkenv->hashtable);31 osync_hashtable_unref(sinkenv->hashtable); 32 32 } 33 33 … … 82 82 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data, info, ctx); 83 83 84 // gnokii_environment *env = (gnokii_environment *) data; 85 86 // forget reported changes 87 // osync_hashtable_forget(env->hashtable); 84 OSyncError *error = NULL; 85 86 //gnokii_environment *env = (gnokii_environment *) data; 87 OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 88 gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); 89 90 // commit changes to persistent hahstable 91 if (!osync_hashtable_save(sinkenv->hashtable, &error)) 92 goto error; 88 93 89 94 // answer the call … … 91 96 92 97 osync_trace(TRACE_EXIT, "%s", __func__); 98 return; 99 100 error: 101 osync_context_report_osyncerror(ctx, error); 102 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); 103 osync_error_unref(&error); 93 104 } 94 105 … … 105 116 if (!gnokii_comm_disconnect(env->state)) { 106 117 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "disconnect failed"); 107 free_gnokiienv(env);108 118 return; 109 119 } … … 123 133 // free everything 124 134 free_gnokiienv(env); 125 126 135 127 136 osync_trace(TRACE_EXIT, "%s", __func__); … … 222 231 contact_sinkenv->hashtable = osync_hashtable_new(tablepath, "contact", error); 223 232 224 //TODO: throw error. 225 //if (!contact_sinkenv->hashtable) 226 // goto error; 227 233 if (!contact_sinkenv->hashtable) 234 goto error; 235 236 if (!osync_hashtable_load(contact_sinkenv->hashtable, error)) 237 goto error; 228 238 229 239 // init the event sink … … 246 256 event_sinkenv->hashtable = osync_hashtable_new(tablepath, "event", error); 247 257 258 if (!event_sinkenv->hashtable) 259 goto error; 260 261 if (!osync_hashtable_load(event_sinkenv->hashtable, error)) 262 goto error; 263 248 264 env->sinks = g_list_append(env->sinks, event_sinkenv); 249 265 … … 257 273 258 274 return (void *)env; 275 276 error: 277 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 278 return NULL; 259 279 } 260 280
