diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/Makefile.am | 1 | ||||
-rw-r--r-- | client/audio_channels.h | 8 | ||||
-rw-r--r-- | client/client_net_socket.cpp | 8 | ||||
-rw-r--r-- | client/client_net_socket.h | 10 | ||||
-rw-r--r-- | client/cursor_channel.cpp | 2 | ||||
-rw-r--r-- | client/cursor_channel.h | 2 | ||||
-rw-r--r-- | client/display_channel.cpp | 8 | ||||
-rw-r--r-- | client/display_channel.h | 8 | ||||
-rw-r--r-- | client/events_loop.h | 86 | ||||
-rw-r--r-- | client/platform.h | 10 | ||||
-rw-r--r-- | client/record_channel.cpp | 16 | ||||
-rw-r--r-- | client/red_channel.cpp | 1 | ||||
-rw-r--r-- | client/red_channel.h | 10 | ||||
-rw-r--r-- | client/red_peer.h | 4 | ||||
-rw-r--r-- | client/screen.cpp | 2 | ||||
-rw-r--r-- | client/screen.h | 6 | ||||
-rw-r--r-- | client/tunnel_channel.cpp | 8 | ||||
-rw-r--r-- | client/windows/events_loop_p.cpp | 158 | ||||
-rw-r--r-- | client/windows/events_loop_p.h | 44 | ||||
-rw-r--r-- | client/windows/record.cpp | 4 | ||||
-rw-r--r-- | client/windows/record.h | 2 | ||||
-rw-r--r-- | client/windows/redc.vcproj | 12 | ||||
-rw-r--r-- | client/x11/Makefile.am | 3 | ||||
-rw-r--r-- | client/x11/events_loop_p.cpp | 337 | ||||
-rw-r--r-- | client/x11/events_loop_p.h | 61 | ||||
-rw-r--r-- | client/x11/record.cpp | 6 |
26 files changed, 58 insertions, 759 deletions
diff --git a/client/Makefile.am b/client/Makefile.am index 2a2d076d..b453e943 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -27,7 +27,6 @@ RED_COMMON_SRCS = \ debug.h \ display_channel.cpp \ display_channel.h \ - events_loop.h \ red_gl_canvas.cpp \ red_gl_canvas.h \ gl_canvas.cpp \ diff --git a/client/audio_channels.h b/client/audio_channels.h index 76150782..6a1c3a80 100644 --- a/client/audio_channels.h +++ b/client/audio_channels.h @@ -73,10 +73,10 @@ private: virtual void on_connect(); - virtual void add_evnet_sorce(EventsLoop::File& evnet_sorce); - virtual void remove_evnet_sorce(EventsLoop::File& evnet_sorce); - virtual void add_evnet_sorce(EventsLoop::Trigger& evnet_sorce); - virtual void remove_evnet_sorce(EventsLoop::Trigger& evnet_sorce); + virtual void add_event_source(EventSources::File& event_source); + virtual void remove_event_source(EventSources::File& event_source); + virtual void add_event_source(EventSources::Trigger& event_source); + virtual void remove_event_source(EventSources::Trigger& event_source); virtual void push_frame(uint8_t *frame); void send_start_mark(); diff --git a/client/client_net_socket.cpp b/client/client_net_socket.cpp index 50174795..312d6bf8 100644 --- a/client/client_net_socket.cpp +++ b/client/client_net_socket.cpp @@ -26,12 +26,12 @@ #include "utils.h" ClientNetSocket::ClientNetSocket(uint16_t id, const struct in_addr& dst_addr, uint16_t dst_port, - EventsLoop& events_loop, EventHandler& event_handler) + ProcessLoop& process_loop, EventHandler& event_handler) : _id (id) , _local_addr (dst_addr) , _local_port (dst_port) , _peer (INVALID_SOCKET) - , _events_loop (events_loop) + , _process_loop (process_loop) , _event_handler (event_handler) , _num_recv_tokens (0) , _send_message (NULL) @@ -82,7 +82,7 @@ bool ClientNetSocket::connect(uint32_t recv_tokens) return false; } - _events_loop.add_socket(*this); + _process_loop.add_socket(*this); _status = SOCKET_STATUS_OPEN; _num_recv_tokens = recv_tokens; return true; @@ -374,7 +374,7 @@ void ClientNetSocket::close_and_tell() void ClientNetSocket::apply_disconnect() { if (_peer != INVALID_SOCKET) { - _events_loop.remove_socket(*this); + _process_loop.remove_socket(*this); closesocket(_peer); _peer = INVALID_SOCKET; LOG_INFO("closing connection_id=%d", _id); diff --git a/client/client_net_socket.h b/client/client_net_socket.h index 8ca1cfcf..578cd400 100644 --- a/client/client_net_socket.h +++ b/client/client_net_socket.h @@ -23,7 +23,7 @@ #include "platform_utils.h" #include "common.h" -#include "events_loop.h" +#include "process_loop.h" /* intterface for connenctions inside client LAN */ @@ -34,7 +34,7 @@ typedef enum { SOCKET_STATUS_CLOSED, } SocketStatus; -class ClientNetSocket: public EventsLoop::Socket { +class ClientNetSocket: public EventSources::Socket { public: class ReceiveBuffer; class SendBuffer; @@ -46,7 +46,7 @@ public: class ShutdownExcpetion {}; ClientNetSocket(uint16_t id, const struct in_addr& dst_addr, uint16_t dst_port, - EventsLoop& events_loop, ClientNetSocket::EventHandler& event_handler); + ProcessLoop& process_loop, ClientNetSocket::EventHandler& event_handler); virtual ~ClientNetSocket(); bool connect(uint32_t recv_tokens); @@ -61,7 +61,7 @@ public: inline const struct in_addr& local_addr() {return _local_addr;} inline uint16_t local_port() {return _local_port;} - /* EventsLoop::Socket interface */ + /* EventSources::Socket interface */ void on_event(); int get_socket() {return _peer;} @@ -98,7 +98,7 @@ private: SOCKET _peer; - EventsLoop& _events_loop; + ProcessLoop& _process_loop; EventHandler& _event_handler; diff --git a/client/cursor_channel.cpp b/client/cursor_channel.cpp index d5a64b2b..fd8761a6 100644 --- a/client/cursor_channel.cpp +++ b/client/cursor_channel.cpp @@ -524,7 +524,7 @@ CursorChannel::CursorChannel(RedClient& client, uint32_t id) sizeof(RedInvalOne)); handler->set_handler(RED_CURSOR_INVAL_ALL, &CursorChannel::handle_inval_all, 0); - get_events_loop().add_trigger(_cursor_trigger); + get_process_loop().add_trigger(_cursor_trigger); } CursorChannel::~CursorChannel() diff --git a/client/cursor_channel.h b/client/cursor_channel.h index 830b57f1..5ac40c10 100644 --- a/client/cursor_channel.h +++ b/client/cursor_channel.h @@ -43,7 +43,7 @@ public: typedef Cache<CursorData, CursorCacheTreat, 1024> CursorCache; -class CursorModeTrigger: public EventsLoop::Trigger { +class CursorModeTrigger: public EventSources::Trigger { public: CursorModeTrigger(CursorChannel& channel); virtual void on_event(); diff --git a/client/display_channel.cpp b/client/display_channel.cpp index e9d4f192..22da9948 100644 --- a/client/display_channel.cpp +++ b/client/display_channel.cpp @@ -571,7 +571,7 @@ GLInterruptRecreate::GLInterruptRecreate(DisplayChannel& channel) void GLInterruptRecreate::trigger() { Lock lock(_lock); - EventsLoop::Trigger::trigger(); + EventSources::Trigger::trigger(); _cond.wait(lock); } @@ -654,11 +654,11 @@ DisplayChannel::DisplayChannel(RedClient& client, uint32_t id, handler->set_handler(RED_DISPLAY_STREAM_DESTROY_ALL, &DisplayChannel::handle_stream_destroy_all, 0); - get_events_loop().add_trigger(_streams_trigger); + get_process_loop().add_trigger(_streams_trigger); #ifdef USE_OGL - get_events_loop().add_trigger(_gl_interrupt_recreate); + get_process_loop().add_trigger(_gl_interrupt_recreate); #endif - get_events_loop().add_trigger(_interrupt_update); + get_process_loop().add_trigger(_interrupt_update); } DisplayChannel::~DisplayChannel() diff --git a/client/display_channel.h b/client/display_channel.h index 894c604f..59dc6a61 100644 --- a/client/display_channel.h +++ b/client/display_channel.h @@ -25,7 +25,7 @@ #include "cairo.h" #include "cache.hpp" #include "screen_layer.h" -#include "events_loop.h" +#include "process_loop.h" #ifdef USE_OGL #include "red_pixmap_gl.h" #endif @@ -36,7 +36,7 @@ class ChannelFactory; class VideoStream; class DisplayChannel; -class StreamsTrigger: public EventsLoop::Trigger { +class StreamsTrigger: public EventSources::Trigger { public: StreamsTrigger(DisplayChannel& channel); @@ -47,7 +47,7 @@ private: }; #ifdef USE_OGL -class GLInterruptRecreate: public EventsLoop::Trigger { +class GLInterruptRecreate: public EventSources::Trigger { public: GLInterruptRecreate(DisplayChannel& channel); virtual void trigger(); @@ -60,7 +60,7 @@ private: }; #endif -class InterruptUpdate: public EventsLoop::Trigger { +class InterruptUpdate: public EventSources::Trigger { public: InterruptUpdate(DisplayChannel& channel); diff --git a/client/events_loop.h b/client/events_loop.h deleted file mode 100644 index ac26a0e6..00000000 --- a/client/events_loop.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (C) 2009 Red Hat, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _H_EVENTS_LOOP -#define _H_EVENTS_LOOP - -#include "common.h" -#include "events_loop_p.h" - -class EventSourceOld; - -class EventsLoop: public EventsLoop_p { -public: - class Trigger; - class Socket; - class File; - - EventsLoop(); - virtual ~EventsLoop(); - - void add_trigger(Trigger& trigger); - void remove_trigger(Trigger& trigger); - void add_socket(Socket& socket); - void remove_socket(Socket& socket); - void add_file(File& file); - void remove_file(File& file); - void run(); - // FIXME: temporary - need to adjust the loop for the main thread - void run_once(int timeout_milli = INFINITE); -}; - -class EventSourceOld { -public: - virtual ~EventSourceOld() {} - virtual void on_event() = 0; - -private: - virtual void action() {on_event();} - - friend class EventsLoop; -}; - -class EventsLoop::Trigger: public EventSourceOld, private EventsLoop_p::Trigger_p { -public: - Trigger(); - virtual ~Trigger(); - virtual void trigger(); - virtual void reset(); - -private: - virtual void action(); - - friend class EventsLoop; -}; - -class EventsLoop::Socket: public EventSourceOld { -protected: - virtual int get_socket() = 0; - - friend class EventsLoop; -}; - - -class EventsLoop::File: public EventSourceOld { -protected: - virtual int get_fd() = 0; - - friend class EventsLoop; -}; - -#endif - diff --git a/client/platform.h b/client/platform.h index a4310d98..ef527d38 100644 --- a/client/platform.h +++ b/client/platform.h @@ -21,7 +21,7 @@ #include "cursor.h" #include "process_loop.h" #include "event_sources.h" -#include "events_loop.h" +#include "process_loop.h" class WaveRecordAbstract; class WavePlaybackAbstract; @@ -118,10 +118,10 @@ public: class Platform::RecordClinet { public: virtual ~RecordClinet() {} - virtual void add_evnet_sorce(EventsLoop::File& evnet_sorce) = 0; - virtual void remove_evnet_sorce(EventsLoop::File& evnet_sorce) = 0; - virtual void add_evnet_sorce(EventsLoop::Trigger& evnet_sorce) = 0; - virtual void remove_evnet_sorce(EventsLoop::Trigger& evnet_sorce) = 0; + virtual void add_event_source(EventSources::File& evnet_source) = 0; + virtual void remove_event_source(EventSources::File& evnet_source) = 0; + virtual void add_event_source(EventSources::Trigger& evnet_source) = 0; + virtual void remove_event_source(EventSources::Trigger& evnet_source) = 0; virtual void push_frame(uint8_t *frame) = 0; }; diff --git a/client/record_channel.cpp b/client/record_channel.cpp index 5bba1dbb..d905ff6e 100644 --- a/client/record_channel.cpp +++ b/client/record_channel.cpp @@ -209,24 +209,24 @@ void RecordChannel::release_message(RecordSamplesMessage *message) _messages.push_front(message); } -void RecordChannel::add_evnet_sorce(EventsLoop::File& evnet_sorce) +void RecordChannel::add_event_source(EventSources::File& event_source) { - get_events_loop().add_file(evnet_sorce); + get_process_loop().add_file(event_source); } -void RecordChannel::remove_evnet_sorce(EventsLoop::File& evnet_sorce) +void RecordChannel::remove_event_source(EventSources::File& event_source) { - get_events_loop().remove_file(evnet_sorce); + get_process_loop().remove_file(event_source); } -void RecordChannel::add_evnet_sorce(EventsLoop::Trigger& evnet_sorce) +void RecordChannel::add_event_source(EventSources::Trigger& event_source) { - get_events_loop().add_trigger(evnet_sorce); + get_process_loop().add_trigger(event_source); } -void RecordChannel::remove_evnet_sorce(EventsLoop::Trigger& evnet_sorce) +void RecordChannel::remove_event_source(EventSources::Trigger& event_source) { - get_events_loop().remove_trigger(evnet_sorce); + get_process_loop().remove_trigger(event_source); } #define FRAME_SIZE 256 diff --git a/client/red_channel.cpp b/client/red_channel.cpp index a82d9f77..cfd47057 100644 --- a/client/red_channel.cpp +++ b/client/red_channel.cpp @@ -254,6 +254,7 @@ RedChannel::RedChannel(RedClient& client, uint8_t type, uint8_t id, , _incomming_message (NULL) , _message_ack_count (0) , _message_ack_window (0) + , _loop (this) , _send_trigger (*this) , _disconnect_stamp (0) , _disconnect_reason (RED_ERR_OK) diff --git a/client/red_channel.h b/client/red_channel.h index 0ffe051a..670d6521 100644 --- a/client/red_channel.h +++ b/client/red_channel.h @@ -23,7 +23,7 @@ #include "threads.h" #include "red_peer.h" #include "platform.h" -#include "events_loop.h" +#include "process_loop.h" enum { PASSIVE_STATE, @@ -85,7 +85,7 @@ private: ChannelCaps _remote_caps; }; -class SendTrigger: public EventsLoop::Trigger { +class SendTrigger: public EventSources::Trigger { public: SendTrigger(RedChannel& channel); @@ -95,7 +95,7 @@ private: RedChannel& _channel; }; -class AbortTrigger: public EventsLoop::Trigger { +class AbortTrigger: public EventSources::Trigger { public: virtual void on_event(); }; @@ -129,7 +129,7 @@ public: protected: RedClient& get_client() { return _client;} - EventsLoop& get_events_loop() { return _loop;} + ProcessLoop& get_process_loop() { return _loop;} MessageHandler* get_message_handler() { return _message_handler.get();} virtual void on_connecting() {} virtual void on_connect() {} @@ -188,7 +188,7 @@ private: uint32_t _message_ack_count; uint32_t _message_ack_window; - EventsLoop _loop; + ProcessLoop _loop; SendTrigger _send_trigger; AbortTrigger _abort_trigger; diff --git a/client/red_peer.h b/client/red_peer.h index eb0597d8..2a53eae8 100644 --- a/client/red_peer.h +++ b/client/red_peer.h @@ -23,11 +23,11 @@ #include "common.h" #include "red.h" -#include "events_loop.h" +#include "process_loop.h" #include "threads.h" #include "platform_utils.h" -class RedPeer: protected EventsLoop::Socket { +class RedPeer: protected EventSources::Socket { public: RedPeer(); virtual ~RedPeer(); diff --git a/client/screen.cpp b/client/screen.cpp index 5d138a1c..b79e2a18 100644 --- a/client/screen.cpp +++ b/client/screen.cpp @@ -751,7 +751,7 @@ bool RedScreen::need_recreate_context_gl() #endif -void RedScreen::set_update_interrupt_trigger(EventsLoop::Trigger *trigger) +void RedScreen::set_update_interrupt_trigger(EventSources::Trigger *trigger) { _update_interrupt_trigger = trigger; } diff --git a/client/screen.h b/client/screen.h index 761ae244..3e2ffdb4 100644 --- a/client/screen.h +++ b/client/screen.h @@ -25,7 +25,7 @@ #include "red_window.h" #include "platform.h" -#include "events_loop.h" +#include "process_loop.h" #include "threads.h" class Application; @@ -78,7 +78,7 @@ public: void untouch_context(); bool need_recreate_context_gl(); #endif - void set_update_interrupt_trigger(EventsLoop::Trigger *trigger); + void set_update_interrupt_trigger(EventSources::Trigger *trigger); bool update_by_interrupt(); void interrupt_update(); void set_type_gl(); @@ -174,7 +174,7 @@ private: }; PointerLocation _pointer_location; int _pixel_format_index; - EventsLoop::Trigger *_update_interrupt_trigger; + EventSources::Trigger *_update_interrupt_trigger; }; #endif diff --git a/client/tunnel_channel.cpp b/client/tunnel_channel.cpp index 5da18f56..08556c67 100644 --- a/client/tunnel_channel.cpp +++ b/client/tunnel_channel.cpp @@ -185,7 +185,7 @@ struct TunnelService { class TunnelChannel::TunnelSocket: public ClientNetSocket { public: - TunnelSocket(uint16_t id, TunnelService & dst_service, EventsLoop & events_loop, + TunnelSocket(uint16_t id, TunnelService& dst_service, ProcessLoop& process_loop, EventHandler & event_handler); virtual ~TunnelSocket() {} @@ -208,10 +208,10 @@ private: }; TunnelChannel::TunnelSocket::TunnelSocket(uint16_t id, TunnelService& dst_service, - EventsLoop& events_loop, + ProcessLoop& process_loop, ClientNetSocket::EventHandler& event_handler) : ClientNetSocket(id, dst_service.ip, htons((uint16_t)dst_service.port), - events_loop, event_handler) + process_loop, event_handler) , _num_tokens (0) , _server_num_tokens (0) , _service_id (dst_service.id) @@ -356,7 +356,7 @@ void TunnelChannel::handle_socket_open(RedPeer::InMessage* message) open_msg->service_id); } - sckt = new TunnelSocket(open_msg->connection_id, *service, get_events_loop(), *this); + sckt = new TunnelSocket(open_msg->connection_id, *service, get_process_loop(), *this); if (sckt->connect(open_msg->tokens)) { _sockets[open_msg->connection_id] = sckt; diff --git a/client/windows/events_loop_p.cpp b/client/windows/events_loop_p.cpp deleted file mode 100644 index 7329d161..00000000 --- a/client/windows/events_loop_p.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - Copyright (C) 2009 Red Hat, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "common.h" -#include "events_loop.h" -#include "debug.h" -#include "utils.h" - - -EventsLoop::EventsLoop() -{ -} - -EventsLoop::~EventsLoop() -{ -} - -void EventsLoop::run() -{ - for (;;) { - run_once(); - } -} - -void EventsLoop::run_once(int timeout_milli) -{ - DWORD wait_res = WaitForMultipleObjects(_handles.size(), &_handles[0], FALSE, timeout_milli); - if (wait_res == WAIT_FAILED) { - THROW("wait failed"); - } - int event_index = wait_res - WAIT_OBJECT_0; - if (event_index < 0 || event_index >= (int)_events.size()) { - THROW("invalid event id"); - } - _events[event_index]->action(); -} - -void EventsLoop::add_socket(Socket& socket) -{ - HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!event) { - THROW("create event failed"); - } - if (WSAEventSelect(socket.get_socket(), event, FD_READ | FD_WRITE | FD_CLOSE) == SOCKET_ERROR) { - CloseHandle(event); - THROW("event select failed"); - } - int size = _events.size(); - _events.resize(size + 1); - _handles.resize(size + 1); - _events[size] = &socket; - _handles[size] = event; -} - -void EventsLoop::remove_socket(Socket& socket) -{ - int size = _events.size(); - for (int i = 0; i < size; i++) { - if (_events[i] == &socket) { - if (WSAEventSelect(socket.get_socket(), NULL, 0) == SOCKET_ERROR) { - THROW("event select failed"); - } - u_long arg = 0; - if (ioctlsocket(socket.get_socket(), FIONBIO, &arg) == SOCKET_ERROR) { - THROW("set blocking mode failed"); - } - CloseHandle(_handles[i]); - for (i++; i < size; i++) { - _events[i - 1] = _events[i]; - _handles[i - 1] = _handles[i]; - } - _events.resize(size - 1); - _handles.resize(size - 1); - return; - } - } - THROW("socket not found"); -} - -void EventsLoop::add_trigger(Trigger& trigger) -{ - int size = _events.size(); - _events.resize(size + 1); - _handles.resize(size + 1); - _events[size] = &trigger; - _handles[size] = trigger.get_handle(); -} - -void EventsLoop::remove_trigger(Trigger& trigger) -{ - int size = _events.size(); - for (int i = 0; i < size; i++) { - if (_events[i] == &trigger) { - for (i++; i < size; i++) { - _events[i - 1] = _events[i]; - _handles[i - 1] = _handles[i]; - } - _events.resize(size - 1); - _handles.resize(size - 1); - return; - } - } - THROW("trigger not found"); -} - -EventsLoop::Trigger::Trigger() -{ - if (!(event = CreateEvent(NULL, FALSE, FALSE, NULL))) { - THROW("create event failed"); - } -} - -EventsLoop::Trigger::~Trigger() -{ - CloseHandle(event); -} - -void EventsLoop::Trigger::trigger() -{ - if (!SetEvent(event)) { - THROW("set event failed"); - } -} - -void EventsLoop::Trigger::reset() -{ - if (!ResetEvent(event)) { - THROW("set event failed"); - } -} - -void EventsLoop::Trigger::action() -{ - on_event(); -} - -void EventsLoop::add_file(File& file) -{ -} - -void EventsLoop::remove_file(File& file) -{ -} - diff --git a/client/windows/events_loop_p.h b/client/windows/events_loop_p.h deleted file mode 100644 index 6bac7b94..00000000 --- a/client/windows/events_loop_p.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2009 Red Hat, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _H_EVENTS_LOOP_P -#define _H_EVENTS_LOOP_P - -#include "common.h" - -#include <vector> - -class EventSourceOld; - -class EventsLoop_p { -public: - class Trigger_p; -public: - std::vector<EventSourceOld*> _events; - std::vector<HANDLE> _handles; -}; - -class EventsLoop_p::Trigger_p { -public: - HANDLE get_handle() { return event;} - -public: - HANDLE event; -}; - -#endif - diff --git a/client/windows/record.cpp b/client/windows/record.cpp index 52fc478e..bd9bc022 100644 --- a/client/windows/record.cpp +++ b/client/windows/record.cpp @@ -61,7 +61,7 @@ WaveRecorder::WaveRecorder(Platform::RecordClinet& client, uint32_t sampels_per_ _frame_pos = _frame; _frame_end = _frame + frame_bytes; init_ring(sampels_per_sec, frame_bytes, frame_align); - _client.add_evnet_sorce(*this); + _client.add_event_source(*this); } catch (...) { delete[] _ring; delete[] _frame; @@ -74,7 +74,7 @@ WaveRecorder::~WaveRecorder() { waveInReset(_wave_in); reclaim(); - _client.remove_evnet_sorce(*this); + _client.remove_event_source(*this); waveInClose(_wave_in); delete[] _ring; delete[] _frame; diff --git a/client/windows/record.h b/client/windows/record.h index dab69fa0..cd33a2aa 100644 --- a/client/windows/record.h +++ b/client/windows/record.h @@ -21,7 +21,7 @@ #include "audio_devices.h" #include "platform.h" -class WaveRecorder: public WaveRecordAbstract, public EventsLoop::Trigger { +class WaveRecorder: public WaveRecordAbstract, public EventSources::Trigger { public: WaveRecorder(Platform::RecordClinet& client, uint32_t sampels_per_sec, uint32_t bits_per_sample, uint32_t channels); diff --git a/client/windows/redc.vcproj b/client/windows/redc.vcproj index c63e1f1c..8df2214c 100644 --- a/client/windows/redc.vcproj +++ b/client/windows/redc.vcproj @@ -229,10 +229,6 @@ >
</File>
<File
- RelativePath=".\events_loop_p.cpp"
- >
- </File>
- <File
RelativePath="..\gdi_canvas.cpp"
>
</File>
@@ -453,14 +449,6 @@ >
</File>
<File
- RelativePath="..\events_loop.h"
- >
- </File>
- <File
- RelativePath=".\events_loop_p.h"
- >
- </File>
- <File
RelativePath="..\..\common\gdi_canvas.h"
>
</File>
diff --git a/client/x11/Makefile.am b/client/x11/Makefile.am index fffd36c8..99f0c26a 100644 --- a/client/x11/Makefile.am +++ b/client/x11/Makefile.am @@ -50,7 +50,6 @@ RED_COMMON_SRCS = \ $(top_srcdir)/client/debug.h \ $(top_srcdir)/client/display_channel.cpp \ $(top_srcdir)/client/display_channel.h \ - $(top_srcdir)/client/events_loop.h \ $(top_srcdir)/client/red_gl_canvas.cpp \ $(top_srcdir)/client/red_gl_canvas.h \ $(top_srcdir)/client/gl_canvas.cpp \ @@ -109,8 +108,6 @@ bin_PROGRAMS = spicec spicec_SOURCES = \ atomic_count.h \ - events_loop_p.cpp \ - events_loop_p.h \ event_sources_p.cpp \ main.cpp \ named_pipe.h \ diff --git a/client/x11/events_loop_p.cpp b/client/x11/events_loop_p.cpp deleted file mode 100644 index a1c450b5..00000000 --- a/client/x11/events_loop_p.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/* - Copyright (C) 2009 Red Hat, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <sys/epoll.h> -#include <sys/fcntl.h> - -#include "events_loop.h" -#include "debug.h" -#include "utils.h" - -#ifdef USING_EVENT_FD -#include <sys/eventfd.h> -#endif - -#define NUM_EPOLL_EVENTS 10 - -#ifdef USING_EVENT_FD -#define WRITE_FD _event_fd -#define EVENT_DATA_TYPE eventfd_t -#else -#define WRITE_FD _event_write_fd -#define EVENT_DATA_TYPE uint8_t -#endif - -class EventWrapper { -public: - EventWrapper(EventsLoop& owner, EventSourceOld& event) - : _owner (owner) - , _event (&event) - , _refs (1) - { - } - - EventWrapper* ref() - { - _refs++; - return this; - } - - void unref() - { - if (!--_refs) { - _owner.remove_wrapper(this); - delete this; - } - } - - EventSourceOld* get_event() - { - return _event; - } - - void invalidate() - { - _event = NULL; - } - -private: - EventsLoop& _owner; - EventSourceOld* _event; - int _refs; -}; - -EventsLoop::EventsLoop() -{ - _epoll = epoll_create(NUM_EPOLL_EVENTS); - if (_epoll == -1) { - THROW("create epool failed"); - } -} - -EventsLoop::~EventsLoop() -{ - Events::iterator iter = _events.begin(); - for (; iter != _events.end(); iter++) { - delete *iter; - } - close(_epoll); -} - -void EventsLoop::run() -{ - for (;;) { - run_once(); - } -} - -void EventsLoop::run_once(int timeout_milli) -{ - struct epoll_event events[NUM_EPOLL_EVENTS]; - - int num_events = epoll_wait(_epoll, events, NUM_EPOLL_EVENTS, timeout_milli); - if (num_events == -1) { - if (errno == EINTR) { - return; - } - THROW("wait error eventfd failed"); - } - - for (int i = 0; i < num_events; i++) { - ((EventWrapper*)events[i].data.ptr)->ref(); - } - for (int i = 0; i < num_events; i++) { - EventWrapper* wrapper; - EventSourceOld* event; - - wrapper = (EventWrapper *)events[i].data.ptr; - if ((event = wrapper->get_event())) { - event->action(); - } - wrapper->unref(); - } -} - -void EventsLoop::add_trigger(Trigger& trigger) -{ - int fd = trigger.get_fd(); - EventWrapper* wrapper = new EventWrapper(*this, trigger); - struct epoll_event event; - event.data.ptr = wrapper; - event.events = EPOLLIN; - if (epoll_ctl(_epoll, EPOLL_CTL_ADD, fd, &event) == -1) { - THROW("epoll add failed"); - } - _events.push_back(wrapper); -} - -void EventsLoop_p::remove_wrapper(EventWrapper* wrapper) -{ - Events::iterator iter = _events.begin(); - for (;; iter++) { - if (iter == _events.end()) { - THROW("wrapper not found"); - } - if ((*iter) == wrapper) { - _events.erase(iter); - return; - } - } -} - -void EventsLoop::remove_trigger(Trigger& trigger) -{ - Events::iterator iter = _events.begin(); - for (;; iter++) { - if (iter == _events.end()) { - THROW("trigger not found"); - } - if ((*iter)->get_event() == &trigger) { - (*iter)->invalidate(); - (*iter)->unref(); - break; - } - } - int fd = trigger.get_fd(); - if (epoll_ctl(_epoll, EPOLL_CTL_DEL, fd, NULL) == -1) { - THROW("epoll remove failed"); - } -} - -EventsLoop::Trigger::Trigger() -{ -#ifdef USING_EVENT_FD - _event_fd = eventfd(0, 0); - if (_event_fd == -1) { - THROW("create eventfd failed"); - } -#else - int fd[2]; - if (pipe(fd) == -1) { - THROW("create pipe failed"); - } - _event_fd = fd[0]; - _event_write_fd = fd[1]; -#endif - int flags; - if ((flags = fcntl(_event_fd, F_GETFL)) == -1) { - THROW("failed to set eventfd non block: %s", strerror(errno)); - } - - if (fcntl(_event_fd, F_SETFL, flags | O_NONBLOCK) == -1) { - THROW("failed to set eventfd non block: %s", strerror(errno)); - } -} - -EventsLoop::Trigger::~Trigger() -{ - close(_event_fd); -#ifndef USING_EVENT_FD - close(_event_write_fd); -#endif -} - -void EventsLoop::Trigger::trigger() -{ - Lock lock(_lock); - if (_pending_int) { - return; - } - _pending_int = true; - static const EVENT_DATA_TYPE val = 1; - if (::write(WRITE_FD, &val, sizeof(val)) != sizeof(val)) { - THROW("write event failed"); - } -} - -bool EventsLoop_p::Trigger_p::reset_event() -{ - Lock lock(_lock); - if (!_pending_int) { - return false; - } - EVENT_DATA_TYPE val; - if (read(_event_fd, &val, sizeof(val)) != sizeof(val)) { - THROW("event read error"); - } - _pending_int = false; - return true; -} - -void EventsLoop::Trigger::reset() -{ - reset_event(); -} - -void EventsLoop::Trigger::action() -{ - if (reset_event()) { - on_event(); - } -} - -static void set_non_blocking(int fd) -{ - int flags; - if ((flags = fcntl(fd, F_GETFL)) == -1) { - THROW("failed to set socket non block: %s", strerror(errno)); - } - - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - THROW("failed to set socket non block: %s", strerror(errno)); - } -} - -static void set_blocking(int fd) -{ - int flags; - if ((flags = fcntl(fd, F_GETFL)) == -1) { - THROW("failed to clear socket non block: %s", strerror(errno)); - } - - if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1) { - THROW("failed to clear socket non block: %s", strerror(errno)); - } -} - -static void add_to_poll(int fd, int epoll, EventWrapper* wrapper) -{ - struct epoll_event event; - event.data.ptr = wrapper; - event.events = EPOLLIN | EPOLLOUT | EPOLLET; - if (epoll_ctl(epoll, EPOLL_CTL_ADD, fd, &event) == -1) { - THROW("epoll add failed"); - } -} - -void EventsLoop::add_socket(Socket& socket) -{ - int fd = socket.get_socket(); - set_non_blocking(fd); - EventWrapper* wrapper = new EventWrapper(*this, socket); - add_to_poll(fd, _epoll, wrapper); - _events.push_back(wrapper); -} - -static bool remove_event(EventsLoop_p::Events& events, EventSourceOld& event) -{ - EventsLoop_p::Events::iterator iter = events.begin(); - for (;; iter++) { - if (iter == events.end()) { - return false; - } - if ((*iter)->get_event() == &event) { - (*iter)->invalidate(); - (*iter)->unref(); - return true; - } - } -} - -void EventsLoop::remove_socket(Socket& socket) -{ - if (!remove_event(_events, socket)) { - THROW("socket not found"); - } - int fd = socket.get_socket(); - if (epoll_ctl(_epoll, EPOLL_CTL_DEL, fd, NULL) == -1) { - THROW("epoll remove failed"); - } - set_blocking(fd); -} - -void EventsLoop::add_file(File& file) -{ - int fd = file.get_fd(); - set_non_blocking(fd); - EventWrapper* wrapper = new EventWrapper(*this, file); - add_to_poll(fd, _epoll, wrapper); - _events.push_back(wrapper); -} - -void EventsLoop::remove_file(File& file) -{ - if (!remove_event(_events, file)) { - THROW("file not found"); - } - int fd = file.get_fd(); - if (epoll_ctl(_epoll, EPOLL_CTL_DEL, fd, NULL) == -1) { - THROW("epoll remove failed"); - } - set_blocking(fd); -} - diff --git a/client/x11/events_loop_p.h b/client/x11/events_loop_p.h deleted file mode 100644 index d339ca4b..00000000 --- a/client/x11/events_loop_p.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (C) 2009 Red Hat, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _H_EVENTS_LOOP_P -#define _H_EVENTS_LOOP_P - -#include "common.h" -#include "threads.h" - -#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) -#define USING_EVENT_FD -#endif - -#define INFINITE -1 - -class EventWrapper; - -class EventsLoop_p { -public: - class Trigger_p; - void remove_wrapper(EventWrapper*); - -public: - int _epoll; - typedef std::list<EventWrapper*> Events; - Events _events; - - friend class EventWrapper; -}; - -class EventsLoop_p::Trigger_p { -public: - Trigger_p() : _pending_int (false) {} - int get_fd() { return _event_fd;} - bool reset_event(); - -public: - int _event_fd; -#ifndef USING_EVENT_FD - int _event_write_fd; -#endif - bool _pending_int; - Mutex _lock; -}; - -#endif - diff --git a/client/x11/record.cpp b/client/x11/record.cpp index b68e2130..a220878c 100644 --- a/client/x11/record.cpp +++ b/client/x11/record.cpp @@ -20,7 +20,7 @@ #include "debug.h" -class WaveRecorder::EventTrigger: public EventsLoop::File { +class WaveRecorder::EventTrigger: public EventSources::File { public: EventTrigger(WaveRecorder& recorder, int fd); virtual void on_event(); @@ -71,7 +71,7 @@ WaveRecorder::~WaveRecorder() void WaveRecorder::cleanup() { if (_event_trigger) { - _client.remove_evnet_sorce(*_event_trigger); + _client.remove_event_source(*_event_trigger); delete _event_trigger; } @@ -194,7 +194,7 @@ bool WaveRecorder::init(uint32_t sampels_per_sec, return false; } _event_trigger = new WaveRecorder::EventTrigger(*this, pfd.fd); - _client.add_evnet_sorce(*_event_trigger); + _client.add_event_source(*_event_trigger); return true; } |