diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index becc2a47e..8facc7d1b 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -148,83 +148,86 @@ struct rgba_data DWORD mac_client_thread(void* param) { - int status; - HANDLE events[4]; - HANDLE input_event; - HANDLE update_event; - HANDLE channels_event; - - DWORD nCount; - rdpContext* context = (rdpContext*) param; - mfContext* mfc = (mfContext*) context; - freerdp* instance = context->instance; - MRDPView* view = mfc->view; - - status = freerdp_connect(context->instance); - - if (!status) - { - [view setIs_connected:0]; - return 0; - } - - [view setIs_connected:1]; - - nCount = 0; - - events[nCount++] = mfc->stopEvent; - - if (instance->settings->AsyncUpdate) - { - events[nCount++] = update_event = freerdp_get_message_queue_event_handle(instance, FREERDP_UPDATE_MESSAGE_QUEUE); - } - - if (instance->settings->AsyncInput) - { - events[nCount++] = input_event = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE); - } - - if (instance->settings->AsyncChannels) - { - events[nCount++] = channels_event = freerdp_channels_get_event_handle(instance); - } - - while (1) - { - status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); - - if (WaitForSingleObject(mfc->stopEvent, 0) == WAIT_OBJECT_0) - { - break; - } - - if (instance->settings->AsyncUpdate) - { - if (WaitForSingleObject(update_event, 0) == WAIT_OBJECT_0) - { - update_activity_cb(instance); - } - } - - if (instance->settings->AsyncInput) - { - if (WaitForSingleObject(input_event, 0) == WAIT_OBJECT_0) - { - input_activity_cb(instance); - } - } - - if (instance->settings->AsyncChannels) - { - if (WaitForSingleObject(channels_event, 0) == WAIT_OBJECT_0) - { - channel_activity_cb(instance); - } - } - } - - ExitThread(0); - return 0; + @autoreleasepool + { + int status; + HANDLE events[4]; + HANDLE input_event; + HANDLE update_event; + HANDLE channels_event; + + DWORD nCount; + rdpContext* context = (rdpContext*) param; + mfContext* mfc = (mfContext*) context; + freerdp* instance = context->instance; + MRDPView* view = mfc->view; + + status = freerdp_connect(context->instance); + + if (!status) + { + [view setIs_connected:0]; + return 0; + } + + [view setIs_connected:1]; + + nCount = 0; + + events[nCount++] = mfc->stopEvent; + + if (instance->settings->AsyncUpdate) + { + events[nCount++] = update_event = freerdp_get_message_queue_event_handle(instance, FREERDP_UPDATE_MESSAGE_QUEUE); + } + + if (instance->settings->AsyncInput) + { + events[nCount++] = input_event = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE); + } + + if (instance->settings->AsyncChannels) + { + events[nCount++] = channels_event = freerdp_channels_get_event_handle(instance); + } + + while (1) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (WaitForSingleObject(mfc->stopEvent, 0) == WAIT_OBJECT_0) + { + break; + } + + if (instance->settings->AsyncUpdate) + { + if (WaitForSingleObject(update_event, 0) == WAIT_OBJECT_0) + { + update_activity_cb(instance); + } + } + + if (instance->settings->AsyncInput) + { + if (WaitForSingleObject(input_event, 0) == WAIT_OBJECT_0) + { + input_activity_cb(instance); + } + } + + if (instance->settings->AsyncChannels) + { + if (WaitForSingleObject(channels_event, 0) == WAIT_OBJECT_0) + { + channel_activity_cb(instance); + } + } + } + + ExitThread(0); + return 0; + } } /************************************************************************ diff --git a/client/Mac/cli/AppDelegate.h b/client/Mac/cli/AppDelegate.h index 779aa51ce..91439c06f 100644 --- a/client/Mac/cli/AppDelegate.h +++ b/client/Mac/cli/AppDelegate.h @@ -18,7 +18,7 @@ MRDPView* mrdpView; } -- (void) rdpConnectError; +- (void) rdpConnectError: (NSString*) customMessage; @property (assign) IBOutlet NSWindow *window; @property (assign) rdpContext *context; diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index 0ae15d323..aec62be91 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -13,6 +13,7 @@ static AppDelegate* _singleDelegate = nil; void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e); void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e); +void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e); @implementation AppDelegate @@ -46,6 +47,7 @@ void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEve else { PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler); + PubSub_SubscribeErrorInfo(context->pubSub, AppDelegate_ErrorInfoEventHandler); PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler); freerdp_client_start(context); @@ -113,19 +115,13 @@ 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 = @"Error connecting to server"; - if (connectErrorCode == AUTHENTICATIONERROR) - { - message = [NSString stringWithFormat:@"%@:\n%@", message, @"Authentication failure, check credentials."]; - } - + NSString* message = withMessage ? withMessage : @"Error connecting to server"; + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:message]; [alert beginSheetModalForWindow:[self window] @@ -169,11 +165,40 @@ void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e) void AppDelegate_ConnectionResultEventHandler(void* ctx, ConnectionResultEventArgs* e) { + NSLog(@"ConnectionResult event result:%d\n", e->result); if (_singleDelegate) { 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]; + } } \ No newline at end of file