Skip to content

Commit

Permalink
Update sources
Browse files Browse the repository at this point in the history
  • Loading branch information
t-gazzy committed Oct 3, 2024
1 parent 0541eb1 commit 3a54055
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Sources/Core/Platform/PlatformInfoDelegator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ namespace platform {

class PlatformInfoDelegator : public interface::PlatformInfoDelegator {
public:
PlatformInfoDelegator();
~PlatformInfoDelegator();
std::string GetPlatform() const override;
std::string GetOsInfo() const override;
std::string GetModelName() const override;
std::string GetSdkVersion() const override;
private:
class Impl;
std::unique_ptr<Impl> impl_;
};

} // namespace platform
Expand Down
67 changes: 57 additions & 10 deletions Sources/Core/Platform/PlatformInfoDelegator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,72 @@
#import <sys/utsname.h>

#include "NSString+StdString.h"
#include "skyway/global/interface/logger.hpp"

@interface PlatformDelegator : NSObject

@property(nonatomic, readonly) NSString* platform;
@property(nonatomic, readonly) NSString* osInfo;
@property(nonatomic, readonly) NSString* modelName;
@property(nonatomic, readonly) NSString* sdkVersion;

- (id)init;

@end

@implementation PlatformDelegator

- (id)init {
if (self = [super init]) {
_platform = @"ios";

// os
NSString* systemName = [UIDevice currentDevice].systemName;
NSString* systemVersion = [UIDevice currentDevice].systemVersion;
_osInfo = [NSString stringWithFormat:@"%@ %@", systemName, systemVersion];

// model
struct utsname systemInfo;
uname(&systemInfo);
_modelName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

// sdk version
NSBundle* bundle = [NSBundle bundleForClass:self.class];
_sdkVersion = [bundle infoDictionary][@"CFBundleShortVersionString"];
}
return self;
}

@end

namespace skyway {
namespace platform {

std::string PlatformInfoDelegator::GetPlatform() const { return "ios"; }
class PlatformInfoDelegator::Impl {
public:
Impl() : delegator_([[PlatformDelegator alloc] init]) {}
PlatformDelegator* delegator_;
};

PlatformInfoDelegator::PlatformInfoDelegator()
: impl_(std::make_unique<PlatformInfoDelegator::Impl>()) {}

PlatformInfoDelegator::~PlatformInfoDelegator(){SKW_TRACE("~PlatformInfoDelegator")}

std::string PlatformInfoDelegator::GetPlatform() const {
return [NSString stdStringForString:impl_->delegator_.platform];
}

std::string PlatformInfoDelegator::GetOsInfo() const {
NSString* systemName = [UIDevice currentDevice].systemName;
NSString* systemVersion = [UIDevice currentDevice].systemVersion;
NSString* osInfo = [NSString stringWithFormat:@"%@ %@", systemName, systemVersion];
return [NSString stdStringForString:osInfo];
return [NSString stdStringForString:impl_->delegator_.osInfo];
}

std::string PlatformInfoDelegator::GetModelName() const {
struct utsname systemInfo;
uname(&systemInfo);
NSString* modelName = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
return [NSString stdStringForString:modelName];
return [NSString stdStringForString:impl_->delegator_.modelName];
}

std::string PlatformInfoDelegator::GetSdkVersion() const {
return [NSString stdStringForString:impl_->delegator_.sdkVersion];
}

} // namespace platform
Expand Down

0 comments on commit 3a54055

Please sign in to comment.