Add Obj-C Wrapper support for DDV
This commit is contained in:
Родитель
6dbbf08c23
Коммит
fba2eba011
|
@ -0,0 +1,59 @@
|
|||
#include "objc_begin.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/*!
|
||||
The <b>ODWDiagnosticDataViewer</b> class represents Diagnostic Data Viewer Hook.
|
||||
*/
|
||||
@interface ODWDiagnosticDataViewer : NSObject
|
||||
|
||||
#pragma mark Initialization methods
|
||||
|
||||
/*!
|
||||
@brief Initializes Data Viewer with an specified machine identifier.
|
||||
@param machineIdentifier A string that contains the machine identifier.
|
||||
*/
|
||||
+(void)initializeViewerWithMachineIdentifier:(NSString *)machineIdentifier;
|
||||
|
||||
#pragma mark Behavior methods
|
||||
/*!
|
||||
@brief Enables Data Viewer.
|
||||
@param endpoint A string that contains endpoint to route events.
|
||||
@param completionWithResult Code to execute when enable is completed. <b>Note:</b> This value can be null.
|
||||
*/
|
||||
+(void)enableRemoteViewer:(NSString *)endpoint
|
||||
completionWithResult:(void(^)(bool result))completion;
|
||||
|
||||
/*!
|
||||
@brief Enables Data Viewer.
|
||||
@param endpoint A string that contains endpoint to route events.
|
||||
*/
|
||||
+(bool)enableRemoteViewer:(NSString *)endpoint;
|
||||
|
||||
/*!
|
||||
@brief Disables Data Viewer.
|
||||
@param completion Code to execute when disable is completed. <b>Note:</b> This value can be null.
|
||||
*/
|
||||
+(void)disableViewer:(void(^)(bool result))completion;
|
||||
|
||||
/*!
|
||||
@brief Disables Data Viewer.
|
||||
*/
|
||||
+(bool)disableViewer;
|
||||
|
||||
/*!
|
||||
@brief Returns if Data Viewer is enabled or not.
|
||||
@return True if viewer is enabled
|
||||
*/
|
||||
+(bool)viewerEnabled;
|
||||
|
||||
/*!
|
||||
@brief Sets callback for OnDisableNotification event.
|
||||
@param callback Code to execute when OnDisableNotification event occurrs.
|
||||
*/
|
||||
+(void)registerOnDisableNotification:(void(^)())callback;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
#include "objc_end.h"
|
|
@ -0,0 +1,162 @@
|
|||
#include <stdexcept>
|
||||
#include "LogManager.hpp"
|
||||
#include "DefaultDataViewer.hpp"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "ODWDiagnosticDataViewer.h"
|
||||
#import "ODWLogConfiguration.h"
|
||||
#import "ODWLogger_private.h"
|
||||
|
||||
using namespace MAT;
|
||||
|
||||
@implementation ODWDiagnosticDataViewer
|
||||
|
||||
std::shared_ptr<DefaultDataViewer> _viewer;
|
||||
|
||||
+(void)initializeViewerWithMachineIdentifier:(NSString *)machineIdentifier
|
||||
{
|
||||
const std::string identifier = { [machineIdentifier UTF8String] };
|
||||
try
|
||||
{
|
||||
_viewer = std::make_shared<DefaultDataViewer> (nullptr, identifier);
|
||||
LogManager::GetDataViewerCollection().RegisterViewer(_viewer);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e.what()];
|
||||
}
|
||||
catch (const std::exception *e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e->what()];
|
||||
}
|
||||
}
|
||||
|
||||
+(void)enableRemoteViewer:(NSString *)endpoint completionWithResult:(void(^)(bool result))completion
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
bool result = [ODWDiagnosticDataViewer enableRemoteViewer: endpoint];
|
||||
if (completion)
|
||||
{
|
||||
completion(result);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
+(bool)enableRemoteViewer:(NSString *)endpoint
|
||||
{
|
||||
std::string endpointString = std::string([endpoint UTF8String]);
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = _viewer->EnableRemoteViewer(endpointString);
|
||||
if ([ODWLogConfiguration enableTrace])
|
||||
{
|
||||
NSLog(@"RemoteDataViewer enabled on endpoint: %@ and result: %@", endpoint, result ? @"success" : @"failure");
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e.what()];
|
||||
}
|
||||
catch (const std::exception *e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e->what()];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+(void)disableViewer:(void(^)(bool result))completion
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
bool result = [ODWDiagnosticDataViewer disableViewer];
|
||||
if (completion)
|
||||
{
|
||||
completion(result);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
+(bool)disableViewer
|
||||
{
|
||||
bool result = _viewer->DisableViewer();
|
||||
if ([ODWLogConfiguration enableTrace])
|
||||
{
|
||||
NSLog(@"RemoteDataViewer disabled with result: %@", result ? @"success" : @"failure");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+(bool)viewerEnabled
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = LogManager::GetDataViewerCollection().IsViewerEnabled();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e.what()];
|
||||
}
|
||||
catch (const std::exception *e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e->what()];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+(void)registerOnDisableNotification:(void(^)())callback
|
||||
{
|
||||
std::function<void()> disableNotification = std::bind(callback);
|
||||
try
|
||||
{
|
||||
_viewer->RegisterOnDisableNotification(disableNotification);
|
||||
if ([ODWLogConfiguration enableTrace])
|
||||
{
|
||||
NSLog(@"Registered OnDisableNotification");
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e.what()];
|
||||
}
|
||||
catch (const std::exception *e)
|
||||
{
|
||||
if ([ODWLogConfiguration surfaceCppExceptions])
|
||||
{
|
||||
throw;
|
||||
}
|
||||
[ODWLogger traceException: e->what()];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -22,6 +22,17 @@
|
|||
*/
|
||||
+(bool)enableTrace;
|
||||
|
||||
/*!
|
||||
@brief Sets if inner C++ exceptions should be surfaced to Wrapper consumers.
|
||||
@param surfaceCppExceptions True if C++ exceptions should be surfaced.
|
||||
*/
|
||||
+ (void)setSurfaceCppExceptions:(bool)surfaceCppExceptions;
|
||||
|
||||
/*!
|
||||
@brief Returns true if inner C++ exceptions are surfaced to Wrapper consumers.
|
||||
*/
|
||||
+ (bool)surfaceCppExceptions;
|
||||
|
||||
@end
|
||||
|
||||
#include "objc_end.h"
|
||||
|
|
|
@ -6,6 +6,7 @@ using namespace Microsoft::Applications::Events;
|
|||
|
||||
@implementation ODWLogConfiguration
|
||||
static bool _enableTrace;
|
||||
static bool _surfaceCppExceptions;
|
||||
|
||||
+(void)setMaxTeardownUploadTimeInSec:(int)maxTeardownUploadTimeInSec
|
||||
{
|
||||
|
@ -25,4 +26,14 @@ using namespace Microsoft::Applications::Events;
|
|||
return _enableTrace;
|
||||
}
|
||||
|
||||
+(void)setSurfaceCppExceptions:(bool)surfaceCppExceptions
|
||||
{
|
||||
_surfaceCppExceptions = surfaceCppExceptions;
|
||||
}
|
||||
|
||||
+(bool)surfaceCppExceptions
|
||||
{
|
||||
return _surfaceCppExceptions;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -206,4 +206,11 @@ using namespace MAT;
|
|||
}
|
||||
}
|
||||
|
||||
+(void)traceException:(const char *)message
|
||||
{
|
||||
if([ODWLogConfiguration enableTrace])
|
||||
{
|
||||
NSLog(EXCEPTION_TRACE_FORMAT, message);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -7,6 +7,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
using namespace MAT;
|
||||
|
||||
#define EXCEPTION_TRACE_FORMAT @"C++ Exception: %s"
|
||||
|
||||
/*!
|
||||
The <b>ODWLogger</b> class represents an event's properties.
|
||||
*/
|
||||
|
@ -17,6 +19,11 @@ using namespace MAT;
|
|||
*/
|
||||
-(instancetype)initWithILogger:(ILogger *)logger;
|
||||
|
||||
/*!
|
||||
@brief Traces C++ exception message. This method might be only used internally by wrapper.
|
||||
*/
|
||||
+ (void)traceException:(const char*)message;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
Загрузка…
Ссылка в новой задаче