External DataStores
[HotSync Services]


Detailed Description

External Datastores.

An external datastore is a datastore that uses its own ID and change system to track what records and objects have been added/modified/deleted. During a sync, the Hotsync Change Manager works on AlpLuids, which is incompatible with an external datastore's external IDs.

To allow external datastores to participate in a sync, the Change Manager reads external IDs that have been added/modified/deleted from the external datastore using the API alp_hsds_ext_get_change_info. The Change Manager then generates a corresponding AlpLuid for each external ID. These AlpLuids are then used as part of the sync process. The Change Manager maintains a mapping of these AlpLuids to external IDs so that it has a way of referring to the same external IDs during the sync and in subsequent syncs.

The Change Manager also records the modification status of each external ID received from alp_hsds_ext_get_change_info. Once all of the modifications have been recorded, the Change Manager calls alp_hsds_ext_clear_change_info, which signals the external datastore that all changes have been recorded.

These two calls occur at the beginning of sync, when the Sync Manager calls alp_hscm_prepare_for_sync, which gives the Change Manager a chance to perform extra preparation steps before the sync starts.

EXAMPLE: Consider a sample memo app called ExampleMemoApp. The ExampleMemoApp uses strings to identify each record, and integers to identify the change status. The memo ID strings are generated from an alphabet scheme. For example, the first memo would have an ID of "A", the second "B", and so on. The change status is a simple integer, so 0 means no modification, 1 added, 2 modified, 3 deleted. When the user adds a new memo to ExampleMemoApp, that new memo has an ID of "A" and a status of 1 (added).

At the beginning of a sync, the Sync Manager calls alp_hscm_prepare_for_sync, so that the Change Manager can a perform extra preparation steps before the sync starts. In this call, the Change Manager calls alp_hsds_ext_get_change_info, and the external datastore reports the ID "A", with a status of kObjectStateNew for its newly added memo.

The Change Manager generates an AlpLuid for "A", for example, 1000, and stores this mapping of "A" <-> 1000 internally. The AlpLuid of 1000 is used to represent the "A" memo for the rest of sync. The Change Manager then records that the AlpLuid of 1000 was a newly added object.

Since this is the only change reported by the external datastore, the Change Manager next calls alp_hsds_ext_clear_change_info. The external datastore then changes the status of the "A" memo to 0, because the added memo was properly recorded, and does not need to be reported to the Change Manager again until the user makes a modification.

This completes the alp_hscm_prepare_for_sync call made by the Sync Manager. The Sync Manager then proceeds with the sync procedure.

In a subsequent sync, if the Sync Manager detects that another app has modified the memo at AlpLuid 1000, the Sync Manager calls the Change Manager with the new memo and an AlpLuid of 1000. The Change Manager looks up 1000 in its internal table and finds "A" as the corresponding external ID. The Change Manager makes the call to alp_hsds_ext_replace, passing "A" as the external ID. The ExampleMemoApp can use "A" to find the exact memo to be modified and replace its current memo with the new memo. END EXAMPLE

Most of the external datastore's APIs are similar to the datastore APIs in hs_data_store.h. The main difference is that the external datastores are called with external IDs, instead of AlpLuids. Also, several addition APIs have been added to allow the external datastore to work with the Change Manager:

For grouping external datastore actions together into a transaction: alp_hsds_ext_begin_db_transaction, alp_hsds_ext_end_db_transaction, alp_hsds_ext_rollback_db_transaction

For allowing the Change Manager to read newly added/modified/deleted IDs from the external datastore: alp_hsds_ext_get_change_info, alp_hsds_ext_clear_change_info


Data Structures

struct  AlpHsExtChangesReportSet
 Contains an array of added/modified/deleted external IDs. More...

Functions

alp_status_t alp_hsds_ext_add (AlpHsDataStoreHandle hDs, AlpHsObjectTypePtr pSrcType, bool isReferenceable, AlpHsExternalID *pComponentExtIds, size_t componentExtIdSize, size_t offset, bool moreData, size_t bufSize, const _TCHAR *pBuf, AlpHsExternalID *pNewExtId)
 Add an object.
alp_status_t alp_hsds_ext_begin_db_transaction (AlpHsDataStoreHandle hDs)
 Start a transaction on the datastore's content.
alp_status_t alp_hsds_ext_clear_change_info (AlpHsDataStoreHandle hDs)
 Clears the status tracking flags after successfully recording all IDs from alp_hsds_ext_get_change_info.
alp_status_t alp_hsds_ext_close (AlpHsDataStoreHandle hDs)
 Closes an external datastore.
alp_status_t alp_hsds_ext_delete (AlpHsDataStoreHandle hDs, AlpHsExternalID *pExtId)
 Delete an object.
alp_status_t alp_hsds_ext_end_db_transaction (AlpHsDataStoreHandle hDs)
 Commit a transaction that was started in alp_hsds_ext_begin_db_transaction.
alp_status_t alp_hsds_ext_get_change_info (AlpHsDataStoreHandle hDs, AlpHsExtChangesReportSet *report_set, int16_t iCountRead, bool *moreData)
 Gets an array of added/modified/deleted records from an external datastore since the last sync.
alp_status_t alp_hsds_ext_is_version_current (AlpHsDataStoreHandle hDs, AlpHsDataStoreVersionType type, uint32_t version, bool *isCurrent)
 Determine whether the capabilities or string table version is current.
alp_status_t alp_hsds_ext_open (const _TCHAR *locURI, uint32_t userId, AlpHsDataStoreHandle *phDs)
 Opens an external datastore.
alp_status_t alp_hsds_ext_read (AlpHsDataStoreHandle hDs, AlpHsObjectTypePtr pTgtType, AlpHsExternalID *pExtId, size_t offset, bool *moreData, size_t *pBufSize, _TCHAR *pBuf)
 Read an object's content.
alp_status_t alp_hsds_ext_read_capabilities (AlpHsDataStoreHandle hDs, uint32_t *pCurrentVersion, size_t *pSize, _TCHAR *pBuffer)
 Read the DataStore's capabilities.
alp_status_t alp_hsds_ext_read_string_table (AlpHsDataStoreHandle hDs, AlpHsObjectTypePtr pObjType, uint32_t *pCurrentVersion, size_t *pSize, _TCHAR *pBuffer)
 Read the DataStore's WBXML string table for the input object type.
alp_status_t alp_hsds_ext_replace (AlpHsDataStoreHandle hDs, AlpHsObjectTypePtr pSrcType, AlpHsExternalID *pExtId, size_t offset, bool moreData, size_t bufSize, const _TCHAR *pBuf, bool *pExtIdChanged)
 Replace an object's content.
alp_status_t alp_hsds_ext_rollback_db_transaction (AlpHsDataStoreHandle hDs)
 Roll back a transaction that was started in alp_hsds_ext_begin_db_transaction.
alp_status_t alp_hsds_ext_update (AlpHsDataStoreHandle hDs, AlpHsObjectTypePtr pSrcType, AlpHsExternalID *pExtId, size_t offset, bool moreData, size_t bufSize, const _TCHAR *pBuf, bool *pExtIdChanged)
 Update an object's content.


Function Documentation

alp_status_t alp_hsds_ext_add AlpHsDataStoreHandle  hDs,
AlpHsObjectTypePtr  pSrcType,
bool  isReferenceable,
AlpHsExternalID pComponentExtIds,
size_t  componentExtIdSize,
size_t  offset,
bool  moreData,
size_t  bufSize,
const _TCHAR *  pBuf,
AlpHsExternalID pNewExtId
 

Add an object.

The HotSync Change Manager calls this function repeatedly to iteratively add a new object to a DataStore. Each call specifies the next bufSize bytes of the new object's content formatted according to the specified srcType.

For an external datastore, this function must fill out the external ID with a new ID for this object and also specify the byte length of the external ID.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pSrcType MIME type format for the content in *pBuf
[in] isReferenceable True if the new object is refereceable; false otherwise
[in] pComponentExtIds If this object contains component external IDs, array of component external IDs. Otherwise, NULL.
[in] componentExtIdSize Number of component IDs array elements, or 0 if there are none.
[in] offset The number of bytes written so far
[in] moreData True when additional calls are required to write all of the object's content; false otherwise
[in] bufSize The size of *pBuf
[in] pBuf The object's content formatted according to pSrcType
[out] pNewExtId The new external ID for this newly added object.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
The Change Manager only calls this function during a synchronization session.

