MacFreeRDP cli fixes:

- added ErrorInfo handling.
- Showing alert message on main thread.
- Autorelease pool for background thread.
This commit is contained in:
Benoît LeBlanc 2013-07-22 15:33:30 -04:00
parent 55ed600f1a
commit 81626c8741
3 changed files with 117 additions and 89 deletions

View File

@ -148,6 +148,8 @@ struct rgba_data
DWORD mac_client_thread(void* param) DWORD mac_client_thread(void* param)
{ {
@autoreleasepool
{
int status; int status;
HANDLE events[4]; HANDLE events[4];
HANDLE input_event; HANDLE input_event;
@ -225,6 +227,7 @@ DWORD mac_client_thread(void* param)
ExitThread(0); ExitThread(0);
return 0; return 0;
}
} }
/************************************************************************ /************************************************************************

View File

@ -18,7 +18,7 @@
MRDPView* mrdpView; MRDPView* mrdpView;
} }
- (void) rdpConnectError; - (void) rdpConnectError: (NSString*) customMessage;
@property (assign) IBOutlet NSWindow *window; @property (assign) IBOutlet NSWindow *window;
@property (assign) rdpContext *context; @property (assign) rdpContext *context;

View File

@ -13,6 +13,7 @@
static AppDelegate* _singleDelegate = nil; static AppDelegate* _singleDelegate = nil;
void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e); void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e);
void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e); void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e);
void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e);
@implementation AppDelegate @implementation AppDelegate
@ -46,6 +47,7 @@ void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEve
else else
{ {
PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler); PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler);
PubSub_SubscribeErrorInfo(context->pubSub, AppDelegate_ErrorInfoEventHandler);
PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler); PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler);
freerdp_client_start(context); freerdp_client_start(context);
@ -113,18 +115,12 @@ void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEve
/** ********************************************************************* /** *********************************************************************
* called when we fail to connect to a RDP server * called when we fail to connect to a RDP server - Make sure this is called from the main thread.
***********************************************************************/ ***********************************************************************/
- (void) rdpConnectError - (void) rdpConnectError : (NSString*) withMessage
{ {
// TODO: This should be called on the main thread NSString* message = withMessage ? withMessage : @"Error connecting to server";
NSString* message = @"Error connecting to server";
if (connectErrorCode == AUTHENTICATIONERROR)
{
message = [NSString stringWithFormat:@"%@:\n%@", message, @"Authentication failure, check credentials."];
}
NSAlert *alert = [[NSAlert alloc] init]; NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:message]; [alert setMessageText:message];
@ -169,11 +165,40 @@ void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e)
void AppDelegate_ConnectionResultEventHandler(void* ctx, ConnectionResultEventArgs* e) void AppDelegate_ConnectionResultEventHandler(void* ctx, ConnectionResultEventArgs* e)
{ {
NSLog(@"ConnectionResult event result:%d\n", e->result);
if (_singleDelegate) if (_singleDelegate)
{ {
if (e->result != 0) if (e->result != 0)
{ {
[_singleDelegate rdpConnectError]; NSString* message = nil;
if (connectErrorCode == AUTHENTICATIONERROR)
{
message = [NSString stringWithFormat:@"%@:\n%@", message, @"Authentication failure, check credentials."];
}
// Making sure this should be invoked on the main UI thread.
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:) withObject:message waitUntilDone:FALSE];
[message release];
} }
} }
} }
void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e)
{
NSLog(@"ErrorInfo event code:%d\n", e->code);
if (_singleDelegate)
{
// Retrieve error message associated with error code
NSString* message = nil;
if (e->code != ERRINFO_NONE)
{
const char* errorMessage = freerdp_get_error_info_string(e->code);
message = [[NSString alloc] initWithUTF8String:errorMessage];
}
// Making sure this should be invoked on the main UI thread.
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:) withObject:message waitUntilDone:TRUE];
[message release];
}
}