FreeRDP/libfreerdp/utils/event.c

173 lines
3.8 KiB
C
Raw Normal View History

/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Events
*
* Copyright 2011 Vic Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/event.h>
#include <freerdp/client/cliprdr.h>
#include <freerdp/client/tsmf.h>
#include <freerdp/rail.h>
static RDP_EVENT* freerdp_cliprdr_event_new(UINT16 event_type)
{
2011-08-18 01:28:26 +04:00
RDP_EVENT* event = NULL;
switch (event_type)
{
case RDP_EVENT_TYPE_CB_MONITOR_READY:
event = (RDP_EVENT*) xnew(RDP_CB_MONITOR_READY_EVENT);
2011-07-12 18:03:09 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_FORMAT_LIST:
event = (RDP_EVENT*) xnew(RDP_CB_FORMAT_LIST_EVENT);
2011-07-12 18:03:09 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_DATA_REQUEST:
event = (RDP_EVENT*) xnew(RDP_CB_DATA_REQUEST_EVENT);
2011-07-12 18:03:09 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_DATA_RESPONSE:
event = (RDP_EVENT*) xnew(RDP_CB_DATA_RESPONSE_EVENT);
2011-07-12 18:03:09 +04:00
break;
2011-08-11 07:07:03 +04:00
}
return event;
}
static RDP_EVENT* freerdp_tsmf_event_new(UINT16 event_type)
2011-08-11 07:07:03 +04:00
{
2011-08-18 01:28:26 +04:00
RDP_EVENT* event = NULL;
2011-08-11 07:07:03 +04:00
switch (event_type)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_TSMF_VIDEO_FRAME:
event = (RDP_EVENT*) xnew(RDP_VIDEO_FRAME_EVENT);
2011-08-11 07:07:03 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_TSMF_REDRAW:
event = (RDP_EVENT*) xnew(RDP_REDRAW_EVENT);
2011-08-11 07:07:03 +04:00
break;
}
return event;
}
static RDP_EVENT* freerdp_rail_event_new(UINT16 event_type)
2011-08-11 07:07:03 +04:00
{
RDP_EVENT* event = NULL;
event = xnew(RDP_EVENT);
return event;
2011-08-11 07:07:03 +04:00
}
RDP_EVENT* freerdp_event_new(UINT16 event_class, UINT16 event_type,
2011-08-18 01:28:26 +04:00
RDP_EVENT_CALLBACK on_event_free_callback, void* user_data)
2011-08-11 07:07:03 +04:00
{
2011-08-18 01:28:26 +04:00
RDP_EVENT* event = NULL;
2011-08-11 07:07:03 +04:00
switch (event_class)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_DEBUG:
event = xnew(RDP_EVENT);
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_CLIPRDR:
2011-08-11 07:07:03 +04:00
event = freerdp_cliprdr_event_new(event_type);
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_TSMF:
2011-08-11 07:07:03 +04:00
event = freerdp_tsmf_event_new(event_type);
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_RAIL:
2011-08-11 07:07:03 +04:00
event = freerdp_rail_event_new(event_type);
break;
}
if (event != NULL)
{
2011-08-11 07:07:03 +04:00
event->event_class = event_class;
event->event_type = event_type;
event->on_event_free_callback = on_event_free_callback;
event->user_data = user_data;
}
return event;
}
2011-08-18 01:28:26 +04:00
static void freerdp_cliprdr_event_free(RDP_EVENT* event)
2011-08-11 07:07:03 +04:00
{
switch (event->event_type)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_FORMAT_LIST:
2011-08-11 07:07:03 +04:00
{
2011-08-18 01:28:26 +04:00
RDP_CB_FORMAT_LIST_EVENT* cb_event = (RDP_CB_FORMAT_LIST_EVENT*)event;
free(cb_event->formats);
free(cb_event->raw_format_data);
2011-08-11 07:07:03 +04:00
}
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_DATA_RESPONSE:
2011-08-11 07:07:03 +04:00
{
2011-08-18 01:28:26 +04:00
RDP_CB_DATA_RESPONSE_EVENT* cb_event = (RDP_CB_DATA_RESPONSE_EVENT*)event;
free(cb_event->data);
2011-08-11 07:07:03 +04:00
}
break;
}
}
2011-08-18 01:28:26 +04:00
static void freerdp_tsmf_event_free(RDP_EVENT* event)
2011-08-11 07:07:03 +04:00
{
switch (event->event_type)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_TSMF_VIDEO_FRAME:
2011-08-11 07:07:03 +04:00
{
2011-08-18 01:28:26 +04:00
RDP_VIDEO_FRAME_EVENT* vevent = (RDP_VIDEO_FRAME_EVENT*)event;
free(vevent->frame_data);
free(vevent->visible_rects);
2011-08-11 07:07:03 +04:00
}
break;
}
}
2011-08-18 01:28:26 +04:00
static void freerdp_rail_event_free(RDP_EVENT* event)
2011-08-11 07:07:03 +04:00
{
}
2011-08-18 01:28:26 +04:00
void freerdp_event_free(RDP_EVENT* event)
{
if (event != NULL)
{
if (event->on_event_free_callback != NULL)
event->on_event_free_callback(event);
2011-08-11 07:07:03 +04:00
switch (event->event_class)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_CLIPRDR:
2011-08-11 07:07:03 +04:00
freerdp_cliprdr_event_free(event);
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_TSMF:
2011-08-11 07:07:03 +04:00
freerdp_tsmf_event_free(event);
2011-07-12 18:03:09 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_CLASS_RAIL:
2011-08-11 07:07:03 +04:00
freerdp_rail_event_free(event);
2011-07-12 18:03:09 +04:00
break;
}
free(event);
}
}