The AlpHsExternalID object that pNewExtId points to is already allocated. The datastore does not need to allocate it. The datastore only needs to fill it with a new ID.

alp_status_t alp_hsds_ext_begin_db_transaction AlpHsDataStoreHandle  hDs  ) 
 

Start a transaction on the datastore's content.

The Hotsync Change Manager will call this function before it writes content to this datastore. The datastore is expected to start a transaction on its content. If the Change Manager successfully writes content to this datastore, the Change Manager will call alp_hsds_ext_end_db_transaction so the datastore can commit the newly added content. If the Change Manager encounters an error, the Change Manager will call alp_hsds_ext_rollback_db_transaction, and the datastore is expected to restore its content back to the state it was in when alp_hsds_ext_begin_db_transaction was called.

Parameters:
[in] hDs Handle of an opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_end_db_transaction alp_hsds_ext_rollback_db_transaction

alp_status_t alp_hsds_ext_clear_change_info AlpHsDataStoreHandle  hDs  ) 
 

Clears the status tracking flags after successfully recording all IDs from alp_hsds_ext_get_change_info.

After the Hotsync Change Manager has received and successfully recorded all added/modified/deleted record IDs since the last sync, the Change Manager will call this function to let the external datastore know of its success. The external datastore is expected to clear its status tracking flags on these records and perform other cleanup functions. For example, a record that was marked as deleted can finally be deleted here.

Parameters:
[in] hDs Handle of an opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_get_change_info

alp_status_t alp_hsds_ext_close AlpHsDataStoreHandle  hDs  ) 
 

Closes an external datastore.

The datastore can free memory that may have been allocated for this datastore handle.

Parameters:
[in] phDs Handle of an opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_open

alp_status_t alp_hsds_ext_delete AlpHsDataStoreHandle  hDs,
AlpHsExternalID pExtId
 

Delete an object.

The HotSync Change Manager calls this function to delete an object from a DataStore.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pExtId The external ID of the object to be deleted.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.

alp_status_t alp_hsds_ext_end_db_transaction AlpHsDataStoreHandle  hDs  ) 
 

Commit a transaction that was started in alp_hsds_ext_begin_db_transaction.

The datastore is expected to save the new data that was added since alp_hsds_ext_begin_db_transaction was called.

Parameters:
[in] hDs Handle of an opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_begin_db_transaction

alp_status_t alp_hsds_ext_get_change_info AlpHsDataStoreHandle  hDs,
AlpHsExtChangesReportSet report_set,
int16_t  iCountRead,
bool *  moreData
 

Gets an array of added/modified/deleted records from an external datastore since the last sync.

At the beginning of sync, the Hotsync Change Manager will ask for all of the added/modified/deleted records IDs since the last sync. The Change Manager will record these IDs into its change management system, and then proceed with the sync operation.

The Change Manager will allocate one AlpHsExtChangesReportSet object, and then allocate an array of AlpHsExternalObject within the report set object. The report set object's 'buffcount' variable indicates the size of this array, and the 'size' variable is initially set to 0.

The external datastore is expected to fill in the array with record IDs of all added/modified/deleted records since the last sync. The external datastore must also fill the report set object's 'size' variable of the actual number of records that was filled into the array. If there are no changed records, the external datastore would fill the 'size' variable with a 0. For example, the Change Manager may create an array capable of receiving 500 record IDs. The external datastore has 10 changed record IDs. The external datastore would fill in the first 10 elements of the array, and set the 'size' variable to 10.

If the external datastore has more changed records than the array can hold, the external datastore must set moreData to 'true', so that the Change Manager can make subsequent call(s) to receive the rest of the changes. When all of the changes have been filled, moreData must be set to 'false' to tell the Change Manager that all changes have been filled into the array. 'iCountRead' is used to indicate how many record IDs the Change Manager has processed so far.

Example:
The Change Manager has allocated an array for 100 record IDs. The external datastore has 250 changes.

First call - The Change Manager sets 'iCountRead' to 0, so the Change Manager is looking for the 1st record.
The external datastore fills in the array of the first 100 records and sets 'size' to 100.
The external datastore sets 'moreData' to 'true'.

