Add Objective-C Wrappers to SDK

This commit is contained in:
Eduardo Camacho Camacho 2019-11-18 14:44:46 -08:00
Родитель d58a779142
Коммит f7fdc110bc
30 изменённых файлов: 801 добавлений и 398 удалений

Просмотреть файл

@ -19,6 +19,10 @@ endif()
option(BUILD_IOS "Build for iOS" NO)
option(BUILD_SIMULATOR "Build using simulator SDK" NO)
# Begin Uncomment for iOS Device build
#set(BUILD_SIMULATOR NO)
# End of iOS Device build
if(BUILD_IOS)
add_definitions(-DIOS_HTTP=1)
set(TARGET_ARCH "APPLE")
@ -43,6 +47,8 @@ if(BUILD_IOS)
message("-- CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT}")
endif()
message("-- BUILD_IOS: ${BUILD_IOS}")
message("-- BUILD_SIMULATOR: ${BUILD_SIMULATOR}")
message("-- CMAKE_SYSTEM_INFO_FILE: ${CMAKE_SYSTEM_INFO_FILE}")
message("-- CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message("-- CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
@ -182,6 +188,7 @@ option(BUILD_TEST_TOOL "Build console test tool" YES)
option(BUILD_UNIT_TESTS "Build unit tests" YES)
option(BUILD_FUNC_TESTS "Build functional tests" YES)
option(BUILD_JNI_WRAPPER "Build JNI wrapper" NO)
option(BUILD_OBJC_WRAPPER "Build Obj-C wrapper" YES)
option(BUILD_PACKAGE "Build package" YES)
if(BUILD_UNIT_TESTS OR BUILD_FUNC_TESTS)

Просмотреть файл

@ -70,6 +70,16 @@ if(EXISTS "modules/dataviewer/")
endif()
if(PAL_IMPLEMENTATION STREQUAL "CPP11")
if(APPLE)
list(APPEND SRCS
pal/posix/sysinfo_utils_apple.mm
)
if(BUILD_IOS)
list(APPEND SRCS
pal/posix/sysinfo_utils_ios.mm
)
endif()
endif()
list(APPEND SRCS
pal/posix/DeviceInformationImpl.cpp
pal/posix/SystemInformationImpl.cpp
@ -81,7 +91,6 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11")
http/HttpClient_iOS.mm
pal/posix/NetworkInformationImpl.mm
pal/posix/Reachability.m
pal/posix/sysinfo_utils_ios.mm
)
else()
list(APPEND SRCS
@ -90,6 +99,15 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11")
pal/posix/NetworkInformationImpl.cpp
)
endif()
if(BUILD_OBJC_WRAPPER)
message("Include Wrappers")
list(APPEND SRCS
../wrappers/obj-c/ODWLogger.mm
../wrappers/obj-c/ODWLogManager.mm
../wrappers/obj-c/ODWEventProperties.mm
../wrappers/obj-c/ODWLogConfiguration.mm
)
endif()
elseif(PAL_IMPLEMENTATION STREQUAL "WIN32")
# Win32 Desktop for now.
# TODO: define a separate PAL for Win10 cmake build

Просмотреть файл

@ -268,11 +268,11 @@ extern "C" {
const char* id;
int64_t delayMs;
const char* typeName;
} task_t;
} task_data_t;
/* Async worker thread callback function signatures */
typedef void (EVTSDK_LIBABI_CDECL *task_callback_fn_t)(const char* /*taskId*/);
typedef void (EVTSDK_LIBABI_CDECL *task_dispatcher_queue_fn_t)(task_t*, task_callback_fn_t);
typedef void (EVTSDK_LIBABI_CDECL *task_dispatcher_queue_fn_t)(task_data_t*, task_callback_fn_t);
typedef bool (EVTSDK_LIBABI_CDECL *task_dispatcher_cancel_fn_t)(const char* /*taskId*/);
typedef void (EVTSDK_LIBABI_CDECL *task_dispatcher_join_fn_t)();

@ -1 +1 @@
Subproject commit ba2b14f1cfb23ce371537c70a2ffcbed9dfc7a4a
Subproject commit dee183f7cd70ea7071e1fdf8a03d42938b43a473

Просмотреть файл

@ -107,7 +107,7 @@ namespace PAL_NS_BEGIN {
auto ownedItem = std::unique_ptr<Task>(task);
// Create task
task_t capiTask;
task_data_t capiTask;
std::string taskId = GetNextTaskId();
capiTask.id = taskId.c_str();
capiTask.typeName = ownedItem->TypeName.c_str();

Просмотреть файл

@ -43,6 +43,7 @@
#include <sys/syslimits.h>
#include <libgen.h>
#include "TargetConditionals.h"
#include "sysinfo_utils_apple.hpp"
#ifdef TARGET_MAC_OS
@ -228,10 +229,10 @@ public:
#else
cache["devModel"] = Exec("sysctl hw.model | awk '{ print $2 }'");
#endif // TARGET_OS_IPHONE
cache["osName"] = Exec("defaults read /System/Library/CoreServices/SystemVersion ProductName");
cache["osVer"] = Exec("defaults read /System/Library/CoreServices/SystemVersion ProductVersion");
cache["osRel"] = Exec("defaults read /System/Library/CoreServices/SystemVersion ProductUserVisibleVersion");
cache["osBuild"] = Exec("defaults read /System/Library/CoreServices/SystemVersion ProductBuildVersion");
cache["osName"] = get_device_osName();
cache["osVer"] = get_device_osVersion();
cache["osRel"] = get_device_osRelease();
cache["osBuild"] = get_device_osBuild();
// Populate user timezone as hh:mm offset from UTC timezone. Example for PST: "-08:00"
CFTimeZoneRef tz = CFTimeZoneCopySystem();

Просмотреть файл

@ -0,0 +1,15 @@
#ifndef LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_
#define LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_
// Copyright (c) Microsoft Corporation. All rights reserved.
#include <string>
std::string get_device_osName();
std::string get_device_osVersion();
std::string get_device_osRelease();
std::string get_device_osBuild();
#endif /* LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_ */

Просмотреть файл

@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
#import <Foundation/Foundation.h>
#include "sysinfo_utils_apple.hpp"
CFDictionaryRef copy_system_plist_dictionary(void)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *versionData = nil;
NSString *systemVersFile = @"/System/Library/CoreServices/SystemVersion.plist";
NSString *serverVersFile = @"/System/Library/CoreServices/ServerVersion.plist";
NSDictionary *properties = nil;
if([fileManager isReadableFileAtPath:systemVersFile])
versionData = [NSData dataWithContentsOfFile:systemVersFile];
else if([fileManager isReadableFileAtPath:serverVersFile])
versionData = [NSData dataWithContentsOfFile:serverVersFile];
if(versionData == nil)
return nil;
properties = [NSPropertyListSerialization propertyListWithData:versionData options:NSPropertyListImmutable format:nil error:nil];
return (CFDictionaryRef) [properties retain];
}
NSString* get_system_value(CFStringRef key)
{
CFDictionaryRef systemProperties = copy_system_plist_dictionary();
if (systemProperties)
{
CFStringRef propertyValue = (CFStringRef) CFDictionaryGetValue(systemProperties, key);
if (propertyValue)
{
return (NSString *)propertyValue;
}
CFRelease(systemProperties);
}
return @"";
}
std::string get_device_osName()
{
NSString* value = get_system_value(CFSTR("ProductName"));
return std::string([value UTF8String]);
}
std::string get_device_osVersion()
{
NSString* value = get_system_value(CFSTR("ProductVersion"));
return std::string([value UTF8String]);
}
std::string get_device_osRelease()
{
NSString* value = get_system_value(CFSTR("ProductUserVisibleVersion"));
return std::string([value UTF8String]);
}
std::string get_device_osBuild()
{
NSString* value = get_system_value(CFSTR("ProductBuildVersion"));
return std::string([value UTF8String]);
}

