Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow to not use auto restart, and to manually restart.

Change-Id: I03d58b2cbd1906a7347b411495600bf1bd201617
Reviewed-on: http://review.couchbase.org/9485
Reviewed-by: Jens Alfke <jens@couchbase.com>
Tested-by: Jens Alfke <jens@couchbase.com>
  • Loading branch information...
commit deeefaf5596e8acefff847fd65ed8ef53e4137d7 1 parent 8a9e541
@apage43 apage43 authored snej committed
View
7 Framework/Classes/CouchbaseMobile.h
@@ -47,6 +47,7 @@
NSString* _iniFilePath;
NSURL* _serverURL;
NSError* _error;
+ BOOL _autoRestart;
BOOL _started;
}
@@ -63,6 +64,9 @@
@return YES if the server is starting, NO if it failed to start. */
- (BOOL) start;
+/** Restart the server, necessary if app being suspended closes its listening socket */
+- (void) restart;
+
/** The HTTP URL the server is listening on.
Will be nil until the server has finished starting up, some time after -start is called.
This property is KV-observable, so an alternative to setting a delegate is to observe this
@@ -73,6 +77,9 @@
This is KV-observable. */
@property (readonly, retain) NSError* error;
+/** Defaults to YES, set to NO to prevent auto-restart behavior when app returns from background */
+@property (assign) BOOL autoRestart;
+
#pragma mark CONFIGURATION:
/** Initializes the instance with a nonstandard location for the runtime resources.
View
16 Framework/Classes/CouchbaseMobile.m
@@ -24,11 +24,14 @@
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
+#include <UIKit/UIApplication.h>
// Erlang entry point
void erl_start(int, char**);
static NSString* const kInternalCouchStartedNotification = @"couchStarted";
+static NSString* const kInternalRestartCouchNotification = @"CouchDBRequestRestart";
+
static const NSTimeInterval kWaitTimeout = 10.0; // How long to wait for CouchDB to start
@@ -82,6 +85,7 @@ - (id) initWithBundlePath: (NSString*)bundlePath {
- (id)init {
NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"CouchbaseResources" ofType:nil];
NSAssert(bundlePath, @"Couldn't find CouchbaseResources bundle in app's Resources directory");
+ _autoRestart = YES;
return [self initWithBundlePath: bundlePath];
}
@@ -97,7 +101,7 @@ - (void)dealloc {
}
-@synthesize delegate = _delegate, iniFilePath=_iniFilePath, serverURL = _serverURL, error = _error;
+@synthesize delegate = _delegate, iniFilePath=_iniFilePath, serverURL = _serverURL, error = _error, autoRestart = _autoRestart;
- (NSString*) logDirectory {
@@ -149,10 +153,20 @@ - (BOOL)start
[self performSelector: @selector(startupTimeout) withObject: nil afterDelay: kWaitTimeout];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(couchStarted:)
name:kInternalCouchStartedNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(maybeRestart)
+ name:UIApplicationWillEnterForegroundNotification object:nil];
[self performSelectorInBackground: @selector(erlangThread) withObject: nil];
return YES;
}
+- (void) maybeRestart {
+ if (_autoRestart) [self restart];
+}
+
+- (void) restart {
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:kInternalRestartCouchNotification object:nil];
+}
#pragma mark LAUNCHING ERLANG:
View
2  Framework/Couchbase.xcodeproj/project.pbxproj
@@ -78,6 +78,7 @@
3DEAEA6612A2D70B00EEBD22 /* erlang */ = {isa = PBXFileReference; lastKnownFileType = folder; name = erlang; path = ../erlang; sourceTree = "<group>"; };
79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CouchbaseMobile.h; sourceTree = "<group>"; };
79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CouchbaseMobile.m; sourceTree = "<group>"; };
+ D9243045141A6BAD002CD246 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -156,6 +157,7 @@
29B97323FDCFA39411CA2CEA /* Libraries */ = {
isa = PBXGroup;
children = (
+ D9243045141A6BAD002CD246 /* UIKit.framework */,
27167ECB13C4E644001CC5B6 /* libiErl14.a */,
27167ECD13C4E64B001CC5B6 /* libiMonkey.a */,
03E839481353ADE600D64D0D /* libcrypto-iphoneos.a */,
Please sign in to comment.
Something went wrong with that request. Please try again.