Second call - The Change Manager sets 'iCountRead' to 100, so the Change Manager is looking for the 101st record.
The external datastore fills in the array of the next 100 records and sets 'size' to 100.
The external datastore sets 'moreData' to 'true'.

Third call - The Change Manager sets 'iCountRead' to 200, so the Change Manager is looking for the 201st record.
The external datastore fills in the array of the last 50 records and sets 'size' to 50.
The external datastore sets 'moreData' to 'false'.

When the Change Manager successfully records all changes, alp_hsds_ext_clear_change_info is called so the external datastore can clear its status tracking flags.

Parameters:
[in] hDs Handle of an opened datastore.
[out] report_set A report set object containing an array for external IDs that the datastore must fill out.
[in] iCountRead The number of records processed by the Change Manager so far.
[out] moreData Set to true if there are more changed records to be reported, false otherwise.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_clear_change_info

alp_status_t alp_hsds_ext_is_version_current AlpHsDataStoreHandle  hDs,
AlpHsDataStoreVersionType  type,
uint32_t  version,
bool *  isCurrent
 

Determine whether the capabilities or string table version is current.

Parameters:
[in] hDs Handle of an opened datastore.
[in] type The version type (capabilities or string table)
[in] version The caller's version number
[out] isCurrent True if the caller's version is the same as the current version; false otherwise
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
The implementation should set *isCurrent to false when the input version is zero.

The buffer is allocated by the caller. When pBuffer is null, the implementation should return the size of the capabilities in *pSize. This usage allows the caller to allocate a buffer of the correct size.

alp_status_t alp_hsds_ext_open const _TCHAR *  locURI,
uint32_t  userId,
AlpHsDataStoreHandle phDs
 

Opens an external datastore.

The external datastore must generate a unique handle and return it in phDs. This handle is used in subsequent datstore calls.

When the datastore is no longer needed, alp_hsds_ext_close is called to close the datastore.

When the datastore is opened for sync, there may be special cases where the datastore is not able to participate in the current sync session, and wants to be ignored for the rest of the current sync session without aborting the sync session itself. In this case, the datastore can return ALP_STATUS_DATASTORE_IGNORE_DATASTORE or ALP_STATUS_DATASTORE_IGNORE_AGENT to tell the sync session to ignore this datastore only, or all datastores of this agent, respectively, for the rest of sync.

Parameters:
[in] locURI The local URI of the datastore that is to be opened.
[in] userId On the Desktop side, the current Desktop user. On an ALP device, this is 0.
[out] phDs A unique handle for the opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. To ignore this datastore for the current sync session, ALP_STATUS_DATASTORE_IGNORE_DATASTORE. To ignore all datastores of this agent for the current sync session, ALP_STATUS_DATASTORE_IGNORE_AGENT. Otherwise, TBD.
See also:
alp_hsds_ext_close

alp_status_t alp_hsds_ext_read AlpHsDataStoreHandle  hDs,
AlpHsObjectTypePtr  pTgtType,
AlpHsExternalID pExtId,
size_t  offset,
bool *  moreData,
size_t *  pBufSize,
_TCHAR *  pBuf
 

Read an object's content.

The HotSync Change Manager calls this function repeatedly to iteratively read an object's content from a DataStore. Each call should return the next *pBufSize bytes of the object's content formatted according to the specified tgtType.

When a read attempt fails due to an active or pending writer, this function should return ALP_HOTSYNC_DATASTORE_BUSY. This will cause the Change Manager to retry the read.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pTgtType How to format the object's content
[in] pExtId The external ID of the object to be read.
[in] offset The number of bytes read so far
[out] moreData True when additional calls are required to read all of the object's content; false otherwise
[in,out] pBufSize On input, the size of *pBuf; on output, the number of bytes written to *pBuf
[in,out] pBuf Buffer to hold the object's content
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
Do not include the null terminated character at the end of content.

The Change Manager only calls this function during a synchronization session.

alp_status_t alp_hsds_ext_read_capabilities AlpHsDataStoreHandle  hDs,
uint32_t *  pCurrentVersion,
size_t *  pSize,
_TCHAR *  pBuffer
 

