summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
2012-10-15scanner: remove useless desc_dump argumentsOlivier Blin1-1/+1
This are remnant from the desc_dump generalization in commit 375cb418.
2012-10-15client: Return number of events dispatched from dispatch functionsKristian Høgsberg1-3/+3
To let clients determine whether any events were dispatched, we return the number of dispatched events. An event source with an event queue (such as wl_display or an X connection) may queue up event as a result of processing a different event source (data on a network socket, timerfd etc). After dispatching data from fd (or just before blocking) we have to check such event sources, which is what wl_event_source_check() is used for. A checked event source will have its handler called with mask=0 just before blocking. If any work is done in any of these handlers, we have to check all the checked sources again, since the work could have queued up events in a different source. This is why the event handlers must return a positive number if events were handled. Which in turn is why we need the wl_display dispatch functions to return that as well.
2012-10-15client: Add wl_display_dispatch_pending() for dispatching without readingKristian Høgsberg2-6/+22
If the main thread ends up dispatching a non-main queue, and not in a wl_display_dispatch() callback, we may queue up main queue events and read all data from the socket fd. When we get back to the main loop, the socket fd is no longer readable and nothing will trigger dispatching of the queued up events. The new function wl_display_dispatch_pending() will dispatch any pending events, but not attempt to read from the socket. Clients that integrate the wayland socket fd into a main loop should call wl_display_dispatch_pending() and then wl_display_flush() before going back to blocking in poll(2) or similar mechanism.
2012-10-11client: Discard proxies with no implementation at dispatch timeKristian Høgsberg1-2/+3
We need to queue up events even if a proxy doesn't have an implementation (listener). In case of server created new objects, the client haven't had a chance to set the listener when the first events to the new object come in. So now we always queue up events and discard them at dispatch time if they don't have a listener at that point.
2012-10-11client: Don't forget to init and destroy mutexKristian Høgsberg1-0/+2
These chunks were dropped at some point, thanks to David Herrmann for spotting the omission.
2012-10-11connection: Print object id for new-id arguments in deubug outputKristian Høgsberg1-2/+1
We can't use the same behaviour in both the client and the server. In the client this is a wl_proxy pointer in the server it's a pointer to the uint32_t object id. This doesn't fix the problem, but it's a slightly more useful default, since we typically use WAYLAND_DEBUG on the client.
2012-10-11client: Fix double locking bugAnder Conselvan de Oliveira2-6/+2
The function wl_proxy_create_for_id() would try to acquire the display lock, but the only call path leading to it would call it with the lock already acquired. This patch removes the attempt to acquire the lock and makes the function static. It was exported before because client had to create proxy's manually when the server sent a new object id, but since commit 9de9e39f [1] this is no longer necessary. [1] commit 9de9e39f87adfce1ea9755e394928756254c0ba2 Author: Kristian Høgsberg <krh@bitplanet.net> Date: Thu Jun 28 22:01:58 2012 -0400 Allocate client proxy automatically for new objects v2: Change the right function. Previous patch changed wl_proxy_create() instead of wl_proxy_create_for_id().
2012-10-11data-device: Don't fake an attach event on drag icon surfaceAnder Conselvan de Oliveira1-10/+2
Emit a new drag icon signal instead and let the compositor handle the unmapping of the icon surface.
2012-10-10Fix typecheck in case of multiple instances of type meta dataKristian Høgsberg1-1/+15
In most cases the pointer equality test is sufficient. However, in some cases, depending on how things are split across shared objects, we can end up with multiple instances of the interface metadata constants. So if the pointers match, the interfaces are equal, if they don't match we have to compare the interface names.
2012-10-10connection: Move object lookup out of wl_connection_demarshal()Kristian Høgsberg4-38/+74
On the client side where we queue up multiple events before dispatching, we need to look up the receiving proxy and argument proxies immediately before calling the handler. Between queueing up multiple events and eventually invoking the handler, previous handlers may have destroyed some of the proxies.
2012-10-10Split the global registry into its own wl_registry objectKristian Høgsberg3-147/+50
The only way to make the global object listener interface thread safe is to make it its own interface and make different listeners different wl_proxies. The core of the problem is the callback we do when a global show up or disappears, which we can't do with a lock held. On the other hand we can't iterate the global list or the listener list without a lock held as new globals or listeners may come and go during the iteration. Making a copy of the list under the lock and then iterating after dropping the lock wont work either. In case of the listener list, once we drop the lock another thread may unregister a listener and destroy the callbackk data, which means that when we eventually call that listener we'll pass it free memory and break everything. We did already solve the thread-safe callback problem, however. It's what we do for all protocol events. So we can just make the global registry functionality its own new interface and give each thread its own proxy. That way, the thread will do its own callbacks (with no locks held) and destroy the proxy when it's no longer interested in wl_registry events.
2012-10-10scanner: Generate client stubs for wl_display requestsKristian Høgsberg3-52/+0
We used to special case this because of the untyped new-id argument in the bind request. Now that the scanner can handle that, we can remove the special case. Switching to the generated stubs does bring an API change since we now also take the interface version that the client expects as an argument. Previously we would take this from the interface struct, but the application may implement a lower version than what the interface struct provides. To make sure we don't try to dispatch event the client doesn't implement handlers for, we have to use a client supplied version number.
2012-10-10scanner: Send interface name and version for types new_id argsKristian Høgsberg1-17/+46
This makes the scanner generate the code and meta data to send the interface name and version when we pass a typeless new_id. This way, the generic factory mechanism provided by wl_display.bind can be provided by any interface.
2012-10-10client: Add wl_event_queue for multi-thread dispatchingKristian Høgsberg2-35/+123
This introduces wl_event_queue, which is what will make multi-threaded wayland clients possible and useful. The driving use case is that of a GL rendering thread that renders and calls eglSwapBuffer independently of a "main thread" that owns the wl_display and handles input events and everything else. In general, the EGL and GL APIs have a threading model that requires the wayland client library to be usable from several threads. Finally, the current callback model gets into trouble even in a single threaded scenario: if we have to block in eglSwapBuffers, we may end up doing unrelated callbacks from within EGL. The wl_event_queue mechanism lets the application (or middleware such as EGL or toolkits) assign a proxy to an event queue. Only events from objects associated with the queue will be put in the queue, and conversely, events from objects associated with the queue will not be queue up anywhere else. The wl_display struct has a built-in event queue, which is considered the main and default event queue. New proxies are associated with the same queue as the object that created them (either the object that a request with a new-id argument was sent to or the object that sent an event with a new-id argument). A proxy can be moved to a different event queue by calling wl_proxy_set_queue(). A subsystem, such as EGL, will then create its own event queue and associate the objects it expects to receive events from with that queue. If EGL needs to block and wait for a certain event, it can keep dispatching event from its queue until that events comes in. This wont call out to unrelated code with an EGL lock held. Similarly, we don't risk the main thread handling an event from an EGL object and then calling into EGL from a different thread without the lock held.
2012-10-10client: Make wl_display thread safeKristian Høgsberg1-4/+42
Not all entry points are thread safe: global listeners and global lookup is still only main thread.
2012-10-10client: Split event handling into demarshal and dispatch stepsKristian Høgsberg2-20/+49
This lets us demarshal with a mutex held and then do dispatching after releasing the mutex.
2012-10-10Change filedescriptor API to be thread safeKristian Høgsberg7-165/+127
The update callback for the file descriptors was always a bit awkward and un-intuitive. The idea was that whenever the protocol code needed to write data to the fd it would call the 'update' function. This function would adjust the mainloop so that it polls for POLLOUT on the fd so we can eventually flush the data to the socket. The problem is that in multi-threaded applications, any thread can issue a request, which writes data to the output buffer and thus triggers the update callback. Thus, we'll be calling out with the display mutex held and may call from any thread. The solution is to eliminate the udpate callback and just require that the application or server flushes all connection buffers before blocking. This turns out to be a simpler API, although we now require clients to deal with EAGAIN and non-blocking writes. It also saves a few syscalls, since the socket will be writable most of the time and most writes will complete, so we avoid changing epoll to poll for POLLOUT, then write and then change it back for each write.
2012-10-09connection: Add missing free from error pathRob Bradford1-0/+1
On the error codepath that errors out on ENOMEM we should free the allocated closure. Signed-off-by: Rob Bradford <rob@linux.intel.com>
2012-10-01connection: Drop unused static closuresKristian Høgsberg1-1/+0
2012-09-12event-loop: export wl_event_loop_dispatch_idle()David Herrmann2-3/+4
When integrating the wayland event-loop into another event-loop, we currently have no chance of checking whether there are pending idle sources that have to be called. This patch exports the "dispatch_idle_sources()" call so other event loops can call this before going to sleep. This is what wl_event_loop_dispatch() currently does so we simply allow external event-loops to do the same now. To avoid breaking existing applications, we keep the call to dispatch_idle_sources() in wl_event_loop_dispatch() for now. However, if we want we can remove this later and require every application to call this manually. This needs to be discussed, but the overhead is negligible so we will probably leave it as it is. This finally allows to fully integrate the wayland-server API into existing event-loops without any nasty workarounds. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-10wayland-server: return new ID in wl_client_add_resource()David Herrmann2-5/+9
wl_client_add_resource() used to return no error even though the new resource wasn't added to the client. This currently makes it very easy to DOS weston by simply posting thousands of "create_surface" requests with an invalid ID. Weston simply assumes the wl_client_add_resource() request succeeds but will never destroy the surface again as the "destroy" signal is never called (because the surface isn't linked into the wl_map). This change makes wl_client_add_resource() return the new ID of the added object and 0 on failure. Servers (like weston) can now correctly immediately destroy the surface when this call fails instead of leaving the surface around and producing memory-leaks. Instead of returning -1 on failure and 0 on success, I made it return the new ID as this seems more appropriate. We can directly use it when calling it with new_id==0. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-10event-loop: remove dead codeDavid Herrmann1-2/+2
There is really no need to increment "n" if we never read the value. The do-while() loop overwrites the value before it is read the first time. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-08-16Add wl_shm_buffer_create()Kristian Høgsberg2-1/+50
2012-08-16client: Add wl_display_connect_to_fd() functionKristian Høgsberg2-27/+45
This lets us connect a display to an already existing socket fd.
2012-08-03connection: zero out string paddingKristian Høgsberg1-3/+5
We don't want to send random data to the client and this also keeps valgrind happy.
2012-07-23More consistent ID printingDaniel Stone3-15/+15
Use unsigned rather than signed for IDs, so they match up with what we see in other prints. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23Make NEW_IDs nullableDaniel Stone3-6/+48
The connection-handling code already allows this, so make it legal in the protocol definition too. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23Unstatic arg_count_for_signature and get_next_argumentDaniel Stone2-7/+13
Expose these to other files using wayland-private.h, so wayland-client.c can walk NULLables properly. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-22connection: reserve id on incoming new objectMathias Fiedler1-3/+3
If a new object id arrives ensure that there is an empty array entry created, otherwise we might get out of sync for new ids if object isn't created by interface implementation.
2012-07-22wayland-util: add method for reserving new object idMathias Fiedler2-0/+34
wl_map_reserve_new() ensures that new id is valid and will point to an empty array entry.
2012-07-22wayland-server: send error on invalid new object idMathias Fiedler1-4/+10
Creation of new client resources was silently ignored when wl_client_add_resource() was used on server side and new object id was out of range. An error is now send out to the client in such case. Also changed error message in wl_client_add_object, since wl_map_insert_at() returns -1 only at invalid new id.
2012-07-20wayland-shm: Commit the width/height getters that actually compileKristian Høgsberg1-4/+4
2012-07-20shm: Add shm_buffer getters for width and heightKristian Høgsberg2-0/+22
2012-07-20wayland-client: Add missing newline from an error messageRobert Ancell1-1/+1
2012-07-17remove listener from wl_data_source destroy_signal listener listDmitry Guryanov1-1/+1
I've found a bug during wayland exploration - if you make two drag'n'drops in weston client example, dnd - weston crashes with segfault. I've tried to investigate it and found a problem. In function drag_grab_button we first call data_device_end_drag_grab, which sets seat->drag_data_source to NULL. Then we remove listener from list only if drag_data_source is not NULL. So if client will not free wl_data_source and start another drag'n'drop, after the first one. Then two wl_data_source structures will be free'd on client exit (let's name them s1 and s2). next and prev pointer of wl_data_source.resource.destroy_signal.listener_list in both wl_data_source structures will be seat->drag_data_source_listener, but next and prev in seat->drag_data_source_listener.link point to listener_list in s2. So if you try to iterate over listener_list in s1 then you get drag_data_source_listener as first item and (struct wl_listener *)(&s2.resource.destroy_signal.listener_list) Iteration over that list occurs in wl_resource_destroy->destroy_resource->wl_signal_emit->wl_signal_emit and try to call function at address of wl_resource->client, so weston segfaults there.
2012-07-10server: fix wl_seat_set_keyboardPekka Paalanen1-1/+1
This makes wl_seat_set_keyboard similar to wl_seat_set_pointer in that it's a no-op, if you try to set keyboard to NULL when it already is NULL, instead of refusing to set it to NULL ever. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-07-10server: add lose_touch_focus()Pekka Paalanen1-0/+10
Just like wl_keyboard and wl_pointer, add a signal handler for losing touch focus. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-07-09scanner: Include weston-client.h as the inline functions require itRobert Ancell1-2/+3
2012-07-09wayland-shm: Add return before we hit the error clean-up pathKristian Høgsberg1-0/+2
Regression in c94c0946db694ec29b5aebb94a8be0501bacfbc7
2012-07-09Fixup source comment in wayland-util.h and fix typo in TODOMartin Olsson1-2/+2
2012-07-09shm: Plug leak in shm_create_pool()Martin Olsson1-6/+9
2012-07-09server: Don't crash for wl_seat_set_touch(seat, NULL)Martin Olsson1-1/+1
2012-07-09scanner: Plug memory leak in end_element()Martin Olsson1-1/+1
2012-07-02protocol: Add explicit nullable typesChristopher James Halse Rogers2-8/+105
Most of the time it does not make sense to pass a NULL object, string, or array to a protocol request. This commit adds an explicit “allow-null” attribute to mark the request arguments where NULL makes sense. Passing a NULL object, string, or array to a protocol request which is not marked as allow-null is now an error. An implementation will never receive a NULL value for these arguments from a client. Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
2012-06-30wayland-client: reject socket paths longer than 108 bytesDylan Noblesmith1-1/+13
Attempting to write anything longer into the embedded char array would create a non-null-terminated string, and all later reads would run off the end into invalid memory. This is a hard limitation of AF_LOCAL/AF_UNIX sockets.
2012-06-30wayland-server: reject socket paths longer than 108 bytesDylan Noblesmith1-1/+15
Attempting to write anything longer into the embedded char array would create a non-null-terminated string, and all later reads would run off the end into invalid memory. This is a hard limitation of AF_LOCAL/AF_UNIX sockets.
2012-06-30wayland-server: add more logging of errorsDylan Noblesmith1-0/+2
2012-06-30wayland-server: fix socket ownership race conditionDylan Noblesmith1-10/+10
Always unlink() the lock file before closing the file descriptor for it. Otherwise, there is a race like this: Process A closes fd, releasing the lock Process B opens the same file, taking the lock Process A unlinks the lock file Process C opens the same file, which now no longer exists, and takes the lock on the newly created lock file Process B and C both 'own' the same display socket. unlink()ing while holding the lock is effectively a better way to release the lock atomically.
2012-06-30wayland-server: fix fd leak on error pathDylan Noblesmith1-8/+16
And restructure get_socket_lock() so it's clearer that it's allocating a new file descriptor. Uncovered by an upcoming test.
2012-06-30drop use of strerror()Dylan Noblesmith2-2/+2
It isn't thread-safe. Use the %m conversion specifier instead, like the rest of the code already does.