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


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

2012-03-29 Thread Lukas Zeller
Hi Zhoulei,

On Mar 29, 2012, at 5:45 , zhou lei wrote:

> In the configure XML file, I set the datastore name to "contacts" which is 
> named "test_contacts" before. And in it, change the displayname to 
> "contacts", set the plugin_module to "iPhone_dbplugin1" which is named 
> "SDK_textdb". Is that correct?

That's correct. However, I tried it myself and as you found, there's still that 
Error 20010, which means that something is wrong in the XML config.
Unfortunately, the sample app did not output the config error messages to the 
console as it should have. I fixed this, please see the lastest commit in the 
luz branch on gitorious (the config variable "conferrpath" must be set to 
"console"). With this, the XCode debug console shows what is the problem:

 Fatal: Module does not understand params passed in 

This is because the sample uses the  , which is 
specific to the SDK_textdb plugin, and is not understood by the dummy plugins. 
So just comment out or remove the entire , and the sync engine 
will initialize correctly.

In the same commit, I also added a line to enable syncml engine logs to 
tmp/sysynclogs for DEBUG builds, so it is easier to get started with the sample 
and see what the SyncML engine is doing.

> When i using the sqlite, i found out that there is no place to set the key 
> "prefs_path",

The prefs_path just returns the default directory for the platform to store 
preferences, so you can use it in the XML config or your app to avoid 
hard-coded paths. 

> and in the sdk document, so should i set it as a defout path to create a 
> SQLite db file?

You just need to set the  to a path where your SQLite database is. 
You could use the $(prefs_path) variable to specifiy that path relative to the 
default preferences location, but you can also use a absolute path. The 
SyncMLClient class defines a config variable called $(sandbox) to contain the 
App's sandbox directory, because that's usually the starting point you need.

So usually you would define the SQLlite file like:

  $(sandbox)/Library/mydatafile.sqlitedb

> And is there any document for the SQL columns'name for sync. There are too 
> many columns in the sunbird_client.xml, like "id" "recurrence_id" 
> last_modified. Is there a really demo, that could work with contacts?

The entire point in libsynthesis is that you can adapt it to your own databases.
If the sync should be with one of the iOS built-in data sources, there are the 
(quite complex) commerical plugins for iOS contacts and iOS calendar.

If you want to design your own address book, it's up to you to design an 
alternate address book database.

> This demo is hardly to read. And may takes a long time to understand what you 
> really want to show to us.

Sync is complex - there's no easy way. SyncML sync is also a niche, and the iOS 
opensourcing is quite new. I admit that there's no good tutorial yet, but then, 
this is OpenSource and anyone is welcome to contribute more samples and docs. 
If I had to write step by step tutorials myself before opensourcing it, 
libsynthesis wouldn't be opensource yet. What I'm providing is 10 years of 
condensed SyncML knowhow, in a library that hides a huge amount of complexity 
from the user, but still admittedly remains non-trivial, and thus needs some 
diggin in to learn.

> Maybe it is easy for you guys to write out a dbplugin or something else, but 
> one guy should know how to set configure xml file, should know how to write a 
> dbplugin, and how to make it runs in the right way, and when it goes wrong he 
> should know where is wrong. Don't know why you guys don't give a demo that 
> could really work on ios, and can do a sync, even for only one contacts or 
> other things.

The demo as provided does work on iOS, and as you see I try to improve it to 
make it more accessible and easier to modify. However, I do this unpaid, and 
writing all that you seem to expect to just be there would take a lot of time. 
Opensource works by everyone contributing to a project what he or she thinks is 
missing, not by one party providing everything for everyone else to use for 
free.



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


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

2012-03-28 Thread Lukas Zeller
Hello,

On Mar 28, 2012, at 5:47 , zhou lei wrote:

> If the google sync is not the good one,  which sync server would be better?

It depends on what you want to do. Of course, if you need to get Google 
contacts, there's no choice. But otherwise, there are many services and 
software that support SyncML - have a look at the wikipedia article for a 
extensive list: SyncML Wikipedia article

> If i set the plugin_module to "iPhone_dbplugin1" the client get a 20010 error 
> code.why?

20010 is a XML parsing error (see doc/SySync_config_reference.pdf, page 200). 

> You told me that just modify the code in the sample_dbplugin1.mm.,like 
> "readItemAsKey". But I found out that, the functions would never been called 
> in the class of "SamplePluginDB1", even the class "SamplePluginDB1" never 
> init by the engine.

Probably because of the XML error, the engine never gets as far to instantiate 
the plugins.

Best Regards,

Lukas Zeller, plan44.ch
l...@plan44.ch - www.plan44.ch


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


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

2012-03-27 Thread zhou lei
Hi, Lukas

If the google sync is not the good one,  which sync server would be better?
If i set the plugin_module to "iPhone_dbplugin1" the client get a 20010
error code.why?
You told me that just modify the code in the sample_dbplugin1.mm.,like "
readItemAsKey". But I found out that, the functions would never been called
in the class of "SamplePluginDB1", even the class "SamplePluginDB1" never
init by the engine.