Read the DataStore's capabilities.

Parameters:
[in] hDs Handle of an opened datastore.
[out] pCurrentVersion The current capabilities version
[in,out] pSize On input, the size of *pBuffer; on output, the number of bytes written to *pBuffer
[in,out] pBuffer Buffer to receive the datastore capabilites
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.

alp_status_t alp_hsds_ext_read_string_table AlpHsDataStoreHandle  hDs,
AlpHsObjectTypePtr  pObjType,
uint32_t *  pCurrentVersion,
size_t *  pSize,
_TCHAR *  pBuffer
 

Read the DataStore's WBXML string table for the input object type.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pObjType Identifies the target object type.
[out] pCurrentVersion The current string table version
[in,out] pSize On input, the size of *pBuffer; on output, the number of bytes written to *pBuffer
[in,out] pBuffer Buffer to receive the datastore's string table
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
The buffer is allocated by the caller. When pBuffer is null, the implementation should return the size of the capabilities in *pSize. This usage allows the caller to allocate a buffer of the correct size.

alp_status_t alp_hsds_ext_replace AlpHsDataStoreHandle  hDs,
AlpHsObjectTypePtr  pSrcType,
AlpHsExternalID pExtId,
size_t  offset,
bool  moreData,
size_t  bufSize,
const _TCHAR *  pBuf,
bool *  pExtIdChanged
 

Replace an object's content.

The HotSync Change Manager calls this function repeatedly to iteratively replace the content for an object that is already present in the DataStore. Each call specifies the next bufSize bytes of the object's new content formatted according to the specified srcType.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pSrcType MIME type format for content in *pBuf
[in,out] pExtId The external ID of the external datastore's record to be replaced.
[in] offset The number of bytes written so far
[in] moreData True when additional calls are required to write all of the object's content; false otherwise
[in] bufSize The size of *pBuf
[in] pBuf The object's content formatted according to pSrcType
[out] pExtIdChanged Whether or not a new external ID was generated for this record.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
The Change Manager only calls this function during a synchronization session.

If the replace operation requires a new external ID to be generated, this function must fill the external ID supplied by pExtId. It must not allocated new memory for the external ID.

alp_status_t alp_hsds_ext_rollback_db_transaction AlpHsDataStoreHandle  hDs  ) 
 

Roll back a transaction that was started in alp_hsds_ext_begin_db_transaction.

The datastore is expected to restore its content back to the state it was in when alp_hsds_ext_begin_db_transaction was called.

Parameters:
[in] hDs Handle of an opened datastore.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
See also:
alp_hsds_ext_begin_db_transaction

alp_status_t alp_hsds_ext_update AlpHsDataStoreHandle  hDs,
AlpHsObjectTypePtr  pSrcType,
AlpHsExternalID pExtId,
size_t  offset,
bool  moreData,
size_t  bufSize,
const _TCHAR *  pBuf,
bool *  pExtIdChanged
 

Update an object's content.

The HotSync Change Manager calls this function repeatedly to iteratively update the content for an object that is already present in the DataStore. Each call specifies the next bufSize bytes of the object's changed content formatted according to the specified srcType.

Unlike a replace, an update does not replace the entire object's content; instead only the specific fields present in the input content are replaced; the value for other fields remains unchanged.

Parameters:
[in] hDs Handle of an opened datastore.
[in] pSrcType MIME type format for content in *pBuf
[in,out] pExtId The external ID of the external datastore's record to be updated.
[in] offset The number of bytes written so far
[in] moreData True when additional calls are required to write all of the object's content; false otherwise
[in] bufSize The size of *pBuf
[in] pBuf The object's modified content formatted pSrcType
[out] pExtIdChanged Whether or not a new external ID was generated for this record.
Returns:
If successful, ALP_STATUS_HOTSYNC_OK. Otherwise, TBD.
Remarks:
The Change Manager only calls this function during a synchronization session.

If the replace operation requires a new external ID to be generated, this function must fill the external ID supplied by pExtId. It must not allocated new memory for the external ID.


Generated on Wed Jul 30 07:06:42 2008 by Doxygen 1.4.6 for ALP SDK + Hiker Documentation

Copyright © 1999-2008 ACCESS CO., LTD. All rights reserved.