server/tests/replay: introduce

usage: replay <cmdfile> <port> <client command line>

will run the commands from cmdfile ignoring timestamps, right after a
connection is established from the client, and will SIGINT the client
on end of cmdfile, and exit itself after waiting for the client.

spicy-stats from spice-gtk is useful for testing, it prints the summary
of the traffic on each channel.

You can also run with no client by doing:
replay <cmdfile>

For example, the 300 MB file (compressed to 4 MB with xz -9) available
at [1] produces the following output:

spicy-stats total bytes read:
total bytes read:
inputs: 214
display: 1968983
cursor: 390
main: 256373

You could run it directly like so:
curl http://annarchy.freedesktop.org/~alon/win7_boot_shutdown.cmd.xz | xzcat | server/tests/replay - 12345 `which spicy-stats` -h localhost -p 12345

Known Problems:
* Implementation is wrong. Should do a single device->host conversion
 (i.e. get_virt), and then marshall/demarshall that (i.e. RedDrawable).
* segfault on file read done resulting in the above spicy-stats not
 being reproducable (well, up to 1% yes).

[1] http://annarchy.freedesktop.org/~alon/win7_boot_shutdown.cmd.xz

Now based on glib including using an asyncqueue for reading the playback
file, and proper freeing of the allocated commands, with --slow,
--compression and a progress timer, and doesn't use more then nsurfaces.
worker: move red_init() functions
worker: replace init with red_worker_new
server: use more const CoreInterface
worker: use glib main loop

Clean up, more extensible.

Avoid server hanging when no client are connected.
channel: do not free rcc->stream in red_channel_client_disconnect

This fixes the following scary racy corruption after glib loop switch:

==28173==
==28173== Debugger has detached.  Valgrind regains control.  We
continue.
==28173== Invalid read of size 8
==28173==    at 0x4C7871E: reds_stream_read (reds.c:4521)
==28173==    by 0x4C2F9D7: red_peer_receive (red_channel.c:209)
==28173==    by 0x4C2FB59: red_peer_handle_incoming (red_channel.c:255)
==28173==    by 0x4C2FF36:
red_channel_client_receive (red_channel.c:329)
==28173==    by 0x4C33D6D: red_channel_client_event (red_channel.c:1577)
==28173==    by 0x4C65098: watch_func (red_worker.c:10292)
==28173==    by 0x504DDAB: g_io_unix_dispatch (giounix.c:167)
==28173==    by 0x4FFACB6: g_main_dispatch (gmain.c:3065)
==28173==    by 0x4FFBA0D: g_main_context_dispatch (gmain.c:3641)
==28173==    by 0x4FFBBFF: g_main_context_iterate (gmain.c:3712)
==28173==    by 0x4FFC028: g_main_loop_run (gmain.c:3906)
==28173==    by 0x4C6ABF2: red_worker_main (red_worker.c:12180)
==28173==  Address 0x7d688e0 is 32 bytes inside a block of size 160
free'd
==28173==    at 0x4A074C4: free (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28173==    by 0x4C78A84: reds_stream_free (reds.c:4594)
==28173==    by 0x4C34E2E:
red_channel_client_disconnect (red_channel.c:1865)
==28173==    by 0x4C30363:
red_channel_client_default_peer_on_error (red_channel.c:417)
==28173==    by 0x4C3011B: red_peer_handle_outgoing (red_channel.c:372)
==28173==    by 0x4C3305F: red_channel_client_send (red_channel.c:1298)
==28173==    by 0x4C33FB6:
red_channel_client_begin_send_message (red_channel.c:1616)
==28173==    by 0x4C5F4B4:
display_begin_send_message (red_worker.c:8360)
==28173==    by 0x4C61DE8: display_channel_send_item (red_worker.c:9164)
==28173==    by 0x4C30C69:
red_channel_client_send_item (red_channel.c:599)
==28173==    by 0x4C332BB: red_channel_client_push (red_channel.c:1351)
==28173==    by 0x4C33C3A:
red_channel_client_handle_message (red_channel.c:1545)
server/dispatcher: move worker enums to dispatcher header

Group enums with their respective struct location.
server: remove hardcoded RED_MAX_RENDERERS
server: remove worker thread creation from dispatcher
worker: remove useless MESSAGE_READY

Now that worker is created before running, and run() returns success,
there is no point in using MESSAGE_READY.
server: dispatcher_init/dispatcher_new
worker: remove need for WorkerInitData

Move code around to declare and place it where it fits better.
worker: use a single clockid

The stat functions in worker are not generic enough to deserve to be
"non-worker", so just pass the worker instance.
server: move dispatcher GSource handling code
worker: use GOnce to surround some global init in dispatcher
server: move some pixmap cache code in own file

Remove that hideous template header that should really be regular code
since it's specialized and instanciated only for pixmap.
server: start separate display/cursor channel headers

Just move some declarations around
server: split cache_item.h
server: rename red_client_cache.h to cache_item.tmpl.c
server: small move to red_channel