mfreerdp-server: added xf style events
This commit is contained in:
parent
70101a7d75
commit
4a010f6328
@ -23,7 +23,9 @@ FIND_LIBRARY(APP_SERVICES ApplicationServices)
|
||||
|
||||
set(${MODULE_PREFIX}_SRCS
|
||||
mfreerdp.c
|
||||
mfreerdp.h)
|
||||
mfreerdp.h
|
||||
mf_event.c
|
||||
mf_event.h)
|
||||
|
||||
if(CHANNEL_AUDIN_SERVER)
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS}
|
||||
|
214
server/Mac/mf_event.c
Normal file
214
server/Mac/mf_event.c
Normal file
@ -0,0 +1,214 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* OS X Server Event Handling
|
||||
*
|
||||
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
|
||||
*
|
||||
* 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 <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
#include "mf_event.h"
|
||||
|
||||
int mf_is_event_set(mfEventQueue* event_queue)
|
||||
{
|
||||
fd_set rfds;
|
||||
int num_set;
|
||||
struct timeval time;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(event_queue->pipe_fd[0], &rfds);
|
||||
memset(&time, 0, sizeof(time));
|
||||
num_set = select(event_queue->pipe_fd[0] + 1, &rfds, 0, 0, &time);
|
||||
|
||||
return (num_set == 1);
|
||||
}
|
||||
|
||||
void mf_signal_event(mfEventQueue* event_queue)
|
||||
{
|
||||
int length;
|
||||
|
||||
length = write(event_queue->pipe_fd[1], "sig", 4);
|
||||
|
||||
if (length != 4)
|
||||
printf("mf_signal_event: error\n");
|
||||
}
|
||||
|
||||
void mf_set_event(mfEventQueue* event_queue)
|
||||
{
|
||||
int length;
|
||||
|
||||
length = write(event_queue->pipe_fd[1], "sig", 4);
|
||||
|
||||
if (length != 4)
|
||||
printf("mf_set_event: error\n");
|
||||
}
|
||||
|
||||
void mf_clear_events(mfEventQueue* event_queue)
|
||||
{
|
||||
int length;
|
||||
|
||||
while (mf_is_event_set(event_queue))
|
||||
{
|
||||
length = read(event_queue->pipe_fd[0], &length, 4);
|
||||
|
||||
if (length != 4)
|
||||
printf("mf_clear_event: error\n");
|
||||
}
|
||||
}
|
||||
|
||||
void mf_clear_event(mfEventQueue* event_queue)
|
||||
{
|
||||
int length;
|
||||
|
||||
length = read(event_queue->pipe_fd[0], &length, 4);
|
||||
|
||||
if (length != 4)
|
||||
printf("mf_clear_event: error\n");
|
||||
}
|
||||
|
||||
void mf_event_push(mfEventQueue* event_queue, mfEvent* event)
|
||||
{
|
||||
pthread_mutex_lock(&(event_queue->mutex));
|
||||
|
||||
if (event_queue->count >= event_queue->size)
|
||||
{
|
||||
event_queue->size *= 2;
|
||||
event_queue->events = (mfEvent**) realloc((void*) event_queue->events, sizeof(mfEvent*) * event_queue->size);
|
||||
}
|
||||
|
||||
event_queue->events[(event_queue->count)++] = event;
|
||||
|
||||
pthread_mutex_unlock(&(event_queue->mutex));
|
||||
|
||||
mf_set_event(event_queue);
|
||||
}
|
||||
|
||||
mfEvent* mf_event_peek(mfEventQueue* event_queue)
|
||||
{
|
||||
mfEvent* event;
|
||||
|
||||
pthread_mutex_lock(&(event_queue->mutex));
|
||||
|
||||
if (event_queue->count < 1)
|
||||
event = NULL;
|
||||
else
|
||||
event = event_queue->events[0];
|
||||
|
||||
pthread_mutex_unlock(&(event_queue->mutex));
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
mfEvent* mf_event_pop(mfEventQueue* event_queue)
|
||||
{
|
||||
mfEvent* event;
|
||||
|
||||
pthread_mutex_lock(&(event_queue->mutex));
|
||||
|
||||
if (event_queue->count < 1)
|
||||
return NULL;
|
||||
|
||||
/* remove event signal */
|
||||
mf_clear_event(event_queue);
|
||||
|
||||
event = event_queue->events[0];
|
||||
(event_queue->count)--;
|
||||
|
||||
memmove(&event_queue->events[0], &event_queue->events[1], event_queue->count * sizeof(void*));
|
||||
|
||||
pthread_mutex_unlock(&(event_queue->mutex));
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
mfEventRegion* mf_event_region_new(int x, int y, int width, int height)
|
||||
{
|
||||
mfEventRegion* event_region = xnew(mfEventRegion);
|
||||
|
||||
if (event_region != NULL)
|
||||
{
|
||||
event_region->x = x;
|
||||
event_region->y = y;
|
||||
event_region->width = width;
|
||||
event_region->height = height;
|
||||
}
|
||||
|
||||
return event_region;
|
||||
}
|
||||
|
||||
void mf_event_region_free(mfEventRegion* event_region)
|
||||
{
|
||||
free(event_region);
|
||||
}
|
||||
|
||||
mfEvent* mf_event_new(int type)
|
||||
{
|
||||
mfEvent* event = xnew(mfEvent);
|
||||
event->type = type;
|
||||
return event;
|
||||
}
|
||||
|
||||
void mf_event_free(mfEvent* event)
|
||||
{
|
||||
free(event);
|
||||
}
|
||||
|
||||
mfEventQueue* mf_event_queue_new()
|
||||
{
|
||||
mfEventQueue* event_queue = xnew(mfEventQueue);
|
||||
|
||||
if (event_queue != NULL)
|
||||
{
|
||||
event_queue->pipe_fd[0] = -1;
|
||||
event_queue->pipe_fd[1] = -1;
|
||||
|
||||
event_queue->size = 16;
|
||||
event_queue->count = 0;
|
||||
event_queue->events = (mfEvent**) xzalloc(sizeof(mfEvent*) * event_queue->size);
|
||||
|
||||
if (pipe(event_queue->pipe_fd) < 0)
|
||||
printf("mf_event_queue_new: pipe failed\n");
|
||||
|
||||
pthread_mutex_init(&(event_queue->mutex), NULL);
|
||||
}
|
||||
|
||||
return event_queue;
|
||||
}
|
||||
|
||||
void mf_event_queue_free(mfEventQueue* event_queue)
|
||||
{
|
||||
if (event_queue->pipe_fd[0] != -1)
|
||||
{
|
||||
close(event_queue->pipe_fd[0]);
|
||||
event_queue->pipe_fd[0] = -1;
|
||||
}
|
||||
|
||||
if (event_queue->pipe_fd[1] != -1)
|
||||
{
|
||||
close(event_queue->pipe_fd[1]);
|
||||
event_queue->pipe_fd[1] = -1;
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&(event_queue->mutex));
|
||||
}
|
75
server/Mac/mf_event.h
Normal file
75
server/Mac/mf_event.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* OS X Server Event Handling
|
||||
*
|
||||
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __MF_EVENT_H
|
||||
#define __XMF_EVENT_H
|
||||
|
||||
typedef struct mf_event mfEvent;
|
||||
typedef struct mf_event_queue mfEventQueue;
|
||||
typedef struct mf_event_region mfEventRegion;
|
||||
|
||||
#include <pthread.h>
|
||||
#include "mfreerdp.h"
|
||||
|
||||
//#include "mf_peer.h"
|
||||
|
||||
enum mf_event_type
|
||||
{
|
||||
mf_EVENT_TYPE_REGION,
|
||||
mf_EVENT_TYPE_FRAME_TICK
|
||||
};
|
||||
|
||||
struct mf_event
|
||||
{
|
||||
int type;
|
||||
};
|
||||
|
||||
struct mf_event_queue
|
||||
{
|
||||
int size;
|
||||
int count;
|
||||
int pipe_fd[2];
|
||||
mfEvent** events;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
struct mf_event_region
|
||||
{
|
||||
int type;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
void mf_event_push(mfEventQueue* event_queue, mfEvent* event);
|
||||
mfEvent* mf_event_peek(mfEventQueue* event_queue);
|
||||
mfEvent* mf_event_pop(mfEventQueue* event_queue);
|
||||
|
||||
mfEventRegion* mf_event_region_new(int x, int y, int width, int height);
|
||||
void mf_event_region_free(mfEventRegion* event_region);
|
||||
|
||||
mfEvent* mf_event_new(int type);
|
||||
void mf_event_free(mfEvent* event);
|
||||
|
||||
mfEventQueue* mf_event_queue_new();
|
||||
void mf_event_queue_free(mfEventQueue* event_queue);
|
||||
|
||||
#endif /* __MF_EVENT_H */
|
@ -48,6 +48,38 @@
|
||||
|
||||
#include "mfreerdp.h"
|
||||
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
|
||||
//refactor these
|
||||
int info_last_sec = 0;
|
||||
int info_last_nsec = 0;
|
||||
|
||||
void mf_peer_rfx_update(freerdp_peer* client)
|
||||
{
|
||||
|
||||
//limit rate
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
|
||||
if ( (mts.tv_sec - info_last_sec > 0) && (mts.tv_nsec - info_last_nsec > 500000000) ) {
|
||||
printf("rfx_update\n");
|
||||
|
||||
info_last_nsec = mts.tv_nsec;
|
||||
info_last_sec = mts.tv_sec;
|
||||
}
|
||||
|
||||
|
||||
//capture entire screen
|
||||
|
||||
//encode
|
||||
|
||||
//send
|
||||
}
|
||||
|
||||
void mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
|
||||
{
|
||||
context->rfx_context = rfx_context_new();
|
||||
@ -101,8 +133,7 @@ static void mf_peer_init(freerdp_peer* client)
|
||||
|
||||
BOOL mf_peer_post_connect(freerdp_peer* client)
|
||||
{
|
||||
int i;
|
||||
mfPeerContext* context = (mfPeerContext*) client->context;
|
||||
//mfPeerContext* context = (mfPeerContext*) client->context;
|
||||
|
||||
printf("Client %s is activated\n", client->hostname);
|
||||
|
||||
@ -121,7 +152,7 @@ BOOL mf_peer_post_connect(freerdp_peer* client)
|
||||
|
||||
#ifdef WITH_SERVER_CHANNELS
|
||||
/* Iterate all channel names requested by the client and activate those supported by the server */
|
||||
|
||||
int i;
|
||||
for (i = 0; i < client->settings->ChannelCount; i++)
|
||||
{
|
||||
if (client->settings->ChannelDefArray[i].joined)
|
||||
@ -305,6 +336,8 @@ static void* mf_peer_main_loop(void* arg)
|
||||
if (client->CheckFileDescriptor(client) != TRUE)
|
||||
break;
|
||||
|
||||
mf_peer_rfx_update(client);
|
||||
|
||||
#ifdef WITH_SERVER_CHANNELS
|
||||
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user