FreeRDP/server/Mac/mf_info.c

310 lines
6.7 KiB
C
Raw Normal View History

/**
2013-02-20 00:06:42 +04:00
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Mac OS X Server
*
* 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 <stdlib.h>
#include <errno.h>
#include "mf_info.h"
#include "mf_mountain_lion.h"
//#include "mf_update.h"
static mfInfo* mfInfoInstance = NULL;
//static int _IDcount = 0;
int mf_info_lock(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
int status = pthread_mutex_lock(&mfi->mutex);
switch (status) {
case 0:
return TRUE;
break;
default:
printf("mf_info_lock failed with %#X\n", status);
return -1;
break;
}
}
int mf_info_try_lock(mfInfo* mfi, UINT32 ms)
{
2013-02-20 00:06:42 +04:00
int status = pthread_mutex_trylock(&mfi->mutex);
switch (status) {
case 0:
return TRUE;
break;
case EBUSY:
return FALSE;
break;
default:
printf("mf_info_try_lock failed with %#X\n", status);
return -1;
break;
}
}
int mf_info_unlock(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
int status = pthread_mutex_unlock(&mfi->mutex);
switch (status) {
case 0:
return TRUE;
break;
default:
printf("mf_info_unlock failed with %#X\n", status);
return -1;
break;
}
}
mfInfo* mf_info_init()
{
mfInfo* mfi;
2013-02-20 00:06:42 +04:00
mfi = (mfInfo*) malloc(sizeof(mfInfo));
2013-02-20 00:06:42 +04:00
memset(mfi, 0, sizeof(mfInfo));
if (mfi != NULL)
{
2013-02-20 00:06:42 +04:00
/* HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
*/
int mutexInitStatus = pthread_mutex_init(&mfi->mutex, NULL);
if (mutexInitStatus != 0)
{
printf(_T("CreateMutex error: %#X\n"), mutexInitStatus);
}
2013-02-20 00:06:42 +04:00
mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
2013-02-20 00:06:42 +04:00
//Set FPS
mfi->framesPerSecond = MF_INFO_DEFAULT_FPS;
2013-02-20 00:06:42 +04:00
/*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
2013-02-20 00:06:42 +04:00
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
mfi->framesPerSecond = dwValue;
}
RegCloseKey(hKey);*/
//Set input toggle
mfi->input_disabled = FALSE;
2013-02-20 00:06:42 +04:00
/*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
2013-02-20 00:06:42 +04:00
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
{
if (dwValue != 0)
mfi->input_disabled = TRUE;
}
}
RegCloseKey(hKey);*/
}
2013-02-20 00:06:42 +04:00
return mfi;
}
mfInfo* mf_info_get_instance()
{
if (mfInfoInstance == NULL)
mfInfoInstance = mf_info_init();
2013-02-20 00:06:42 +04:00
return mfInfoInstance;
}
void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context)
{
if (mf_info_lock(mfi) > 0)
{
int i;
int peerId;
if (mfi->peerCount == MF_INFO_MAXPEERS)
{
2013-02-20 00:06:42 +04:00
printf("TODO: socketClose on OS X\n");
//context->socketClose = TRUE;
mf_info_unlock(mfi);
return;
}
2013-02-20 00:06:42 +04:00
context->info = mfi;
//get the offset of the top left corner of selected screen
//EnumDisplayMonitors(NULL, NULL, mf_info_monEnumCB, 0);
//_IDcount = 0;
2013-02-20 00:06:42 +04:00
//initialize screen capture
if (mfi->peerCount == 0)
2013-02-20 00:06:42 +04:00
{
mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale);
mf_mlion_screen_updates_init();
mf_mlion_start_getting_screen_updates();
}
//look trhough the array of peers until an empty slot
2013-02-20 01:26:06 +04:00
peerId = NULL;
for(i=0; i<MF_INFO_MAXPEERS; ++i)
{
//empty index will be our peer id
if (mfi->peers[i] == NULL)
{
peerId = i;
break;
}
}
2013-02-20 00:06:42 +04:00
mfi->peers[peerId] = ((rdpContext*) context)->peer;
mfi->peers[peerId]->pId = peerId;
mfi->peerCount++;
2013-02-20 01:26:06 +04:00
//printf("Registering Peer: id=%d #=%d\n", peerId, mfi->peerCount);
2013-02-20 00:06:42 +04:00
mf_info_unlock(mfi);
2013-02-20 00:06:42 +04:00
//mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_CONNECT);
}
}
void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context)
{
if (mf_info_lock(mfi) > 0)
{
int peerId;
2013-02-20 00:06:42 +04:00
peerId = ((rdpContext*) context)->peer->pId;
mfi->peers[peerId] = NULL;
mfi->peerCount--;
2013-02-20 00:06:42 +04:00
2013-02-20 01:26:06 +04:00
//printf("Unregistering Peer: id=%d, #=%d\n", peerId, mfi->peerCount);
2013-02-20 00:06:42 +04:00
//screen capture cleanup
if (mfi->peerCount == 0)
2013-02-20 00:06:42 +04:00
{
mf_mlion_stop_getting_screen_updates();
}
mf_info_unlock(mfi);
2013-02-20 00:06:42 +04:00
//mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_DISCONNECT);
}
}
BOOL mf_info_have_updates(mfInfo* mfi)
{
if(mfi->framesWaiting == 0)
return FALSE;
2013-02-20 00:06:42 +04:00
return TRUE;
}
void mf_info_update_changes(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
/*#ifdef WITH_WIN8
mf_dxgi_nextFrame(mfi, mfi->framesPerSecond * 1000);
#else
GETCHANGESBUF* buf;
buf = (GETCHANGESBUF*) mfi->changeBuffer;
mfi->nextUpdate = buf->buffer->counter;
#endif*/
}
void mf_info_find_invalid_region(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
mf_mlion_get_dirty_region(&mfi->invalid);
}
void mf_info_clear_invalid_region(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
mf_mlion_clear_dirty_region();
mfi->invalid.height = 0;
mfi->invalid.width = 0;
}
void mf_info_invalidate_full_screen(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
mfi->invalid.x = 0;
mfi->invalid.y = 0;
mfi->invalid.height = mfi->servscreen_height;
mfi->invalid.height = mfi->servscreen_width;
}
BOOL mf_info_have_invalid_region(mfInfo* mfi)
{
2013-02-20 00:06:42 +04:00
if (mfi->invalid.width * mfi->invalid.height == 0) {
return FALSE;
}
return TRUE;
}
void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch)
{
2013-02-20 00:06:42 +04:00
*width = mfi->invalid.width / mfi->scale;
*height = mfi->invalid.height / mfi->scale;
*pitch = mfi->servscreen_width * mfi->scale * 4;
mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width, *height, pBits);
*pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y);
}
/*
2013-02-20 00:06:42 +04:00
BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
mfInfo * mfi;
mfi = mf_info_get_instance();
if(_IDcount == mfi->screenID)
{
mfi->servscreen_xoffset = lprcMonitor->left;
mfi->servscreen_yoffset = lprcMonitor->top;
}
_IDcount++;
return TRUE;
}
*/