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