Detecting Changes to Desktop Objects (Windows Embedded CE 6.0)

1/6/2010

The service manager automatically detects object changes and deletions by comparing the list of handles returned during enumeration with the handles loaded from the service manager's persistent file. Before starting an enumeration process, the service manager does the following:

  1. Marks a bit for each handle stored in Repl.dat.
  2. Calls IReplStore::FindFirstItem and IReplStore::FindNextItem.
  3. Performs a binary search on the handles in Repl.dat each time one of these methods returns a new handle to find a handle representing the same object.
  4. If no matching handle is found, it creates a new object on the desktop store.
  5. If a matching handle is found, it clears the bit from the handle in Repl.dat and calls IReplStore::IsItemChanged to see if the object has changed since the last synchronization.
  6. If the object has changed, it calls IReplStore::CopyObject to copy the data from the returned handle into the handle that is saved in Repl.dat.
  7. Calls IReplStore::IsItemReplicated to see if it should send the object to the Windows Embedded CE-based device.

All handles in Repl.dat that remain marked once enumeration is complete represent deleted objects.

To speed up enumeration, the desktop provider can detect and report desktop changes to the service manager in real time. To do so, the desktop provider and service manager perform the following actions.

  1. The service manager calls IReplNotify::OnItemNotify to inform the desktop provider of an object's status.
  2. The desktop provider passes RNC_MODIFIED for a modified object, RNC_CREATED for a created object, and RNC_DELETED for a deleted object.
  3. The desktop provider passes a handle to the object so the service manager can search the persistent file for the corresponding device object.

The following illustration shows the sequence of real-time notification calls.

Ee485560.3a22d5bc-f72e-4e2f-9f7b-9faf464a1e13(en-US,WinEmbedded.60).gif

If the desktop provider detects that the desktop application has closed, it calls IReplNotify::OnItemNotify with RNC_SHUTDOWN. The service manager responds by unloading the desktop provider and updating the status display.

The following code examples show how to implement IReplStore::IsItemChanged and IReplStore::IsItemReplicated.

STDMETHODIMP_(BOOL) CStore::IsItemChanged
(
   HREPLFLD  hFolder,   // handle of folder or container that stores object
   HREPLITEM hItem,     // handle of object
   HREPLITEM hItemComp  // handle of object used for comparison
)
{
   CFolder *pFolder   = (CFolder*)hFolder;
   CItem   *pItem     = (CItem*)  hItem;
   CItem   *pItemComp = (CItem*)  hItemComp;
   BOOL     fChanged  =  FALSE;

   if (pItemComp)
       fChanged = CompareFileTime (&pItem->m_ftModified,
                                   &pItemComp->m_ftModified);
   else
   {
       FILETIME ft;

       // Read modification time stamp from object into ft.
       // Compare with the time stamp in the object.
       fChanged = CompareFileTime (&pItem->m_ftModified, &ft);
   }
   return fChanged;
}

STDMETHODIMP_(BOOL) CStore::IsItemReplicated
(
   HREPLFLD  hFolder,   // handle of folder or container that stores object
   HREPLITEM hItem,     // handle of object
)
{
   CFolder *pFolder = (CFolder*)hFolder;
   CItem   *pItem   = (CItem*)  hItem;

   // hItem can be NULL.
   if (pItem == NULL)
       return TRUE;

   // Search for the item. Return FALSE if not found.
   // ...

   // Check if pItem should be replicated by using information
   // stored both in pFolder & pItem. If so, return TRUE.
   // ...

   return FALSE;
}

See Also

Concepts

Developing the Desktop Provider