spice/client/events_loop.h
Yonit Halperin 8d5b738ba1 spice client: creating a general process loop.
The process loop is responsible for: 1) waiting for events 2) timers 3) events queue for
actions that should be performed in the context of the thread and are pushed from other threads.
The benefits:
1) remove duplicity: till now, there was one implementaion of events loop for the channels and
another one for the main thread.
2) timers can be executed on each thread and not only on the main thread.
3) events can be pushed to each thread and not only to the main thread.
In this commit, only the main thread was modified to use the new process loop.
2009-11-09 14:39:33 +02:00

87 lines
2.0 KiB
C++

/*
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