Commit Graph

30 Commits

Author SHA1 Message Date
Frediano Ziglio
4c25ce1877 dispatcher: Update documentation
Move to Doxygen (output was not meant to generate output
automatically).
Update some part that were outdated.
Typo messsage_type -> message_type.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-25 09:12:37 +01:00
Frediano Ziglio
982d14dd69 dispatcher: Move some private functions to DispatcherPrivate
Reduce declaration in the header.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-17 10:59:38 +02:00
Frediano Ziglio
2b9e1dcd55 dispatcher: Reuse base reference counting for Dispatcher hierararchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
f4aefa728e Remove GObject from Dispatcher hierarchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
f680cc7870 dispatcher: Add a more safe dispatcher_send_message_custom version
Use a template to wrap the other dispatcher_send_message_custom
avoiding having to pass a void* opaque and extract payload size
from passed type.
Will be used more by next commit when Dispatchers are turned into
C++.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
164a333f99 Define and use (un)ref
Avoids g_object_(un)ref.
This in preparation to remove GObject.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
75679dc95d dispatcher: Use IS-A relationship for Dispatcher hierarchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
e0b395fb68 Declare exported functions as C
Allows to be used by both C and C++ code.
So to leave part of the code in C and part move to C++.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
948ec8b81b dispatcher: Move thread_id field from Dispatcher to MainDispatcher
Dispatcher is just storing the thead_id for MainDispatcher,
move thread_if to MainDispatcher to avoid useless field and API.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-26 14:36:14 +00:00
Frediano Ziglio
5fb4f52bdb dispatcher: Use a new API to handle events
Instead of having to manually register the file descriptor and
than need to call dispatcher_handle_recv_read just provide a single
API to create the watch.
This has some advantage:
- replace 2 API with 1;
- code reuse for handling the event (removed 2 functions);
- avoid the caller to use the file descriptor;
- avoid the caller to register wrong events.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:16:57 +01:00
Frediano Ziglio
46efdc1e09 dispatcher: Allows to manage messages without registering them
The only way to add new message to Dispatcher was to register
using a number. These numbers corresponded to array indexes.
This is good if the list of messages is allocated statically
and contiguously, on the contrary this method is not that
flexible.
Writing a header of 4 or 16 bytes using system call does not
make much difference so pass all message information in the
payload header.
A new dispatcher_send_message_custom function allows to send
a message passing all message information, including the
pointer to the handler.
This will allow for instance a Dispatcher associate to a given
thread to be reused by different classes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 15:38:16 +00:00
Frediano Ziglio
dec1fdeab8 Add possibly missing headers for pthread.h
In some environment pthread.h is not defined but its definitions
are used in some headers.
Actually happens using MingW.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-26 10:54:01 +01:00
Jonathon Jongsma
a4450f928d Add documentation for Dispatcher 2017-09-07 11:12:45 -05:00
Jonathon Jongsma
439fa1574f Dispatcher: remove async_done callback
This callback was only executed for message types that were registered
with DISPATCHER_ASYNC ack type. However, the async_done handler was
called immediately after the message-specific handler and was called in
the same thread, so the async_done stuff can just as easily be done from
within the message-specific handler. This allows to simplify the
dispatcher_register_handler() method to simply require a boolean
argument for whether the message type requires an ACK or not.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-07 10:22:15 -05:00
Frediano Ziglio
343cac8d6d dispatcher: Remove "opaque" property
Is supposed to be used during initialization but is never
used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-07 16:13:49 +01:00
Jonathon Jongsma
02176e565c Move DispatcherMessage to source file
This is an internal implementation detail

Acked-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-05 13:50:16 -05:00
Christophe Fergeau
bc5326b1ce Unify header guards
This changes the header guards in all .h files to follow this format:

/*
 * Licensing block
 */

/* ... */

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-03-30 18:17:20 +01:00
Frediano Ziglio
4585fa9cbd unify header include order
Use this style for include headers inside headers:

  #include <system_headers.h>
  #include <no_spice_no_system_libraries.h>
  #include <spice_protocol.h>
  #include <spice_common.h>

  #include "spice_server.h"

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-12 11:02:54 +01:00
Jonathon Jongsma
5c55955ade Convert Dispatcher and MainDispatcher to GObjects
Allows more explicit inheritance relationship, and numerous other
advantages.

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-03-30 17:19:24 +01:00
Frediano Ziglio
febaed3529 server: misc header cleanups
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-09 22:17:51 +00:00
Marc-André Lureau
d793473e5e server: cleanups
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2015-11-27 11:49:56 +00:00
Pavel Grunt
fd1eff352d dispatcher: Remove unused dispatcher_read_message
It is not needed since d3153f8610

Signed-off-by: Pavel Grunt <pgrunt@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2015-11-23 11:45:20 +00:00
Frediano Ziglio
78c8203f16 removed unused recv_core field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-23 12:08:09 +01:00
Marc-André Lureau
bba1bf180a server: remove worker thread creation from dispatcher
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-22 17:06:44 +01:00
Christophe Fergeau
e5e3e9eefe Add missing license headers 2015-10-19 14:25:36 +02:00
Alon Levy
865455cf32 server/dispatcher: add extra_dispatcher, hack for red_record
Signed-off-by: Alon Levy <alon@pobox.com>
2015-08-20 17:47:24 +01:00
Yonit Halperin
ba1aaef0fe dispatcher.h: fix - s/#define MAIN_DISPATCHER_H/#define DISPATCHER_H 2013-04-22 16:30:54 -04:00
Alon Levy
ca5776f40e server/dispatcher: add dispatcher_register_async_done_callback 2011-11-08 16:22:21 +02:00
Alon Levy
fff04e867c introduce DISPATCHER_{NONE,ACK,ASYNC} 2011-11-08 14:59:51 +02:00
Alon Levy
776bdd6c95 server: introduce dispatcher
used for main_dispatcher only in this patch.

Dispatcher is meant to be used for Main<->any low frequency messages.

It's interface is meant to include the red_dispatcher usage:
 fixed size messages per message type
 some messages require an ack

Some methods are added to be used by RedDispatcher later:
 dispatcher_handle_read - to be called directly by RedDispatcher epoll
  based loop
 dispatcher_set_opaque - to be set from red_worker pthread
 dispatcher_init - allow NULL core as used by red_worker

Read and Write behavior:
 Sender: blocking write, blocking read for ack (if any).
 Reader: poll for any data, if such then blocking read for a
 message_type and following message. repeat until poll returns
 with no pending data to read.

FDO Bugzilla: 42463
2011-11-08 14:59:49 +02:00