Skip to content
Browse files

Renamed CouchbaseEmbeddedServer->CouchbaseMobile

And some other namesmithing too.

Change-Id: I934d2abee130380702b432f011269690decd29d2
Reviewed-on: http://review.couchbase.org/9133
Reviewed-by: Chris Anderson <jchris@couchbase.com>
Tested-by: Jens Alfke <jens@couchbase.com>
  • Loading branch information...
1 parent 804e08e commit 03dedb148e6e6b12febb6e7232af994c6edd6b0a @snej snej committed Aug 19, 2011
View
2 EmptyApp/Source/EmptyAppDelegate.h
@@ -7,7 +7,7 @@
//
#import <UIKit/UIKit.h>
-#import <Couchbase/CouchbaseEmbeddedServer.h>
+#import <Couchbase/CouchbaseMobile.h>
@interface EmptyAppDelegate : UIResponder <UIApplicationDelegate, CouchbaseDelegate>
View
12 EmptyApp/Source/EmptyAppDelegate.m
@@ -13,7 +13,7 @@ @implementation EmptyAppDelegate
BOOL sUnitTesting;
-CouchbaseEmbeddedServer* sCouchbase; // Used by the unit tests
+CouchbaseMobile* sCouchbase; // Used by the unit tests
@synthesize window = _window;
@@ -28,7 +28,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.window makeKeyAndVisible];
// Initialize CouchDB:
- CouchbaseEmbeddedServer* cb = [[CouchbaseEmbeddedServer alloc] init];
+ CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
cb.delegate = self;
NSAssert([cb start], @"Couchbase couldn't start! Error = %@", cb.error);
sCouchbase = cb;
@@ -85,8 +85,7 @@ - (void)send: (NSString*)method toPath: (NSString*)relativePath body: (NSString*
}
-- (void)couchbaseDidStart:(NSURL *)serverURL {
- NSAssert(serverURL != nil, @"Couchbase failed to initialize");
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
NSLog(@"CouchDB is Ready, go!");
self.serverURL = serverURL;
@@ -102,4 +101,9 @@ - (void)couchbaseDidStart:(NSURL *)serverURL {
}
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase failedToStart:(NSError*)error {
+ NSAssert(NO, @"Couchbase failed to initialize: %@", error);
+}
+
+
@end
View
4 EmptyApp/Tests/EmptyAppTests.m
@@ -7,10 +7,10 @@
//
#import "EmptyAppTests.h"
-#import <Couchbase/CouchbaseEmbeddedServer.h>
+#import <Couchbase/CouchbaseMobile.h>
extern BOOL sUnitTesting;
-extern CouchbaseEmbeddedServer* sCouchbase; // Defined in EmptyAppDelegate.m
+extern CouchbaseMobile* sCouchbase; // Defined in EmptyAppDelegate.m
@implementation EmptyAppTests
View
20 Framework/Classes/CouchbaseEmbeddedServer.h → Framework/Classes/CouchbaseMobile.h
@@ -1,5 +1,5 @@
//
-// Couchbase.h
+// CouchbaseMobile.h
// Couchbase Mobile
//
// Created by J Chris Anderson on 3/2/11.
@@ -19,15 +19,25 @@
#import <Foundation/Foundation.h>
+@class CouchbaseMobile;
+
@protocol CouchbaseDelegate
@required
--(void)couchbaseDidStart:(NSURL *)serverURL;
+/** Called after a CouchbaseMobile instance finishes starting up.
+ @param couchbase The instance of CouchbaseMobile.
+ @param serverURL The URL at which the Couchbase server is listening. */
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL;
+
+/** Called after a CouchbaseMobile instance fails to start up.
+ @param couchbase The instance of CouchbaseMobile.
+ @param error The error that occurred. */
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase failedToStart:(NSError*)error;
@end
/** Manages an embedded instance of CouchDB that runs in a background thread. */
-@interface CouchbaseEmbeddedServer : NSObject
+@interface CouchbaseMobile : NSObject
{
id<CouchbaseDelegate> _delegate;
CFAbsoluteTime _timeStarted;
@@ -36,11 +46,11 @@
NSString* _iniFilePath;
NSURL* _serverURL;
NSError* _error;
- pthread_t _erlangThread;
+ BOOL _started;
}
/** Convenience to instantiate and start a new instance. */
-+ (CouchbaseEmbeddedServer*) startCouchbase: (id<CouchbaseDelegate>)delegate;
++ (CouchbaseMobile*) startCouchbase: (id<CouchbaseDelegate>)delegate;
/** Initializes the instance. */
- (id) init;
View
25 Framework/Classes/CouchbaseEmbeddedServer.m → Framework/Classes/CouchbaseMobile.m
@@ -1,5 +1,5 @@
//
-// Couchbase.m
+// CouchbaseMobile.m
// Couchbase Mobile
//
// Created by J Chris Anderson on 3/2/11.
@@ -17,7 +17,7 @@
// License for the specific language governing permissions and limitations under
// the License.
-#import "CouchbaseEmbeddedServer.h"
+#import "CouchbaseMobile.h"
#include <pthread.h>
#include <stdlib.h>
@@ -33,7 +33,7 @@
static const NSTimeInterval kWaitTimeout = 10.0; // How long to wait for CouchDB to start
-@interface CouchbaseEmbeddedServer ()
+@interface CouchbaseMobile ()
@property (readwrite, retain) NSURL* serverURL;
@property (readwrite, retain) NSError* error;
- (BOOL)createDir:(NSString*)dirName;
@@ -49,11 +49,11 @@ - (BOOL)deleteFile:(NSString*)filename fromDir: (NSString*)fromDir;
@end
-@implementation CouchbaseEmbeddedServer
+@implementation CouchbaseMobile
-+ (CouchbaseEmbeddedServer*) startCouchbase: (id<CouchbaseDelegate>)delegate {
- static CouchbaseEmbeddedServer* sCouchbase;
++ (CouchbaseMobile*) startCouchbase: (id<CouchbaseDelegate>)delegate {
+ static CouchbaseMobile* sCouchbase;
NSAssert(!sCouchbase, @"+startCouchbase has already been called");
sCouchbase = [[self alloc] init];
@@ -116,15 +116,15 @@ - (NSString*) localIniFilePath {
- (BOOL) installDefaultDatabase: (NSString*)databasePath {
NSString* dbDir = self.databaseDirectory;
return [self createDir: dbDir] &&
- [self installItemNamed: databasePath fromDir:nil toDir: dbDir replace: NO];
+ [self installItemNamed: databasePath fromDir:nil toDir: dbDir replace: NO];
}
#pragma mark STARTING COUCHDB:
- (BOOL)start
{
- if (_erlangThread)
+ if (_started)
return YES;
_timeStarted = CFAbsoluteTimeGetCurrent();
@@ -145,6 +145,7 @@ - (BOOL)start
toDir: _documentsDirectory])
return NO;
+ _started = YES;
[self performSelector: @selector(startupTimeout) withObject: nil afterDelay: kWaitTimeout];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(couchStarted:)
name:kInternalCouchStartedNotification object:nil];
@@ -224,14 +225,18 @@ - (void)notifyCouchStarted:(NSDictionary*)info {
self.error = error;
self.serverURL = serverURL; // Will trigger KVO notification
- [_delegate couchbaseDidStart:_serverURL];
+
+ if (_serverURL)
+ [_delegate couchbaseMobile:self didStart:_serverURL];
+ else
+ [_delegate couchbaseMobile:self failedToStart:_error];
}
- (void)startupTimeout {
NSLog(@"Couchbase: Error: No startup notification from server engine");
self.error = [NSError errorWithDomain:@"Couchbase" code:2 userInfo:nil]; //TODO: Real error
- [_delegate couchbaseDidStart:nil];
+ [_delegate couchbaseMobile:self failedToStart:_error];
}
View
20 Framework/Couchbase.xcodeproj/project.pbxproj
@@ -7,14 +7,14 @@
objects = {
/* Begin PBXBuildFile section */
- 27167C5C13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 27167C5E13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */; };
+ 27167C5C13C4DB53001CC5B6 /* CouchbaseMobile.h in Headers */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 27167C5E13C4DB53001CC5B6 /* CouchbaseMobile.m in Sources */ = {isa = PBXBuildFile; fileRef = 79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */; };
27167C6213C4DB53001CC5B6 /* libcrypto-iphonesimulator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E8394C1353ADF300D64D0D /* libcrypto-iphonesimulator.a */; };
27167C6313C4DB53001CC5B6 /* libssl-iphonesimulator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E8394D1353ADF300D64D0D /* libssl-iphonesimulator.a */; };
27167C6B13C4DFFF001CC5B6 /* libcrypto-iphoneos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E839481353ADE600D64D0D /* libcrypto-iphoneos.a */; };
27167C6C13C4E002001CC5B6 /* libssl-iphoneos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E839491353ADE600D64D0D /* libssl-iphoneos.a */; };
27167ECC13C4E644001CC5B6 /* libiErl14.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27167ECB13C4E644001CC5B6 /* libiErl14.a */; };
- 273A733613BD473D0078870D /* CouchbaseEmbeddedServer.h in Copy Header(s) */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */; };
+ 273A733613BD473D0078870D /* CouchbaseMobile.h in Copy Header(s) */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */; };
273A734213BD4DE90078870D /* default.ini in Copy into CouchbaseResources */ = {isa = PBXBuildFile; fileRef = 3D4791CB12A19F6A00581D10 /* default.ini */; };
278FE89713E74C7A009FEE49 /* libiMonkey.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27167ECD13C4E64B001CC5B6 /* libiMonkey.a */; };
27A74EAF13D4E64D00522F59 /* default_ios.ini in Copy into CouchbaseResources */ = {isa = PBXBuildFile; fileRef = 3D4791CC12A19F6A00581D10 /* default_ios.ini */; };
@@ -37,7 +37,7 @@
dstPath = Headers;
dstSubfolderSpec = 1;
files = (
- 273A733613BD473D0078870D /* CouchbaseEmbeddedServer.h in Copy Header(s) */,
+ 273A733613BD473D0078870D /* CouchbaseMobile.h in Copy Header(s) */,
);
name = "Copy Header(s)";
runOnlyForDeploymentPostprocessing = 0;
@@ -76,8 +76,8 @@
3D4791CB12A19F6A00581D10 /* default.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default.ini; sourceTree = "<group>"; };
3D4791CC12A19F6A00581D10 /* default_ios.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default_ios.ini; sourceTree = "<group>"; };
3DEAEA6612A2D70B00EEBD22 /* erlang */ = {isa = PBXFileReference; lastKnownFileType = folder; name = erlang; path = ../erlang; sourceTree = "<group>"; };
- 79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CouchbaseEmbeddedServer.h; sourceTree = "<group>"; };
- 79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CouchbaseEmbeddedServer.m; 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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -100,8 +100,8 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
- 79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */,
- 79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */,
+ 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */,
+ 79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -173,7 +173,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
- 27167C5C13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.h in Headers */,
+ 27167C5C13C4DB53001CC5B6 /* CouchbaseMobile.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -308,7 +308,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 27167C5E13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.m in Sources */,
+ 27167C5E13C4DB53001CC5B6 /* CouchbaseMobile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 README.md
@@ -78,7 +78,7 @@ _Important: The `rsync` command below is a single long line. Do not put a newlin
# and other resources needed at runtime. Copy it into the app bundle:
rsync -a "${SRCROOT}/Frameworks/Couchbase.framework/CouchbaseResources" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
-That’s it for the project setup. In your application code, you’ll need to start the CouchbaseEmbeddedServer object at launch time. (See CouchbaseEmbeddedServer.h, and see EmptyAppDelegate.m for an example of how to call it.)
+That’s it for the project setup. In your application code, you’ll need to start the CouchbaseMobile object at launch time. (See CouchbaseMobile.h, and see EmptyAppDelegate.m for an example of how to call it.)
## License

0 comments on commit 03dedb1

Please sign in to comment.
Something went wrong with that request. Please try again.