Skip to content

Commit

Permalink
KAA-292: implement Objective-C SDK; add ability to generate Objective…
Browse files Browse the repository at this point in the history
…-C SDK dynamically.
  • Loading branch information
abohomol committed Dec 4, 2015
1 parent 4feb902 commit 5f0db5c
Show file tree
Hide file tree
Showing 361 changed files with 37,792 additions and 34 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Expand Up @@ -28,4 +28,34 @@ pom.xml.versionsBackup
examples/*/source/lib/
examples/*/source/java/lib/
server/common/dao/src/main/resources/dao.properties

build/
DerivedData
Pods/

!Podfile.lock
!Manifest.lock

.DS_Store
*~
*.swp
*.rbc

*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
!default.xcworkspace
xcuserdata
*.xccheckout
profile
!scripts/profile
*.moved-aside
*.hmap
*.ipa
Tests/Pods
Tests/Podfile.lock
1 change: 0 additions & 1 deletion avrogenc/.gitignore

This file was deleted.

2,426 changes: 2,426 additions & 0 deletions client/client-multi/client-objective-c/Kaa.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,30 @@
{
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "0CA4F3CFE55A12407B44C8109D3620D699EFEF07",
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"0CA4F3CFE55A12407B44C8109D3620D699EFEF07" : 0,
"B401B74FA4825A3AF8BEAD942EB222B09AC26B7C" : 0
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "8FE1BCB9-AB7D-4D85-B95B-A4B1D479C183",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"0CA4F3CFE55A12407B44C8109D3620D699EFEF07" : "kaa-client-objective-c",
"B401B74FA4825A3AF8BEAD942EB222B09AC26B7C" : "..\/.."
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "Kaa",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Kaa.xcworkspace",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:abohomol\/kaa-client-objective-c.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "0CA4F3CFE55A12407B44C8109D3620D699EFEF07"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:kaaproject\/kaa.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B401B74FA4825A3AF8BEAD942EB222B09AC26B7C"
}
]
}
@@ -0,0 +1,34 @@
/*
* Copyright 2014-2015 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "ConfigurationCommon.h"
#import "KaaClientProperties.h"
#import "ConfigurationDeserializer.h"
#import "KaaClientState.h"
#import "ExecutorContext.h"

@interface AbstractConfigurationManager : NSObject <ConfigurationManager>

@property(nonatomic,strong,readonly) ConfigurationDeserializer *deserializer;

- (instancetype)initWithClientProperties:(KaaClientProperties *)properties state:(id<KaaClientState>)state andExecutorContext:(id<ExecutorContext>)context;

- (NSData *)getConfigurationData;

- (NSData *)getDefaultConfiguratioData;

@end
@@ -0,0 +1,143 @@
/*
* Copyright 2014-2015 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "AbstractConfigurationManager.h"
#import "KaaLogging.h"

#define TAG @"AbstractConfigurationManager >>>"

@interface AbstractConfigurationManager ()

@property(nonatomic,strong) KaaClientProperties *properties;
@property(nonatomic,strong) id<KaaClientState> state;
@property(nonatomic,strong) id<ConfigurationStorage> storage;
@property(nonatomic,strong) NSData *configurationData;
@property(nonatomic,strong) id<ExecutorContext> executorContext;

@property(strong) NSMutableSet *delegates;
@property(strong) NSLock *delegatesLock;

- (NSData *)loadConfigurationData;

@end

@implementation AbstractConfigurationManager

- (instancetype)initWithClientProperties:(KaaClientProperties *)properties state:(id<KaaClientState>)state andExecutorContext:(id<ExecutorContext>)context {
self = [super init];
if (self) {
self.delegates = [NSMutableSet set];
self.properties = properties;
self.state = state;
_deserializer = [[ConfigurationDeserializer alloc] initWithExecutorContext:context];
self.executorContext = context;
}
return self;
}

- (void)initiate {
[self getConfigurationData];
DDLogDebug(@"%@ Configuration manager init completed!", TAG);
}

- (void)addDelegate:(id<ConfigurationDelegate>)delegate {
if (delegate) {
DDLogVerbose(@"%@ Adding delegate %@", TAG, delegate);
[self.delegatesLock lock];
[self.delegates addObject:delegate];
[self.delegatesLock unlock];
} else {
[NSException raise:NSInvalidArgumentException format:@"Can't add nil delegate"];
}
}

- (void)removeDelegate:(id<ConfigurationDelegate>)delegate {
if (delegate) {
DDLogVerbose(@"%@ Removing delegate", TAG);
[self.delegatesLock lock];
[self.delegates removeObject:delegate];
[self.delegatesLock unlock];
} else {
[NSException raise:NSInvalidArgumentException format:@"Can't remove nil delegate"];

}
}

- (void)processConfigurationData:(NSData *)data fullResync:(BOOL)fullResync {
if (fullResync) {
self.configurationData = data;
DDLogVerbose(@"%@ Received configuration data: %@", TAG, self.configurationData);
if (self.storage) {
DDLogDebug(@"%@ Persisting configuration data from storage: %@", TAG, self.storage);
[self.storage saveConfiguration:self.configurationData];
DDLogDebug(@"%@ Persisted configuration data from storage: %@", TAG, self.storage);
}
[self.delegatesLock lock];
[_deserializer notify:self.delegates withData:self.configurationData];
[self.delegatesLock unlock];
} else {
DDLogWarn(@"%@ Only full resync delta is supported!", TAG);
}
}

- (EndpointObjectHash *)getConfigurationHash {
return [EndpointObjectHash fromSHA1:[self getConfigurationData]];
}

- (void)setConfigurationStorage:(id<ConfigurationStorage>)storage {
self.storage = storage;
}

- (NSData *)loadConfigurationData {
if (self.storage) {
if ([self.state isConfigurationVersionUpdated]) {
DDLogDebug(@"%@ Clearing old configuration data from storage: %@", TAG, self.storage);
@try {
[self.storage clearConfiguration];
}
@catch (NSException *exception) {
DDLogError(@"%@ Failed to clear configuration from storage: %@", TAG, exception);
}
} else {
DDLogDebug(@"%@ Loading configuration data from storage: %@", TAG, self.storage);
@try {
self.configurationData = [self.storage loadConfiguration];
}
@catch (NSException *exception) {
DDLogError(@"%@ Failed to load configuration from storage: %@", TAG, exception);
}
}
}
if (!self.configurationData) {
DDLogDebug(@"%@ Loading configuration data from defaults: %@", TAG, self.storage);
self.configurationData = [self getDefaultConfiguratioData];
}
DDLogVerbose(@"%@ Loaded configuration data: %@", TAG, self.configurationData);
return self.configurationData;
}

- (NSData *)getConfigurationData {
if (!self.configurationData) {
self.configurationData = [self loadConfigurationData];
}
return self.configurationData;
}

- (NSData *)getDefaultConfiguratioData {
return [self.properties defaultConfigData];
}

@end
@@ -0,0 +1,29 @@
/*
* Copyright 2014-2015 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "ExecutorContext.h"
#import "TimeCommons.h"

@interface AbstractExecutorContext : NSObject <ExecutorContext>

@property (nonatomic) NSInteger timeOut;
@property (nonatomic) TimeUnit timeUnit;

- (instancetype)initWithTimeOut:(NSInteger)timeOut andTimeUnit:(TimeUnit)timeUnit;
- (void)shutDownExecutor:(NSOperationQueue*)queue;

@end
@@ -0,0 +1,93 @@
/*
* Copyright 2014-2015 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


@import QuartzCore;
#import "AbstractExecutorContext.h"
#import "KaaLogging.h"

#define TAG @"AbstractExecutorContext >>>"

#define DEFAULT_TIMEOUT (5)
#define DEFAULT_TIMEUNIT TIME_UNIT_SECONDS

@implementation AbstractExecutorContext


- (instancetype)init {
return [self initWithTimeOut:DEFAULT_TIMEOUT andTimeUnit:DEFAULT_TIMEUNIT];
}

- (instancetype) initWithTimeOut:(NSInteger)timeOut andTimeUnit:(TimeUnit)timeUnit {
self = [super init];
if (self) {
self.timeOut = timeOut;
self.timeUnit = timeUnit;
}
return self;
}

- (void) shutDownExecutor:(NSOperationQueue*)queue {

if (!queue) {
DDLogWarn(@"%@ Can't shutdown empty executor", TAG);
return;
}

DDLogDebug(@"%@ Shutdown executor service", TAG);
[queue cancelAllOperations];
DDLogDebug(@"%@ Waiting for executor service to shutdown for %ld %u", TAG, (long)self.timeOut, self.timeUnit);
@try {
double fixedTime = CACurrentMediaTime();
while ([queue operationCount] && (CACurrentMediaTime() < (fixedTime + self.timeOut))) {
sleep(100);
}
}
@catch (NSException *exception) {
DDLogWarn(@"%@ Interrupted while waiting for executor to shutdown. Reason: %@", TAG, exception.reason);
}
}

- (NSOperationQueue *)getLifeCycleExecutor {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
return nil;
}

- (NSOperationQueue *)getApiExecutor {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
return nil;
}

- (NSOperationQueue *)getCallbackExecutor {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
return nil;
}

- (dispatch_queue_t)getSheduledExecutor {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
return nil;
}

- (void) stop {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
}

- (void) initiate {
[NSException raise:NSInternalInconsistencyException format:@"Not implemented in abstract class"];
}


@end

0 comments on commit 5f0db5c

Please sign in to comment.