20 #include <freerdp/config.h>
30 #include <freerdp/log.h>
31 #define TAG SERVER_TAG("mac")
33 static int mf_is_event_set(mfEventQueue* event_queue)
37 struct timeval time = { 0 };
40 FD_SET(event_queue->pipe_fd[0], &rfds);
41 num_set = select(event_queue->pipe_fd[0] + 1, &rfds, 0, 0, &time);
43 return (num_set == 1);
46 static void mf_signal_event(mfEventQueue* event_queue)
50 length = write(event_queue->pipe_fd[1],
"sig", 4);
53 WLog_ERR(TAG,
"mf_signal_event: error");
56 static void mf_set_event(mfEventQueue* event_queue)
60 length = write(event_queue->pipe_fd[1],
"sig", 4);
63 WLog_ERR(TAG,
"mf_set_event: error");
66 static void mf_clear_events(mfEventQueue* event_queue)
70 while (mf_is_event_set(event_queue))
72 length = read(event_queue->pipe_fd[0], &length, 4);
75 WLog_ERR(TAG,
"mf_clear_event: error");
79 static void mf_clear_event(mfEventQueue* event_queue)
83 length = read(event_queue->pipe_fd[0], &length, 4);
86 WLog_ERR(TAG,
"mf_clear_event: error");
89 void mf_event_push(mfEventQueue* event_queue, mfEvent* event)
91 pthread_mutex_lock(&(event_queue->mutex));
93 if (event_queue->count >= event_queue->size)
95 event_queue->size *= 2;
97 (mfEvent**)realloc((
void*)event_queue->events,
sizeof(mfEvent*) * event_queue->size);
100 event_queue->events[(event_queue->count)++] = event;
102 pthread_mutex_unlock(&(event_queue->mutex));
104 mf_set_event(event_queue);
107 mfEvent* mf_event_peek(mfEventQueue* event_queue)
111 pthread_mutex_lock(&(event_queue->mutex));
113 if (event_queue->count < 1)
116 event = event_queue->events[0];
118 pthread_mutex_unlock(&(event_queue->mutex));
123 mfEvent* mf_event_pop(mfEventQueue* event_queue)
127 pthread_mutex_lock(&(event_queue->mutex));
129 if (event_queue->count < 1)
133 mf_clear_event(event_queue);
135 event = event_queue->events[0];
136 (event_queue->count)--;
138 memmove(&event_queue->events[0], &event_queue->events[1], event_queue->count *
sizeof(
void*));
140 pthread_mutex_unlock(&(event_queue->mutex));
145 mfEventRegion* mf_event_region_new(
int x,
int y,
int width,
int height)
147 mfEventRegion* event_region = malloc(
sizeof(mfEventRegion));
149 if (event_region != NULL)
153 event_region->width = width;
154 event_region->height = height;
160 void mf_event_region_free(mfEventRegion* event_region)
165 mfEvent* mf_event_new(
int type)
167 mfEvent*
event = malloc(
sizeof(mfEvent));
174 void mf_event_free(mfEvent* event)
179 mfEventQueue* mf_event_queue_new()
181 mfEventQueue* event_queue = malloc(
sizeof(mfEventQueue));
183 if (event_queue != NULL)
185 event_queue->pipe_fd[0] = -1;
186 event_queue->pipe_fd[1] = -1;
188 event_queue->size = 16;
189 event_queue->count = 0;
190 event_queue->events = (mfEvent**)malloc(
sizeof(mfEvent*) * event_queue->size);
192 if (pipe(event_queue->pipe_fd) < 0)
198 pthread_mutex_init(&(event_queue->mutex), NULL);
204 void mf_event_queue_free(mfEventQueue* event_queue)
206 if (event_queue->pipe_fd[0] != -1)
208 close(event_queue->pipe_fd[0]);
209 event_queue->pipe_fd[0] = -1;
212 if (event_queue->pipe_fd[1] != -1)
214 close(event_queue->pipe_fd[1]);
215 event_queue->pipe_fd[1] = -1;
218 pthread_mutex_destroy(&(event_queue->mutex));