/* if mouse event is wheelup ,wheeldown or move
then go to ps2 mouse event(index == 0) */
if((buttons_state > 3 && entry->index == 0)) {
- INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
+ //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
buttons_state = 0;
mouse_event = entry->qemu_put_mouse_event;
mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
entry = QTAILQ_FIRST(&mouse_handlers);
mouse_event = entry->qemu_put_mouse_event;
mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
- INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
+ //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state);
}
#else
entry = QTAILQ_FIRST(&mouse_handlers);
#include "console.h"
#include "maru_virtio_touchscreen.h"
#include "maru_device_ids.h"
+#include "mloop_event.h"
#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(qemu, touchscreen);
#define DEVICE_NAME "virtio-touchscreen"
-#define MAX_TOUCH_EVENT_CNT 128
+#define MAX_TOUCH_EVENT_CNT 16
/* This structure must match the kernel definitions */
typedef struct EmulTouchEvent {
TouchscreenState *ts;
-// lock for between communication thread and IO thread
-//static pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER;
+/* lock for between communication thread and IO thread */
+static pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER;
void virtio_touchscreen_event(void *opaque, int x, int y, int z, int buttons_state)
{
TouchEventEntry *entry = NULL;
- TouchscreenState *ts = opaque;
- VirtQueueElement elem;
- //pthread_mutex_lock(&event_mutex);
+ pthread_mutex_lock(&event_mutex);
-#if 0
if (queue_cnt >= MAX_TOUCH_EVENT_CNT) {
pthread_mutex_unlock(&event_mutex);
INFO("full touch event queue, lose event\n", queue_cnt);
return;
}
-#endif
entry = &(_events_buf[ringbuf_cnt % MAX_TOUCH_EVENT_CNT]);
ringbuf_cnt++;
entry->touch.z = z;
entry->touch.state = buttons_state;
- //QTAILQ_INSERT_TAIL(&events_queue, entry, node);
+ QTAILQ_INSERT_TAIL(&events_queue, entry, node);
- /* virtio */
- virtqueue_pop(ts->vq, &elem);
- memcpy(elem.in_sg[0].iov_base, &(entry->touch), sizeof(EmulTouchEvent));
- virtqueue_push(ts->vq, &elem, 0);
- virtio_notify(&(ts->vdev), ts->vq);
+ pthread_mutex_unlock(&event_mutex);
- //pthread_mutex_unlock(&event_mutex);
+ mloop_evcmd_touch();
INFO("touch event (%d) : x=%d, y=%d, z=%d, state=%d\n",
entry->index, entry->touch.x, entry->touch.y, entry->touch.z, entry->touch.state);
}
+void maru_virtio_touchscreen_notify(void)
+{
+ TouchEventEntry *entry = NULL;
+ VirtQueueElement elem;
+
+ INFO("maru_virtio_touchscreen_notify\n");
+
+ /* get from virtio queue */
+ virtqueue_pop(ts->vq, &elem);
+
+ pthread_mutex_lock(&event_mutex);
+
+ /* get from host event queue */
+ entry = QTAILQ_FIRST(&events_queue);
+ /* copy host event into virtio queue */
+ memcpy(elem.in_sg[0].iov_base, &(entry->touch), sizeof(EmulTouchEvent));
+ /* remove host event */
+ QTAILQ_REMOVE(&events_queue, entry, node);
+ queue_cnt--;
+
+ pthread_mutex_unlock(&event_mutex);
+
+ /* put into virtio queue */
+ virtqueue_push(ts->vq, &elem, 0);
+ /* notify to guest */
+ virtio_notify(&(ts->vdev), ts->vq);
+}
+
static uint32_t virtio_touchscreen_get_features(VirtIODevice *vdev, uint32_t request_features)
{
// TODO:
#define MLOOP_EVTYPE_USB_DEL 2
#define MLOOP_EVTYPE_INTR_UP 3
#define MLOOP_EVTYPE_INTR_DOWN 4
-#define MLLOP_EVTYPE_HWKEY 5
+#define MLOOP_EVTYPE_HWKEY 5
+#define MLOOP_EVTYPE_TOUCH 6
-static struct mloop_evsock mloop = {-1,0,0};
+
+static struct mloop_evsock mloop = {-1, 0, 0};
static int mloop_evsock_create(struct mloop_evsock *ev)
{
static void mloop_evhandle_hwkey(struct mloop_evpack* pack)
{
- int event_type;
- int keycode;
+ int event_type = 0;
+ int keycode = 0;
memcpy(&event_type, pack->data, sizeof(int));
memcpy(&keycode, pack->data + sizeof(int), sizeof(int));
}
}
+static void mloop_evhandle_touch(struct mloop_evpack* pack)
+{
+ maru_virtio_touchscreen_notify();
+}
+
static void mloop_evcb_recv(struct mloop_evsock *ev)
{
struct mloop_evpack pack;
case MLOOP_EVTYPE_INTR_DOWN:
mloop_evhandle_intr_down(ntohl(*(long*)&pack.data[0]));
break;
- case MLLOP_EVTYPE_HWKEY:
+ case MLOOP_EVTYPE_HWKEY:
mloop_evhandle_hwkey(&pack);
break;
+ case MLOOP_EVTYPE_TOUCH:
+ mloop_evhandle_touch(&pack);
+ break;
default:
break;
}
{
struct mloop_evpack pack;
- pack.type = htons(MLLOP_EVTYPE_HWKEY);
+ pack.type = htons(MLOOP_EVTYPE_HWKEY);
pack.size = htons(5 + 8); //TODO: ?
memcpy(pack.data, &event_type, sizeof(int));
mloop_evsock_send(&mloop, &pack);
}
+void mloop_evcmd_touch(void)
+{
+ struct mloop_evpack pack;
+ memset(&pack, 0, sizeof(struct mloop_evpack));
+
+ pack.type = htons(MLOOP_EVTYPE_TOUCH);
+ pack.size = htons(5);
+ mloop_evsock_send(&mloop, &pack);
+}
+