Просмотреть файл

@ -1,5 +1,3 @@
#ifndef LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_
#define LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_
// Copyright (c) Microsoft Corporation. All rights reserved.
#include <string>
@ -7,5 +5,3 @@
std::string get_device_model();
std::string get_device_id();
#endif /* LIB_PAL_POSIX_SYSINFO_UTILS_IOS_HPP_ */

Просмотреть файл

@ -12,6 +12,15 @@ std::string get_device_model()
std::string get_device_id()
{
std::string deviceId { [[[[UIDevice currentDevice] identifierForVendor] UUIDString] UTF8String] };
return deviceId;
NSUUID *nsuuid = [[UIDevice currentDevice] identifierForVendor];
if (nsuuid)
{
std::string deviceId { [[nsuuid UUIDString] UTF8String] };
return deviceId;
}
else
{
std::string emptyString;
return emptyString;
}
}

Просмотреть файл

@ -18,12 +18,15 @@ namespace
void SetShouldExecute(bool shouldExecute) { m_shouldExecute = shouldExecute; }
bool ShouldExecute() { return m_shouldExecute; }
void SetQueueValidation(std::function<void(task_t*)> fn) { m_validateQueueFn = fn; }
void SetQueueValidation(std::function<void(task_data_t*)> fn)
{
m_validateQueueFn = fn;
}
void SetCancelValidation(std::function<void(const char*)> fn) { m_validateCancelFn = fn; }
void SetJoinValidation(std::function<void()> fn) { m_validateJoinFn = fn; }
void SetCallbackValidation(std::function<void(int, int)> fn) { m_validateCallbackFn = fn; }
void OnQueue(task_t* task)
void OnQueue(task_data_t* task)
{
if (m_validateQueueFn)
m_validateQueueFn(task);
@ -50,7 +53,7 @@ namespace
private:
bool m_shouldExecute = false;
std::function<void(task_t*)> m_validateQueueFn;
std::function<void(task_data_t*)> m_validateQueueFn;
std::function<void(const char*)> m_validateCancelFn;
std::function<void()> m_validateJoinFn;
std::function<void(int, int)> m_validateCallbackFn;
@ -83,7 +86,7 @@ namespace
};
} // namespace
void EVTSDK_LIBABI_CDECL OnTaskDispatcherQueue(task_t* task, task_callback_fn_t callback)
void EVTSDK_LIBABI_CDECL OnTaskDispatcherQueue(task_data_t* task, task_callback_fn_t callback)
{
s_testHelper->OnQueue(task);
@ -101,7 +104,7 @@ void EVTSDK_LIBABI_CDECL OnTaskDispatcherJoin()
s_testHelper->OnJoin();
}
void CheckTaskTypeNameIsExpectedOrEmptyIfRTTIIsEnabled(task_t* task) noexcept
void CheckTaskTypeNameIsExpectedOrEmptyIfRTTIIsEnabled(task_data_t* task) noexcept
{
std::string typeName { task->typeName };
#if HAS_RTTI
@ -120,7 +123,7 @@ TEST(TaskDispatcherCAPITests, Execute)
// Validate C++ -> C transformation of task
bool wasQueued = false;
testHelper->SetQueueValidation([&wasQueued](task_t* task) {
testHelper->SetQueueValidation([&wasQueued](task_data_t* task) {
wasQueued = true;
EXPECT_EQ(task->delayMs, 0);
CheckTaskTypeNameIsExpectedOrEmptyIfRTTIIsEnabled(task);
@ -149,7 +152,7 @@ TEST(TaskDispatcherCAPITests, Schedule)
// Validate C++ -> C transformation of task
bool wasQueued = false;
testHelper->SetQueueValidation([&wasQueued](task_t* task) {
testHelper->SetQueueValidation([&wasQueued](task_data_t* task) {
wasQueued = true;
EXPECT_NE(task->delayMs, 0);
CheckTaskTypeNameIsExpectedOrEmptyIfRTTIIsEnabled(task);
@ -179,7 +182,7 @@ TEST(TaskDispatcherCAPITests, Cancel)
// Validate C++ -> C transformation of task
string taskIdStr;
bool wasQueued = false;
testHelper->SetQueueValidation([&wasQueued, &taskIdStr](task_t* task) {
testHelper->SetQueueValidation([&wasQueued, &taskIdStr](task_data_t* task) {
wasQueued = true;
taskIdStr = task->id;
EXPECT_NE(task->delayMs, 0);

Просмотреть файл

@ -32,8 +32,8 @@ set (PLATFORM_LIBS "-framework Foundation -framework CoreFoundation -framework I
endif()
include_directories(
/build/Aria.SDK.Cpp/lib/include/public/
/build/Aria.SDK.Cpp/lib/include/mat/
../../lib/include/public/
../../lib/include/mat/
)
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
@ -41,7 +41,7 @@ foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
set(PLATFORM_FILES main.mm WLogManager.mm WLogger.mm WEventProperties.mm)
set(PLATFORM_FILES main.mm ODWLogManager.mm ODWLogger.mm ODWEventProperties.mm ODWLogConfiguration.mm)
add_executable( sample ${PLATFORM_FILES} )
target_link_libraries(sample ${MATSDK_LIB}/libmat.a curl z ${CMAKE_THREAD_LIBS_INIT} ${SQLITE3_LIB} ${PLATFORM_LIBS} dl)

Просмотреть файл

@ -0,0 +1,88 @@
#include "objc_begin.h"
NS_ASSUME_NONNULL_BEGIN
/*!
@enum ODWEventPriority
@brief The <b>ODWEventPriority</b> enumeration contains a set of values that specify event priority.
*/
typedef NS_ENUM(NSInteger, ODWEventPriority)
{
ODWEventPriorityUnspecified = -1,
ODWEventPriorityOff = 0,
ODWEventPriorityLow = 1,
ODWEventPriorityNormal = 2,
ODWEventPriorityHigh = 3,
ODWEventPriorityImmediate = 4
};
/*!
The <b>ODWEventProperties</b> class represents an event's properties.
*/
@interface ODWEventProperties : NSObject
/*!
@brief Event name.
*/
@property(readwrite, copy, nonatomic) NSString* name;
/*!
@brief Event priority.
*/
@property(readwrite, nonatomic) ODWEventPriority priority;
/*!
@brief Event properties.
*/
@property(readonly, copy, nonatomic) NSDictionary<NSString *, id> * properties;
/*!
@brief Constructs an ODWEventProperties object, taking an event name.
@param name A string that contains the name of the event.
@return An instance of the ODWEventProperties interface.
*/
-(instancetype)initWithName:(NSString *)name;
/*!
@brief Constructs an ODWEventProperties object, taking an event name and properties.
@param name A string that contains the name of the event.
@param properties A dictionary containing property name and value pairs.
@return An instance of the ODWEventProperties interface.
*/
-(instancetype)initWithName:(NSString *)name
properties:(NSDictionary<NSString *,id>*)properties NS_DESIGNATED_INITIALIZER;
-(instancetype)init NS_UNAVAILABLE;
/*!
@brief Sets a string property for an event.
@param name A string that contains the name of the property.
@param value A string that contains the property value.
*/
-(void)setProperty:(NSString *)name withValue:(id)value;
/*!
@brief Sets a double property for an event.
@param name A string that contains the name of the property.
@param value A double that contains the property value.
*/
-(void)setProperty:(NSString*)name withDoubleValue:(double)value;
/*!
@brief Sets an integer property for an event.
@param name A string that contains the name of the property.
@param value An integer that contains the property value.
*/
-(void)setProperty:(NSString*)name withInt64Value:(int64_t)value;
/*!
@brief Sets a BOOL property for an event.
@param name A string that contains the name of the property.
@param value A BOOL that contains the property value.
*/
-(void)setProperty:(NSString*)name withBoolValue:(BOOL)value;
@end
NS_ASSUME_NONNULL_END
#include "objc_end.h"

Просмотреть файл

@ -0,0 +1,54 @@
#import <Foundation/Foundation.h>
#import "ODWEventProperties.h"
@implementation ODWEventProperties {
NSMutableDictionary<NSString *, id> * _properties;
}
@dynamic properties;
-(instancetype)initWithName:(nonnull NSString *)name
{
return [self initWithName:name aproperties:[[NSMutableDictionary alloc] init]];
}
-(instancetype)initWithName:(nonnull NSString *)name
properties:(NSDictionary<NSString*,id>*) properties
{
self = [super init];
if (self)
{
_name = [name copy];
_properties = [properties mutableCopy];
_priority = ODWEventPriorityUnspecified;
}
return self;
}
-(NSDictionary<NSString *, id> *)properties
{
return [_properties copy];
}
-(void)setProperty:(NSString*)name withValue:(id)value
{
[_properties setValue:value forKey:name];
}
-(void)setProperty:(NSString*)name withDoubleValue:(double)value
{
[_properties setValue:@(value) forKey:name];
}
-(void)setProperty:(NSString*)name withInt64Value:(int64_t)value
{
[_properties setValue:@(value) forKey:name];
}
-(void)setProperty:(NSString*)name withBoolValue:(BOOL)value
{
[_properties setValue:@(value) forKey:name];
}
@end

Просмотреть файл

@ -0,0 +1,16 @@
#include "objc_begin.h"
/*!
The <b>ODWLogConfiguration</b> static class represents general logging properties.
*/
@interface ODWLogConfiguration : NSObject
/*!
@brief Sets max teardown upload time in seconds.
@param maxTeardownUploadTimeInSec An integer that time in seconds.
*/
+(void)setMaxTeardownUploadTimeInSec:(int)maxTeardownUploadTimeInSec;
@end
#include "objc_end.h"

Просмотреть файл

@ -0,0 +1,15 @@
#import <Foundation/Foundation.h>
#import "ODWLogConfiguration.h"
#import "LogManager.hpp"
using namespace Microsoft::Applications::Events;
@implementation ODWLogConfiguration
+(void)setMaxTeardownUploadTimeInSec:(int)maxTeardownUploadTimeInSec
{
auto& config = LogManager::GetLogConfiguration();
config[CFG_INT_MAX_TEARDOWN_TIME] = maxTeardownUploadTimeInSec;
}
@end

Просмотреть файл

@ -0,0 +1,85 @@
#include "objc_begin.h"
NS_ASSUME_NONNULL_BEGIN
/*!
@brief The ODWLogManager class manages the telemetry lgging system.
*/
@interface ODWLogManager : NSObject
/*!
@enum ODWTransmissionProfile
@brief The <b>ODWTransmissionProfile</b> enumeration contains a set of values that specify how efficiently telemetry events are sent.
*/typedef NS_ENUM(NSInteger, ODWTransmissionProfile)
{
ODWRealTime = 0,
ODWNearRealTime = 1,
ODWBestEffort = 2
};
/*!
@brief Initializes the telemetry logging system with the default cofiguration, using the specified tenant token.
@param tenantToken A string that contains the tenant token.
@return An ODWLogger instance
*/
+(nullable id)loggerWithTenant:(NSString *)tenantToken;
/*!
@brief Initializes the telemetry logging system with the default configuration, using the specified tenant token and source.
@param tenantToken A string that contains the tenant token.
@param source A string that contains the name of the source of events.
@return An ODWLogger pointer that points to the logger for the specified tenantToken and source.
*/
+(nullable id)loggerWithTenant:(NSString *)tenantToken
source:(NSString *)source;
/*!
@brief Retrieves a new instance of ODWLogger for logging telemetry events. It requires to previously call "loggerWithTenant" method
@param source A string that contains the name of the source of events sent by this logger instance.
@return An ODWLogger instance that points to the logger for source.
*/
+(nullable id)loggerForSource:(NSString *)source;
/*!
@brief Attempts to send any pending telemetry events that are currently cached either in memory, or on disk. Use this method if your event can't wait for automatic timed upload
*/
+(void)uploadNow;
/*!
@brief Flushes pending telemetry events from memory to disk (to reduce possible data loss).
*/
+(void)flush;
/*!
@brief Sets the transmit profile for event transmission.
@details A transmit profile is a collection of hardware and system settings (like network connectivity, power state, etc.)
that determines how efficiently telemetry events are transmitted.
@param profile The transmit profile to set&mdash;as one of the ::ODWTransmissionProfile enumeration values.
*/
+(void)setTransmissionProfile:(ODWTransmissionProfile)profile;
/*!
@brief Pauses the transmission of telemetry events to the data collector.
@details While paused, events continue to be queued on the client side&mdash;cached either in memory or on disk.
*/
+(void)pauseTransmission;
/*!
@brief Resumes the transmission of telemetry events to the data collector.
*/
+(void)resumeTransmission;
/*!
@brief Flushes pending telemetry events from memory to disk, and tears-down the telemetry logging system.
*/
+(void)flushAndTeardown;
/*!
@brief Resets the transmit profiles to contain only default profiles.
*/
+(void)resetTransmitProfiles;
@end
NS_ASSUME_NONNULL_END
#include "objc_end.h"

Просмотреть файл

@ -0,0 +1,98 @@
#import <Foundation/Foundation.h>
#import "ODWLogManager.h"
#import "ODWLogger_private.h"
#include "LogManager.hpp"
using namespace MAT;
using namespace Microsoft::Applications::Events;
LOGMANAGER_INSTANCE
@implementation ODWLogManager
+(nullable id)loggerWithTenant:(nonnull NSString *)tenantToken
{
ILogger* logger = [ODWLogManager initializeLogManager:tenantToken];
if(!logger) return nil;
return [[ODWLogger alloc] initWithILogger: logger];
}
+(nullable id)loggerWithTenant:(nonnull NSString *)tenantToken
source:(nonnull NSString *)source
{
ILogger* logger = [ODWLogManager initializeLogManager:tenantToken];
if(!logger) return nil;
std::string strToken = std::string([tenantToken UTF8String]);
std::string strSource = std::string([source UTF8String]);
logger = LogManager::GetLogger(strToken, strSource);
if(!logger) return nil;
return [[ODWLogger alloc] initWithILogger: logger];
}
+(ILogger *)initializeLogManager:(nonnull NSString *)tenantToken
{
std::string strToken = std::string([tenantToken UTF8String]);
ILogger* logger = LogManager::Initialize(strToken);
// Obtain semantics values
NSBundle* bundle = [NSBundle mainBundle];
std::string strUserLocale = std::string([[[NSLocale currentLocale] localeIdentifier] UTF8String]);
std::string strBundleVersion = std::string([[bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] UTF8String]);
NSString* appLanguage = [[bundle preferredLocalizations] firstObject];
NSString* appCountry = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
std::string strBundleLocale = std::string([[NSString stringWithFormat:@"%@-%@", appLanguage, appCountry] UTF8String]);
// Set semantics
ISemanticContext* semanticContext = LogManager::GetSemanticContext();
semanticContext->SetAppVersion(strBundleVersion);
semanticContext->SetAppLanguage(strBundleLocale);
semanticContext->SetUserLanguage(strUserLocale);
return logger;
}
+(nullable id)loggerForSource:(nonnull NSString *)source
{
std::string strSource = std::string([source UTF8String]);
ILogger* logger = LogManager::GetLogger(strSource);
if(!logger) return nil;
return [[ODWLogger alloc] initWithILogger: logger];
}
+(void)uploadNow
{
LogManager::UploadNow();
}
+(void)flush
{
LogManager::Flush();
}
+(void)flushAndTeardown
{
LogManager::FlushAndTeardown();
}
+(void)setTransmissionProfile:(ODWTransmissionProfile)profile
{
LogManager::SetTransmitProfile((TransmitProfile)profile);
}
+(void)pauseTransmission
{
LogManager::PauseTransmission();
}
+(void)resumeTransmission
{
LogManager::ResumeTransmission();
}
+(void)resetTransmitProfiles
{
LogManager::ResetTransmitProfiles();
}
@end

Просмотреть файл

@ -0,0 +1,80 @@
#include "objc_begin.h"
#import "ODWEventProperties.h"
NS_ASSUME_NONNULL_BEGIN
/*!
The <b>ODWLogger</b> class represents an event's properties.
*/
@interface ODWLogger : NSObject
#pragma mark Basic LogEvent methods
/*!
@brief Logs a custom event with a specified name.
@param name A string that contains the name of the event.
*/
-(void)logEventWithName:(NSString *)name;
/*!
@brief Logs a custom event with a specified set of properties.
@param properties The custom event properties, encapsulated within an ODWEventProperties object.
*/
-(void)logEventWithEventProperties:(ODWEventProperties *)properties;
#pragma mark Semantic LogEvent methods
/*!
@brief Logs a failure event (such as an application exception), taking a signature, failure details, and event properties.
@param signature A string that identifies the bucket of the failure.
@param detail A string that contains a description of the failure.
@param properties Properties of the failure event, encapsulated within an ODWEventProperties object. <b>Note:</b> This value can be null.
*/
-(void)logFailureWithSignature:(NSString *)signature
detail:(NSString *)detail
eventproperties:(ODWEventProperties *)properties;
/*!
@brief Logs a failure event&mdash;such as an application exception.
@param signature A string that identifies the bucket of the failure.
@param detail A string that contains a description of the failure.
@param category A string that contains the category of the failure&mdash;such as an application error, the spplication stops responding, or a crash.
@param identifier A string that contains that uniquely identifies this failure.
@param properties Properties of the failure event, encapsulated within an ODWEventProperties object.
*/
-(void)logFailureWithSignature:(NSString *)signature
detail:(NSString *)detail
category:(NSString *)category
id:(NSString *)identifier
eventProperties:(ODWEventProperties *)properties;
/*!
@brief Logs a page action event.
@param identifier A string that contains that uniquely identifies the page view.
@param pageName The page name.
@param properties Properties of the page action event, encapsulated within an ODWEventProperties object.
*/
-(void)logPageViewWithId:(NSString *)identifier
pageName:(NSString *)pageName
eventProperties:(ODWEventProperties *)properties;
/*!
@brief Logs a page action event.
@param identifier A string that contains that uniquely identifies the page view.
@param pageName The page name.
@param category A string that contains the name of the category this page belongs to.
@param uri A string that contains the URI of this page.
@param referrerUri A string that contains the URI that refers to this page.
@param properties Properties of the page action event, encapsulated within an ODWEventProperties object.
*/
-(void)logPageViewWithId:(NSString *)identifier
pageName:(NSString *)pageName
category:(NSString *)category
uri:(NSString *)uri
referrerUri:(NSString *)referrerUri
eventProperties:(ODWEventProperties *)properties;
@end
NS_ASSUME_NONNULL_END
#include "objc_end.h"

133
wrappers/obj-c/ODWLogger.mm Normal file
Просмотреть файл

@ -0,0 +1,133 @@
#include "ILogger.hpp"
#import <Foundation/Foundation.h>
#import "ODWLogger_private.h"
using namespace MAT;
@implementation ODWLogger
ILogger* _wrappedLogger;
-(instancetype)initWithILogger:(ILogger*)logger
{
self = [super init];
if(self){
_wrappedLogger = logger;
NSLog(@"Logger initialized successfully");
}
return self;
}
-(void) logEventWithName:(NSString *)name
{
std::string eventName = std::string([name UTF8String]);
EventProperties event(eventName);
_wrappedLogger->LogEvent(event);
NSLog(@"Log event with name: %@",name);
}
-(void) unwrapEventProperties: (ODWEventProperties*) wrappedProperties onEvent:(EventProperties&) event
{
std::string strName = std::string([[wrappedProperties name] UTF8String]);
event.SetName(strName);
ODWEventPriority priority = [wrappedProperties priority];
if (priority != ODWEventPriorityUnspecified)
{
event.SetPriority((EventPriority)priority);
}
NSDictionary* props = [wrappedProperties properties];
for(NSString* propertyName in props){
NSObject* value = [props objectForKey: propertyName];
std::string strPropertyName = std::string([propertyName UTF8String]);
if([value isKindOfClass: [NSNumber class]]){
NSNumber* num = (NSNumber*)value;
if(strcmp([num objCType], @encode(BOOL))==0 ) {
event.SetProperty(strPropertyName, [num boolValue] ? true : false);
}
else if( strcmp([num objCType], @encode(int))==0 ){
event.SetProperty(strPropertyName, [num intValue]);
}else{
event.SetProperty(strPropertyName, [num floatValue]);
}
}else{
NSString* str = (NSString*)value;
event.SetProperty(strPropertyName, [str UTF8String]);
}
}
}
-(void) logEventWithEventProperties: (nonnull ODWEventProperties*) properties
{
EventProperties event;
[self unwrapEventProperties: properties onEvent: event];
_wrappedLogger->LogEvent(event);
NSLog(@"Log event with name: %@",[properties name]);
}
-(void) logFailureWithSignature: (nonnull NSString*) signature
detail: (nonnull NSString*) detail
eventproperties: (nonnull ODWEventProperties*) properties
{
EventProperties event;
[self unwrapEventProperties: properties onEvent: event];
std::string strSignature = std::string([signature UTF8String]);
std::string strDetail = std::string([detail UTF8String]);
_wrappedLogger->LogFailure(strSignature, strDetail, event);
NSLog(@"Log failure with signature: %@, detail: %@ and name: %@",signature, detail, [properties name]);
}
-(void) logFailureWithSignature: (nonnull NSString*) signature
detail: (nonnull NSString*) detail
category: (nonnull NSString*) category
id: (nonnull NSString*) identifier
eventProperties: (nonnull ODWEventProperties*) properties
{
EventProperties event;
[self unwrapEventProperties: properties onEvent: event];
std::string strSignature = std::string([signature UTF8String]);
std::string strDetail = std::string([detail UTF8String]);
std::string strCategory = std::string([category UTF8String]);
std::string strId = std::string([identifier UTF8String]);
_wrappedLogger->LogFailure(strSignature, strDetail, strCategory, strId, event);
NSLog(@"Log failure with signature %@, detail %@, category: %@, id: %@ and name: %@",signature, detail, category, identifier, [properties name]);
}
-(void) logPageViewWithId: (nonnull NSString*) identifier
pageName: (nonnull NSString*) pageName
eventProperties: (nonnull ODWEventProperties*) properties
{
EventProperties event;
[self unwrapEventProperties: properties onEvent: event];
std::string strId = std::string([identifier UTF8String]);
std::string strPageName = std::string([pageName UTF8String]);
_wrappedLogger->LogPageView(strId, strPageName, event);
NSLog(@"Log page view with id: %@, page name: %@ and name %@", identifier, pageName, [properties name]);
}
-(void) logPageViewWithId: (nonnull NSString*) identifier
pageName: (nonnull NSString*) pageName
category: (nonnull NSString*) category
uri: (nonnull NSString*) uri
referrerUri: (nonnull NSString*) referrerUri
eventProperties: (nonnull ODWEventProperties*) properties
{
EventProperties event;
[self unwrapEventProperties: properties onEvent: event];
std::string strId = std::string([identifier UTF8String]);
std::string strPageName = std::string([pageName UTF8String]);
std::string strCategory = std::string([category UTF8String]);
std::string strUri = std::string([uri UTF8String]);
std::string strReferrerUri = std::string([referrerUri UTF8String]);
_wrappedLogger->LogPageView(strId, strPageName, strCategory, strUri, strReferrerUri, event);
NSLog(@"Log page view with id: %@, page name: %@, category: %@, uri: %@, referrer uri: %@ and name %@", identifier, pageName, category, uri, referrerUri, [properties name]);
}
@end

Просмотреть файл

@ -0,0 +1,23 @@
#include "objc_begin.h"
#include "ILogger.hpp"
#import "ODWLogger.h"
#import "ODWEventProperties.h"
NS_ASSUME_NONNULL_BEGIN
using namespace MAT;
/*!
The <b>ODWLogger</b> class represents an event's properties.
*/
@interface ODWLogger (Private)
/*!
@brief Constructs an ODWLogger object, taking internal API logger pointer. This method might be only used internally by wrapper. Use ODWLogManager initForTenant instead
*/
-(instancetype)initWithILogger:(ILogger *)logger;
@end
NS_ASSUME_NONNULL_END
#include "objc_end.h"

Просмотреть файл

@ -1,31 +0,0 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface WEventProperties : NSObject
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) NSMutableDictionary<NSString*, NSObject*> * propertiesStorage;
-(id) init;
-(id) initWithName: (nonnull NSString*) name;
-(id) initWithName: (nonnull NSString*) name
andProperties: (NSDictionary<NSString*,NSObject*>*) properties;
-(void) setName: (nonnull NSString*) name;
-(NSString*) getName;
-(NSMutableDictionary<NSString*, NSObject*> *) getProperties;
-(void) setPropertyWithName: (NSString*) name withStringValue: (NSString*) value;
-(void) setPropertyWithName: (NSString*) name withDoubleValue: (double) value;
-(void) setPropertyWithName: (NSString*) name withInt64Value: (int64_t) value;
-(void) setPropertyWithName: (NSString*) name withBoolValue: (BOOL) value;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -1,56 +0,0 @@
#import "WEventProperties.h"
@implementation WEventProperties
-(id) init {
self = [super init];
if(self){
_name = @"";
_propertiesStorage = [[NSMutableDictionary<NSString*,NSObject*> alloc] init];
NSLog(@"EventProperties initialized successfully");
}
return self;
}
-(id) initWithName: (nonnull NSString*) name {
[self init];
_name = name;
return self;
}
-(id) initWithName: (nonnull NSString*) name
andProperties: (NSDictionary<NSString*,NSObject*>*) properties {
[self initWithName: name];
_propertiesStorage = [properties mutableCopy];
return self;
}
-(void) setName: (nonnull NSString*) name {
_name = name;
}
-(NSString*) getName{
return _name;
}
-(NSMutableDictionary<NSString*, NSObject*> *) getProperties{
return _propertiesStorage;
}
-(void) setPropertyWithName: (NSString*) name withStringValue: (NSString*) value{
[_propertiesStorage setValue:value forKey:name];
}
-(void) setPropertyWithName: (NSString*) name withDoubleValue: (double) value{
[_propertiesStorage setValue:@(value) forKey:name];
}
-(void) setPropertyWithName: (NSString*) name withInt64Value: (int64_t) value{
[_propertiesStorage setValue:@(value) forKey:name];
}
-(void) setPropertyWithName: (NSString*) name withBoolValue: (BOOL) value{
[_propertiesStorage setValue:[NSNumber numberWithBool:value] forKey:name];
}
@end

Просмотреть файл

@ -1,25 +0,0 @@
#import <Foundation/Foundation.h>
#include "LogManager.hpp"
#import "WLogger.h"
#include <cstdio>
NS_ASSUME_NONNULL_BEGIN
using namespace MAT;
@interface WLogManager : NSObject
+(nullable id) initForTenant: (nonnull NSString*) tenantToken;
+(nullable id) getLogger;
+(nullable id) getLoggerForSource: (nonnull NSString*) source;
+(void) uploadNow;
+(void) flush;
+(void) pauseTransmission;
+(void) resumeTransmission;
+(void) flushAndTeardown;
+(void) resetTransmitProfiles;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -1,79 +0,0 @@
#import "WLogManager.h"
LOGMANAGER_INSTANCE
@implementation WLogManager
+(nullable id) initForTenant: (nonnull NSString*) tenantToken{
/*printf("Setting up configuration...\n");
auto& config = LogManager::GetLogConfiguration();
config["name"] = "SampleObjectiveC";
config["version"] = "1.2.5";
config["config"]["host"] = "SampleObjectiveC"; // host
config["compat"]["dotType"] = false; // Legacy v1 behaviour with respect to SetType using underscore instead of a dot
config[CFG_STR_CACHE_FILE_PATH] = "/tmp/offlinestorage.db";
config[CFG_INT_TRACE_LEVEL_MASK] = 0; // 0xFFFFFFFF ^ 128;
config[CFG_INT_TRACE_LEVEL_MIN] = ACTTraceLevel_Warn; // ACTTraceLevel_Info; // ACTTraceLevel_Debug;
config[CFG_INT_SDK_MODE] = SdkModeTypes::SdkModeTypes_CS;
config[CFG_INT_MAX_TEARDOWN_TIME] = 10;
config[CFG_INT_RAM_QUEUE_SIZE] = 32 * 1024 * 1024; // 32 MB heap limit for sqlite3
config[CFG_INT_CACHE_FILE_SIZE] = 16 * 1024 * 1024; // 16 MB storage file limit*/
std::string strToken = std::string([tenantToken UTF8String]);
ILogger* logger = LogManager::Initialize(strToken);
// This global context variable will not be seen by C API client
LogManager::SetContext("GlobalContext.Var", 12345);
printf("LogManager::GetSemanticContext \n");
ISemanticContext* semanticContext = LogManager::GetSemanticContext();
semanticContext->SetAppId("ObjectiveC_App"); // caller must obtain this from app manifest, e.g. .plist on Mac OS X
semanticContext->SetAppVersion("1.0.1"); // caller must obtain this from app manifest, e.g. .plist on Mac OS X
semanticContext->SetAppLanguage("en-US"); // caller must obtain this from app manifest, e.g. .plist on Mac OS X
semanticContext->SetUserLanguage("en-US"); // caller must obtain the user language from preferences
if(!logger) return nil;
return [[WLogger alloc] initWithILogger: logger];
}
+(nullable id) getLogger{
ILogger* logger = LogManager::GetLogger();
if(!logger) return nil;
return [[WLogger alloc] initWithILogger: logger];
}
+(nullable id) getLoggerForSource: (nonnull NSString*) source{
std::string strSource = std::string([source UTF8String]);
ILogger* logger = LogManager::GetLogger(strSource);
if(!logger) return nil;
return [[WLogger alloc] initWithILogger: logger];
}
+(void) uploadNow{
LogManager::UploadNow();
}
+(void) flush{
LogManager::Flush();
}
+(void) flushAndTeardown{
LogManager::FlushAndTeardown();
}
+(void) pauseTransmission{
LogManager::PauseTransmission();
}
+(void) resumeTransmission{
LogManager::ResumeTransmission();
}
+(void) resetTransmitProfiles{
LogManager::ResetTransmitProfiles();
}
@end

Просмотреть файл

@ -1,47 +0,0 @@
#import <Foundation/Foundation.h>
#import "WEventProperties.h"
#include "ILogger.hpp"
NS_ASSUME_NONNULL_BEGIN
using namespace MAT;
@interface WLogger : NSObject{
ILogger* wrappedLogger;
}
-(id) initWithILogger : (ILogger*) logger;
-(void) logEventWithName: (nonnull NSString*) name;
-(void) logEventWithWEventProperties: (nonnull WEventProperties*) properties;
-(void) logFailureWithSignature: (nonnull NSString*) aSignature
detail: (nonnull NSString*) aDetail
eventproperties: (nonnull WEventProperties*) properties;
-(void) logFailureWithSignature: (nonnull NSString*) aSignature
detail: (nonnull NSString*) aDetail
category: (nonnull NSString*) aCategory
id: (nonnull NSString*) anId
eventProperties: (nonnull WEventProperties*) properties;
-(void) logPageViewWithId: (nonnull NSString*) anID
pageName: (nonnull NSString*) aPageName
eventProperties: (nonnull WEventProperties*) properties;
-(void) logPageViewWithId: (nonnull NSString*) anId
pageName: (nonnull NSString*) aPageName
eventProperties: (nonnull WEventProperties*) properties;
-(void) logPageViewWithId: (nonnull NSString*) anId
pageName: (nonnull NSString*) aPageName
category: (nonnull NSString*) aCategory
uri: (nonnull NSString*) anUri
referrerUri: (nonnull NSString*) aReferrerUri
eventProperties: (nonnull WEventProperties*) properties;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -1,116 +0,0 @@
#import "WLogger.h"
@implementation WLogger
-(id) initWithILogger : (ILogger*) logger{
self = [super init];
if(self){
wrappedLogger = logger;
NSLog(@"Logger initialized successfully");
}
return self;
}
-(void) logEventWithName:(NSString *)name{
std::string eventName = std::string([name UTF8String]);
EventProperties event(eventName);
wrappedLogger->LogEvent(event);
NSLog(@"Log event with name: %@",name);
}
-(void) unwrapWEventProperties: (WEventProperties*) wrappedProperties onEvent:(EventProperties&) event{
std::string strName = std::string([[wrappedProperties getName] UTF8String]);
event.SetName(strName);
NSMutableDictionary* props = [wrappedProperties getProperties];
for(NSString* propertyName in props){
NSObject* value = [props objectForKey: propertyName];
std::string strPropertyName = std::string([propertyName UTF8String]);
if([value isKindOfClass: [NSNumber class]]){
NSNumber* num = (NSNumber*)value;
if(strcmp([num objCType], @encode(BOOL))==0 ) {
event.SetProperty(strPropertyName, [num boolValue] ? true : false);
}
else if( strcmp([num objCType], @encode(int))==0 ){
event.SetProperty(strPropertyName, [num intValue]);
}else{
event.SetProperty(strPropertyName, [num floatValue]);
}
}else{
NSString* str = (NSString*)value;
event.SetProperty(strPropertyName, [str UTF8String]);
}
}
}
-(void) logEventWithWEventProperties: (nonnull WEventProperties*) properties{
EventProperties event;
[self unwrapWEventProperties: properties onEvent: event];
wrappedLogger->LogEvent(event);
NSLog(@"Log event with name: %@",[properties getName]);
}
-(void) logFailureWithSignature: (nonnull NSString*) aSignature
detail: (nonnull NSString*) aDetail
eventproperties: (nonnull WEventProperties*) properties{
EventProperties event;
[self unwrapWEventProperties: properties onEvent: event];
std::string strSignature = std::string([aSignature UTF8String]);
std::string strDetail = std::string([aDetail UTF8String]);
wrappedLogger->LogFailure(strSignature, strDetail, event);
NSLog(@"Log failure with signature: %@, detail: %@ and name: %@",aSignature, aDetail, [properties getName]);
}
-(void) logFailureWithSignature: (nonnull NSString*) aSignature
detail: (nonnull NSString*) aDetail
category: (nonnull NSString*) aCategory
id: (nonnull NSString*) anId
eventProperties: (nonnull WEventProperties*) properties{
EventProperties event;
[self unwrapWEventProperties: properties onEvent: event];
std::string strSignature = std::string([aSignature UTF8String]);
std::string strDetail = std::string([aDetail UTF8String]);
std::string strCategory = std::string([aCategory UTF8String]);
std::string strId = std::string([anId UTF8String]);
wrappedLogger->LogFailure(strSignature, strDetail, strCategory, strId, event);
NSLog(@"Log failure with signature %@, detail %@, category: %@, id: %@ and name: %@",aSignature, aDetail, aCategory, anId, [properties getName]);
}
-(void) logPageViewWithId: (nonnull NSString*) anId
pageName: (nonnull NSString*) aPageName
eventProperties: (nonnull WEventProperties*) properties{
EventProperties event;
[self unwrapWEventProperties: properties onEvent: event];
std::string strId = std::string([anId UTF8String]);
std::string strPageName = std::string([aPageName UTF8String]);
wrappedLogger->LogPageView(strId, strPageName, event);
NSLog(@"Log page view with id: %@, page name: %@ and name %@", anId, aPageName, [properties getName]);
}
-(void) logPageViewWithId: (nonnull NSString*) anId
pageName: (nonnull NSString*) aPageName
category: (nonnull NSString*) aCategory
uri: (nonnull NSString*) anUri
referrerUri: (nonnull NSString*) aReferrerUri
eventProperties: (nonnull WEventProperties*) properties{
EventProperties event;
[self unwrapWEventProperties: properties onEvent: event];
std::string strId = std::string([anId UTF8String]);
std::string strPageName = std::string([aPageName UTF8String]);
std::string strCategory = std::string([aCategory UTF8String]);
std::string strUri = std::string([anUri UTF8String]);
std::string strReferrerUri = std::string([aReferrerUri UTF8String]);
wrappedLogger->LogPageView(strId, strPageName, strCategory, strUri, strReferrerUri, event);
NSLog(@"Log page view with id: %@, page name: %@, category: %@, uri: %@, referrer uri: %@ and name %@", anId, aPageName, aCategory, anUri, aReferrerUri, [properties getName]);
}
@end

Просмотреть файл

@ -1,43 +1,42 @@
#import <Foundation/Foundation.h>
#import "WLogManager.h"
#import "WLogger.h"
#import "WEventProperties.h"
#import "ODWLogManager.h"
#import "ODWLogger.h"
#import "ODWEventProperties.h"
int main(int argc, char** argv){
@autoreleasepool{
// 1DSCppSdkTest sandbox key. Replace with your own iKey!
NSString* token = @"7c8b1796cbc44bd5a03803c01c2b9d61-b6e370dd-28d9-4a52-9556-762543cf7aa7-6991";
WLogger* myLogger = [WLogManager initForTenant: token];
ODWLogger* myLogger = [ODWLogManager loggerWithTenant: token];
if(myLogger){
[myLogger logEventWithName: @"Simple_ObjC_Event"];
}
[WLogManager uploadNow];
[ODWLogManager uploadNow];
WEventProperties* event = [[WEventProperties alloc] initWithName: @"WEvtProps_ObjC_Event"
andProperties: @{
ODWEventProperties* event = [[ODWEventProperties alloc] initWithName: @"WEvtProps_ObjC_Event"
properties: @{
@"result": @"Success",
@"seq": @2,
@"random": @3,
@"secret": @5.75
} ];
WLogger* logger2 = [WLogManager getLoggerForSource: @"source2"];
ODWLogger* logger2 = [ODWLogManager loggerForSource: @"source2"];
if(logger2){
[logger2 logEventWithWEventProperties: event];
[logger2 logEventWithEventProperties: event];
}
[WLogManager uploadNow];
[ODWLogManager uploadNow];
WEventProperties* event2 = [[WEventProperties alloc] init];
[event2 setName: @"SetProps_ObjC_Event"];
[event2 setPropertyWithName: @"result" withStringValue: @"Failure"];
[event2 setPropertyWithName: @"intVal" withInt64Value: (int64_t)8165];
[event2 setPropertyWithName: @"doubleVal" withDoubleValue: (double)1.24];
[event2 setPropertyWithName: @"wasSuccessful" withBoolValue: YES];
ODWEventProperties* event2 = [[ODWEventProperties alloc] initWithName:@"SetProps_ObjC_Event"];
[event2 setProperty: @"result" withValue: @"Failure"];
[event2 setProperty: @"intVal" withInt64Value: (int64_t)8165];
[event2 setProperty: @"doubleVal" withDoubleValue: (double)1.24];
[event2 setProperty: @"wasSuccessful" withBoolValue: YES];
[logger2 logEventWithWEventProperties: event2];
[logger2 logEventWithEventProperties: event2];
[WLogManager flushAndTeardown];
[ODWLogManager flushAndTeardown];
}
return 0;
}

Просмотреть файл

@ -0,0 +1,41 @@
/*
If the source file or header file is contaminated by Windows headers,
Wrap the pure Objective-C part with #include <objc_begin.h> and #include <objc_end.h>.
These inclusions always have to come together and be balanced
The primary goal is to take care of "interface" and "BOOL" conflicts
// Whenever possible, avoid contaminated source or header.
// For legacy,
// - if the header is pure Objective-C, put the wrap in the contaminated source that includes it.
// - if the header itself is contaminated, put the wrap in the header
*/
#if !__OBJC__
#error "this file should be used only in Obj-C code"
#endif
//make sure "interface" is not #defined
//this check seemingly does nothing but it works around a freakish clang preprocessor bug
//that sometimes push_macro/pop_macro does not work. VSO:142920
#if defined(interface)
#endif
#pragma push_macro("interface")
#if defined(interface)
#undef interface
#endif
//make sure "BOOL" is not #defined
//this check seemingly does nothing but it works around a freakish clang preprocessor bug
#if defined(BOOL)
#endif
#pragma push_macro("BOOL")
#if defined(BOOL)
#undef BOOL
#endif

10
wrappers/obj-c/objc_end.h Normal file
Просмотреть файл

@ -0,0 +1,10 @@
/*
Balance #include <objc_begin.h>
*/
#if !__OBJC__
#error "this file should be used only in Obj-C code"
#endif
#pragma pop_macro("interface")
#pragma pop_macro("BOOL")