13#include <freerdp/config.h> 
   17#include <freerdp/freerdp.h> 
   18#include <freerdp/log.h> 
   20#define TAG CLIENT_TAG("android") 
   22#include "android_freerdp.h" 
   23#include "android_cliprdr.h" 
   29  if (aCtx->event_queue->count >= aCtx->event_queue->size)
 
   33    new_size = aCtx->event_queue->size * 2;
 
   34    new_events = realloc((
void*)aCtx->event_queue->events, 
sizeof(
ANDROID_EVENT*) * new_size);
 
   39    aCtx->event_queue->events = new_events;
 
   40    aCtx->event_queue->size = new_size;
 
   43  aCtx->event_queue->events[(aCtx->event_queue->count)++] = event;
 
   44  return SetEvent(aCtx->event_queue->isSet);
 
   54  event = queue->events[0];
 
   65  event = queue->events[0];
 
   68  for (
size_t i = 0; i < queue->count; i++)
 
   70    queue->events[i] = queue->events[i + 1];
 
   83  context = inst->context;
 
   84  WINPR_ASSERT(context);
 
   86  while (android_peek_event(queue))
 
  100        rc = freerdp_input_send_keyboard_event(context->input, key_event->flags,
 
  101                                               key_event->scancode);
 
  105      case EVENT_TYPE_KEY_UNICODE:
 
  109        rc = freerdp_input_send_unicode_keyboard_event(context->input, key_event->flags,
 
  110                                                       key_event->scancode);
 
  114      case EVENT_TYPE_CURSOR:
 
  118        rc = freerdp_input_send_mouse_event(context->input, cursor_event->flags,
 
  119                                            cursor_event->x, cursor_event->y);
 
  123      case EVENT_TYPE_CLIPBOARD:
 
  126        UINT32 formatId = ClipboardRegisterFormat(afc->clipboard, 
"text/plain");
 
  127        UINT32 size = clipboard_event->data_length;
 
  130          ClipboardSetData(afc->clipboard, formatId, clipboard_event->data, size);
 
  132          ClipboardEmpty(afc->clipboard);
 
  134        rc = (android_cliprdr_send_client_format_list(afc->cliprdr) == CHANNEL_RC_OK);
 
  138      case EVENT_TYPE_DISCONNECT:
 
  143    android_event_free(event);
 
  152HANDLE android_get_handle(freerdp* inst)
 
  156  if (!inst || !inst->context)
 
  161  if (!aCtx->event_queue || !aCtx->event_queue->isSet)
 
  164  return aCtx->event_queue->isSet;
 
  167BOOL android_check_handle(freerdp* inst)
 
  171  if (!inst || !inst->context)
 
  176  if (!aCtx->event_queue || !aCtx->event_queue->isSet)
 
  179  if (WaitForSingleObject(aCtx->event_queue->isSet, 0) == WAIT_OBJECT_0)
 
  181    if (!ResetEvent(aCtx->event_queue->isSet))
 
  184    if (!android_process_event(aCtx->event_queue, inst))
 
  198  event->type = EVENT_TYPE_KEY;
 
  199  event->flags = flags;
 
  200  event->scancode = scancode;
 
  217  event->type = EVENT_TYPE_KEY_UNICODE;
 
  218  event->flags = flags;
 
  219  event->scancode = key;
 
  236  event->type = EVENT_TYPE_CURSOR;
 
  239  event->flags = flags;
 
  256  event->type = EVENT_TYPE_DISCONNECT;
 
  260static void android_event_disconnect_free(
ANDROID_EVENT* event)
 
  273  event->type = EVENT_TYPE_CLIPBOARD;
 
  277    event->data = calloc(data_length + 1, 
sizeof(
char));
 
  285    memcpy(event->data, data, data_length);
 
  286    event->data_length = data_length + 1;
 
  301BOOL android_event_queue_init(freerdp* inst)
 
  309    WLog_ERR(TAG, 
"android_event_queue_init: memory allocation failed");
 
  315  queue->isSet = CreateEventA(NULL, TRUE, FALSE, NULL);
 
  327    WLog_ERR(TAG, 
"android_event_queue_init: memory allocation failed");
 
  328    (void)CloseHandle(queue->isSet);
 
  333  aCtx->event_queue = queue;
 
  337void android_event_queue_uninit(freerdp* inst)
 
  342  if (!inst || !inst->context)
 
  346  queue = aCtx->event_queue;
 
  352      (void)CloseHandle(queue->isSet);
 
  359      queue->events = NULL;
 
  379    case EVENT_TYPE_KEY_UNICODE:
 
  383    case EVENT_TYPE_CURSOR:
 
  387    case EVENT_TYPE_DISCONNECT:
 
  391    case EVENT_TYPE_CLIPBOARD: