Event.next: lazily evaluate the snapshot

The database_callback was previously generating a snapshot
(eg VM.get_record) for every database write, and then throwing
it away in events_notify when no-one was registered. Simply
starting xapi would trigger at least 60 of these; every CLI command
triggers a minimum of an extra 5 by virtue of logging in and out
(even though sessions are deliberately excluded from the event
system).

- This is fixed by replacing 'snapshot' with 'snapshot_fn', a
  thunk which generates the snapshot. The thunk is only evaluated
  if a registered client calls event.next().

The database_callback snapshots sitting in the event.next queue
contain lots of duplicated data, since one field changes at a time.

- This is fixed by ensuring the 'snapshot_fn' captures the database
  in its closure, so all the duplicated data stays shared and is
  only expanded out into XML if the user requests it.

After this patch, in a simple case where a VM changes name, each
event is responsible for about 160 extra heap words.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>