Thanks
Regards
-Zhoulei

2012/3/23 

> Send os-libsynthesis mailing list submissions to
>os-libsynthesis@synthesis.ch
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://lists.synthesis.ch/mailman/listinfo/os-libsynthesis
> or, via email, send a message with subject or body 'help' to
>os-libsynthesis-requ...@synthesis.ch
>
> You can reach the person managing the list at
>os-libsynthesis-ow...@synthesis.ch
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of os-libsynthesis digest..."
>
>
> Today's Topics:
>
>   1. Re: what's deference between dbplugin for cocoa   and for cpp
>  (Lukas Zeller)
>   2. Re: os-libsynthesis Digest, Vol 33, Issue 6 (Lukas Zeller)
>
>
> --
>
> Message: 1
> Date: Thu, 22 Mar 2012 16:09:12 +0100
> From: Lukas Zeller 
> Subject: Re: [os-libsynthesis] what's deference between dbplugin for
>cocoa   and for cpp
> To: zhou lei 
> Cc: os-libsynthesis@synthesis.ch
> Message-ID: <30a570f1-3a3e-4ae7-85b9-8d75813ac...@plan44.ch>
> Content-Type: text/plain; charset=iso-8859-1
>
> Hi Zhoulei,
>
> On Mar 20, 2012, at 10:31 , zhou lei wrote:
>
> > We can find "snowwhite" in the doc of the libsynthesis, and in the file
> named "dbapi.cpp" we can find it too.
>
> This is the C++ branch of things, it is not relevant for iOS (except maybe
> for general understanding of how the library works on other platforms).
>
> > And from the demo for IOS, We can find out that, in cocoa, the lib would
> using the code in "dbplugin_cocoa.m".
>
> dbplugin_cocoa.m is the wrapper code that handles the somewhat tricky
> interface between C and ObjC for you. No need to edit this.
>
> The actual plugin code to write will go into sample_dbplugin1.mm(2,3,4...).
>
> All you need to do is implementing the following methods:
>
> - (TSyError)startDataReadWithLastToken:(cAppCharP)aLastToken
> andResumeToken:(cAppCharP)aResumeToken;
>
> - (TSyError)readNextItemAsKey:(SettingsKey *)aItemKey
>  itemIdP:(NSString **)aItemIdP parentIdP:(NSString **)aParentIdP
>  statusP:(sInt32 *)aStatusP
>  isFirst:(BOOL)aFirst;
>
> - (TSyError)readItemAsKey:(SettingsKey *)aItemKey
>  itemID:(NSString *)aItemID parentID:(NSString *)aParentID;
>
> - (TSyError)endDataRead;
>
> - (TSyError)startDataWrite;
>
> - (TSyError)insertItemAsKey:(SettingsKey *)aItemKey
>  parentID:(NSString *)aParentID newItemIdP:(NSString **)aNewItemIdP;
>
> - (TSyError)updateItemAsKey:(SettingsKey *)aItemKey
>  itemIdP:(NSString **)aItemIdP parentIdP:(NSString **)aParentIdP;
>
> - (TSyError)deleteItem:(NSString *)aItemID parentID:(NSString *)aParentID;
>
> - (TSyError)endDataWriteWithSuccess:(BOOL)aSuccess andNewToken:(NSString
> **)aNewTokenP;
>
> ...plus maybe some of the optional methods if you have advanced features
> like filtering (but probably not to start with).
>
> These are semantically 1:1 representations in ObjC of the functions you
> find described in more detail in doc/SDK_manual.pdf and also in the C++
> samples. Because of the work the wrapper code does for you, it is only a
> small subset of what the C plugin ABI consists of. Things like module/db
> context creation/deletion is done in the wrapper.
>
> One important note: the Cocoa wrapper code only uses the "AsKey" variants
> from the plugin API. This means that rather than passing items as text
> strings, a SettingsKey object is passed, on which you can call methods like
> stringValueByName: / setStringValueByName:toValue: to access individual
> fields (see SettingsKey.h for all available access methods). Note that this
> is the same mechanism as for accessing settings, and you'll find examples
> for SettingsKey usage in the sample iOS app.
>
> Best Regards,
>
> Lukas Zeller, plan44.ch
> l...@plan44.ch - www.plan44.ch
>
>
>
>
> --
>
> Message: 2
> Date: Thu, 22 Mar 2012 16:11:40 +0100
> From: Lukas Zeller 
> Subject: Re: [os-libsynthesis] os-libsynthesis Digest, Vol 33, Issue 6
> To: zhou lei 
> Cc: os-libsynthesis@synthesis.ch
> Message-ID: <0229f62b-bca6-4498-a527-fb99cdb31...@plan44.ch>
> Content-Type: text/plain; charset=iso-8859-1
>
> Hi Zhoulei,
>
> On Mar 19, 2012, at 3:57 , zhou lei wrote:
>
> > In my satuation, I  want to sync the address book from the iphone to the
> sync server, and when needed the client would update the address book from
> the server. And for now, I just want to make the client works, and would
> using the syncML server of the google sync.
>
> Be careful and don't ex