Re: [os-libsynthesis] os-libsynthesis Digest, Vol 33, Issue 9

2012-03-31 Thread Lukas Zeller
Hi Zhoulei,

On Mar 31, 2012, at 11:12 , zhou lei wrote:

> I try to modify "ReadItemAsKey". Using SetValue to set the contacts, and i 
> just guess that "read" mean read the local contacts and send them to server.

Exactly. The terms in the plugin are all meant towards the database.

> But with the struct fCB in the sample_dbplugin1.mm, just get a error named 
> "EXC_BAD_ACCESS". And I use it like this "fCB->ui.SetValue( &fCB, aItemKey, 
> "N_FIRST" ,VALTYPE_TEXT, "123131" , strlen("123131")); ", the fCB was set 
> when init the "SamplePluginDB1". 

I would really discourage using a mixture of ObjC and parts from the C++ 
examples. The ObjC wrapper was done exactly because dealing with the fCB and 
it's members directly is difficult, and you need to do all the memory 
management on your own.

EXC_BAD_ACCESS is a bus error which is hard to debug, especially as two 
completely different memory management systems need to cooperate here (ObjC 
refcounted world with C++/C traditional malloc/free world).

The ObjC wrapper classes however are really simple to use from the ObjC world.

I made a skeleton for the two read* methods to show how to easily access fields 
from ObjC, without any messing with fCB, and with automatic conversion from 
NSString (the SettingsKey also gives you convenience methods to access dates as 
NSDate and integers).


- (TSyError)readNextItemAsKey:(SettingsKey *)aItemKey
  itemIdP:(NSString **)aItemIdP parentIdP:(NSString **)aParentIdP
  statusP:(sInt32 *)aStatusP
  isFirst:(BOOL)aFirst
{
  TSyError sta = LOCERR_OK;

  [self debugOut:[NSString stringWithFormat:@"readNextItemAsKey: aFirst=%d", 
aFirst]];
  // read next item from DB
  if (aFirst) {
// %%% reset iterator over dataset here
  }
  // get next item
  BOOL found = NO;
  do {
if (/* %%% no more data items */) {
  *aStatusP = ReadNextItem_EOF;
  break;
}
else {
  found = YES;
  // %%% get IDs of records from the database
  // Note: data is not required at this point, however, if the database 
is such
  //   that it always reads the data anyway when getting the IDs, 
the data
  //   CAN be OPTIONALLY read here already (see below)

  NSString *localID = /*  item ID as string */ @"dummyID";
  *aItemIdP = localID;

  // %%% find out if it has modified since last time
  if (/* %%% modified since last suspend */)
*aStatusP = ReadNextItem_Resumed; // changed since last resume (implies 
changed since last sync also)
  else if (/* %%% modified since last completed sync session */)
*aStatusP = ReadNextItem_Changed; // changed since last sync (but NOT 
since last resume)
  else
*aStatusP = ReadNextItem_Unchanged; // not changed, but caller wants to 
see all records


  // %%% optionally, you can ready actual item data from the DB here and 
return it. If you don't deliver
  // data here, the engine will later call readItemAsKey to get the data

  // %%% just set some sample properties
  // - simple strings
  [aItemKey setStringValueByName:"N_FIRST" toValue:/* dummy first name */ 
@"Theodor"];
  [aItemKey setStringValueByName:"N_LAST" toValue:/* dummy last name */ 
@"Tester"];

  // - strings in an array
  sInt32 telFieldID = [aItemKey valueIDByName:"TEL"];
  for (int i=0; i<3; i++) {
[aItemKey setStringValueByID:telFieldID arrayIndex:i toValue:/* dummy 
TEL */ @"12345 78 90"];
  }

  // %%% advance iterator to next item (such that next item will be 
delivered on next call to reasNextItemAsKey
}
  } while (!found);
  // done
  return sta;
}




- (TSyError)readItemAsKey:(SettingsKey *)aItemKey
  itemID:(NSString *)aItemID parentID:(NSString *)aParentID
{
  TSyError sta = LOCERR_OK;

  [self debugOut:[NSString stringWithFormat:
@"readItemAsKey: itemID=%@ parentID=%@",
aItemID, aParentID
  ]];

  // %%% read item identified by NSString in aItemID from DB

  if (/* %%% found item with ID aItemID*/) {

// %%% just set some sample properties
// - simple strings
[aItemKey setStringValueByName:"N_FIRST" toValue:/* dummy first name */ 
@"Theodor"];
[aItemKey setStringValueByName:"N_LAST" toValue:/* dummy last name */ 
@"Tester"];

// - strings in an array
sInt32 telFieldID = [aItemKey valueIDByName:"TEL"];
for (int i=0; i<3; i++) {
  [aItemKey setStringValueByID:telFieldID arrayIndex:i toValue:/* dummy TEL 
*/ @"12345 78 90"];
}

  }
  else {
// item not found
sta = DB_NotFound;
  }
  // done
  return sta;
}



Best Regards,

Lukas

PS: please make sure to Cc: your replies to the mailing list (Synthesis 
) as well, and not only to me, so everyone on the 
list can follow the conversation.
___
os-libsynthesis mailing list
os-libsynthesis@synthesis.ch
http://lists.synthesis.ch/mailman/listinfo/os-libsynthesis


[os-libsynthesis] The sync works now. But some other problems about the set value.

2012-03-31 Thread zhou lei
Hi, Lukas

I just try it as what to told me to do, and the client works. Thank you
very much.

For property "TEL" in the vcard, it just has too many enum values, how
could i set the "TEL" value with its enum flags. If only set it by the
setstringvaluebyname, It may use the default one, but i want to set it
myself.

Thanks
Best Regards
-Zhoulei
___
os-libsynthesis mailing list
os-libsynthesis@synthesis.ch
http://lists.synthesis.ch/mailman/listinfo/os-libsynthesis