00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SUBPROCESSWINDOWBUFFER_H
00016 #define SUBPROCESSWINDOWBUFFER_H
00017
00018 #include <stdio.h>
00019 #include <assert.h>
00020 #include <string>
00021 using namespace std;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class SubprocessWindowBuffer {
00043 private:
00044 void *operator new(size_t, void *addr);
00045 SubprocessWindowBuffer(int x_size, int y_size);
00046 SubprocessWindowBuffer(const SubprocessWindowBuffer ©);
00047 ~SubprocessWindowBuffer();
00048
00049 public:
00050 static SubprocessWindowBuffer *new_buffer(int &fd, size_t &mmap_size,
00051 string &filename,
00052 int x_size, int y_size);
00053 static void destroy_buffer(int fd, size_t mmap_size,
00054 const string &filename,
00055 SubprocessWindowBuffer *buffer);
00056
00057 static SubprocessWindowBuffer *open_buffer(int &fd, size_t &mmap_size,
00058 const string &filename);
00059 static void close_buffer(int fd, size_t mmap_size,
00060 const string &filename,
00061 SubprocessWindowBuffer *buffer);
00062
00063 bool verify_magic_number() const;
00064
00065 inline int get_x_size() const;
00066 inline int get_y_size() const;
00067 inline size_t get_row_size() const;
00068 inline size_t get_framebuffer_size() const;
00069
00070 inline bool ready_for_read() const;
00071 inline bool ready_for_write() const;
00072
00073 inline const void *open_read_framebuffer();
00074 inline void close_read_framebuffer();
00075 inline void *open_write_framebuffer();
00076 inline void close_write_framebuffer();
00077
00078 enum EventSource {
00079 ES_none,
00080 ES_mouse,
00081 ES_keyboard
00082 };
00083
00084 enum EventType {
00085 ET_none,
00086 ET_button_down,
00087 ET_button_up,
00088 ET_button_again,
00089 };
00090
00091 enum EventFlags {
00092 EF_has_mouse = 0x0001,
00093 EF_mouse_position = 0x0002,
00094 EF_shift_held = 0x0004,
00095 EF_control_held = 0x0008,
00096 EF_alt_held = 0x0010,
00097 EF_meta_held = 0x0020,
00098 EF_caps_lock = 0x0040,
00099 };
00100
00101 class Event {
00102 public:
00103 EventSource _source;
00104 int _code;
00105 EventType _type;
00106 int _x, _y;
00107 unsigned int _flags;
00108 };
00109
00110 inline bool add_event(const Event &event);
00111 inline bool has_event() const;
00112 inline bool get_event(Event &event);
00113
00114 private:
00115
00116
00117
00118 enum { magic_number_length = 8 };
00119 static const char _magic_number[magic_number_length];
00120 char _this_magic[magic_number_length];
00121
00122
00123
00124 size_t _mmap_size;
00125
00126
00127 int _x_size, _y_size;
00128 size_t _row_size;
00129 size_t _framebuffer_size;
00130
00131
00132 enum { max_events = 64 };
00133 int _event_in;
00134 int _event_out;
00135 Event _events[max_events];
00136
00137
00138
00139
00140
00141 int _last_written;
00142 int _last_read;
00143
00144
00145 };
00146
00147 #include "subprocessWindowBuffer.I"
00148
00149 #endif