Skip to content

Commit

Permalink
Renamed CouchbaseEmbeddedServer->CouchbaseMobile
Browse files Browse the repository at this point in the history
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
snej committed Aug 23, 2011
1 parent 804e08e commit 03dedb1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion EmptyApp/Source/EmptyAppDelegate.h
Expand Up @@ -7,7 +7,7 @@
// //


#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Couchbase/CouchbaseEmbeddedServer.h> #import <Couchbase/CouchbaseMobile.h>


@interface EmptyAppDelegate : UIResponder <UIApplicationDelegate, CouchbaseDelegate> @interface EmptyAppDelegate : UIResponder <UIApplicationDelegate, CouchbaseDelegate>


Expand Down
12 changes: 8 additions & 4 deletions EmptyApp/Source/EmptyAppDelegate.m
Expand Up @@ -13,7 +13,7 @@ @implementation EmptyAppDelegate




BOOL sUnitTesting; BOOL sUnitTesting;
CouchbaseEmbeddedServer* sCouchbase; // Used by the unit tests CouchbaseMobile* sCouchbase; // Used by the unit tests




@synthesize window = _window; @synthesize window = _window;
Expand All @@ -28,7 +28,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];


// Initialize CouchDB: // Initialize CouchDB:
CouchbaseEmbeddedServer* cb = [[CouchbaseEmbeddedServer alloc] init]; CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
cb.delegate = self; cb.delegate = self;
NSAssert([cb start], @"Couchbase couldn't start! Error = %@", cb.error); NSAssert([cb start], @"Couchbase couldn't start! Error = %@", cb.error);
sCouchbase = cb; sCouchbase = cb;
Expand Down Expand Up @@ -85,8 +85,7 @@ - (void)send: (NSString*)method toPath: (NSString*)relativePath body: (NSString*
} }




- (void)couchbaseDidStart:(NSURL *)serverURL { -(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
NSAssert(serverURL != nil, @"Couchbase failed to initialize");
NSLog(@"CouchDB is Ready, go!"); NSLog(@"CouchDB is Ready, go!");
self.serverURL = serverURL; self.serverURL = serverURL;


Expand All @@ -102,4 +101,9 @@ - (void)couchbaseDidStart:(NSURL *)serverURL {
} }




-(void)couchbaseMobile:(CouchbaseMobile*)couchbase failedToStart:(NSError*)error {
NSAssert(NO, @"Couchbase failed to initialize: %@", error);
}


@end @end
4 changes: 2 additions & 2 deletions EmptyApp/Tests/EmptyAppTests.m
Expand Up @@ -7,10 +7,10 @@
// //


#import "EmptyAppTests.h" #import "EmptyAppTests.h"
#import <Couchbase/CouchbaseEmbeddedServer.h> #import <Couchbase/CouchbaseMobile.h>


extern BOOL sUnitTesting; extern BOOL sUnitTesting;
extern CouchbaseEmbeddedServer* sCouchbase; // Defined in EmptyAppDelegate.m extern CouchbaseMobile* sCouchbase; // Defined in EmptyAppDelegate.m


@implementation EmptyAppTests @implementation EmptyAppTests


Expand Down
@@ -1,5 +1,5 @@
// //
// Couchbase.h // CouchbaseMobile.h
// Couchbase Mobile // Couchbase Mobile
// //
// Created by J Chris Anderson on 3/2/11. // Created by J Chris Anderson on 3/2/11.
Expand All @@ -19,15 +19,25 @@




#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class CouchbaseMobile;



@protocol CouchbaseDelegate @protocol CouchbaseDelegate
@required @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 @end




/** Manages an embedded instance of CouchDB that runs in a background thread. */ /** Manages an embedded instance of CouchDB that runs in a background thread. */
@interface CouchbaseEmbeddedServer : NSObject @interface CouchbaseMobile : NSObject
{ {
id<CouchbaseDelegate> _delegate; id<CouchbaseDelegate> _delegate;
CFAbsoluteTime _timeStarted; CFAbsoluteTime _timeStarted;
Expand All @@ -36,11 +46,11 @@
NSString* _iniFilePath; NSString* _iniFilePath;
NSURL* _serverURL; NSURL* _serverURL;
NSError* _error; NSError* _error;
pthread_t _erlangThread; BOOL _started;
} }


/** Convenience to instantiate and start a new instance. */ /** Convenience to instantiate and start a new instance. */
+ (CouchbaseEmbeddedServer*) startCouchbase: (id<CouchbaseDelegate>)delegate; + (CouchbaseMobile*) startCouchbase: (id<CouchbaseDelegate>)delegate;


/** Initializes the instance. */ /** Initializes the instance. */
- (id) init; - (id) init;
Expand Down
@@ -1,5 +1,5 @@
// //
// Couchbase.m // CouchbaseMobile.m
// Couchbase Mobile // Couchbase Mobile
// //
// Created by J Chris Anderson on 3/2/11. // Created by J Chris Anderson on 3/2/11.
Expand All @@ -17,7 +17,7 @@
// License for the specific language governing permissions and limitations under // License for the specific language governing permissions and limitations under
// the License. // the License.


#import "CouchbaseEmbeddedServer.h" #import "CouchbaseMobile.h"


#include <pthread.h> #include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
Expand All @@ -33,7 +33,7 @@
static const NSTimeInterval kWaitTimeout = 10.0; // How long to wait for CouchDB to start 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) NSURL* serverURL;
@property (readwrite, retain) NSError* error; @property (readwrite, retain) NSError* error;
- (BOOL)createDir:(NSString*)dirName; - (BOOL)createDir:(NSString*)dirName;
Expand All @@ -49,11 +49,11 @@ - (BOOL)deleteFile:(NSString*)filename fromDir: (NSString*)fromDir;
@end @end




@implementation CouchbaseEmbeddedServer @implementation CouchbaseMobile




+ (CouchbaseEmbeddedServer*) startCouchbase: (id<CouchbaseDelegate>)delegate { + (CouchbaseMobile*) startCouchbase: (id<CouchbaseDelegate>)delegate {
static CouchbaseEmbeddedServer* sCouchbase; static CouchbaseMobile* sCouchbase;
NSAssert(!sCouchbase, @"+startCouchbase has already been called"); NSAssert(!sCouchbase, @"+startCouchbase has already been called");


sCouchbase = [[self alloc] init]; sCouchbase = [[self alloc] init];
Expand Down Expand Up @@ -116,15 +116,15 @@ - (NSString*) localIniFilePath {
- (BOOL) installDefaultDatabase: (NSString*)databasePath { - (BOOL) installDefaultDatabase: (NSString*)databasePath {
NSString* dbDir = self.databaseDirectory; NSString* dbDir = self.databaseDirectory;
return [self createDir: dbDir] && 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: #pragma mark STARTING COUCHDB:


- (BOOL)start - (BOOL)start
{ {
if (_erlangThread) if (_started)
return YES; return YES;


_timeStarted = CFAbsoluteTimeGetCurrent(); _timeStarted = CFAbsoluteTimeGetCurrent();
Expand All @@ -145,6 +145,7 @@ - (BOOL)start
toDir: _documentsDirectory]) toDir: _documentsDirectory])
return NO; return NO;


_started = YES;
[self performSelector: @selector(startupTimeout) withObject: nil afterDelay: kWaitTimeout]; [self performSelector: @selector(startupTimeout) withObject: nil afterDelay: kWaitTimeout];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(couchStarted:) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(couchStarted:)
name:kInternalCouchStartedNotification object:nil]; name:kInternalCouchStartedNotification object:nil];
Expand Down Expand Up @@ -224,14 +225,18 @@ - (void)notifyCouchStarted:(NSDictionary*)info {


self.error = error; self.error = error;
self.serverURL = serverURL; // Will trigger KVO notification 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 { - (void)startupTimeout {
NSLog(@"Couchbase: Error: No startup notification from server engine"); NSLog(@"Couchbase: Error: No startup notification from server engine");
self.error = [NSError errorWithDomain:@"Couchbase" code:2 userInfo:nil]; //TODO: Real error self.error = [NSError errorWithDomain:@"Couchbase" code:2 userInfo:nil]; //TODO: Real error
[_delegate couchbaseDidStart:nil]; [_delegate couchbaseMobile:self failedToStart:_error];
} }




Expand Down
20 changes: 10 additions & 10 deletions Framework/Couchbase.xcodeproj/project.pbxproj
Expand Up @@ -7,14 +7,14 @@
objects = { objects = {


/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
27167C5C13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 27167C5C13C4DB53001CC5B6 /* CouchbaseMobile.h in Headers */ = {isa = PBXBuildFile; fileRef = 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */; settings = {ATTRIBUTES = (Public, ); }; };
27167C5E13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */; }; 27167C5E13C4DB53001CC5B6 /* CouchbaseMobile.m in Sources */ = {isa = PBXBuildFile; fileRef = 79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */; };
27167C6213C4DB53001CC5B6 /* libcrypto-iphonesimulator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E8394C1353ADF300D64D0D /* libcrypto-iphonesimulator.a */; }; 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 */; }; 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 */; }; 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 */; }; 27167C6C13C4E002001CC5B6 /* libssl-iphoneos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E839491353ADE600D64D0D /* libssl-iphoneos.a */; };
27167ECC13C4E644001CC5B6 /* libiErl14.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27167ECB13C4E644001CC5B6 /* libiErl14.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 */; }; 273A734213BD4DE90078870D /* default.ini in Copy into CouchbaseResources */ = {isa = PBXBuildFile; fileRef = 3D4791CB12A19F6A00581D10 /* default.ini */; };
278FE89713E74C7A009FEE49 /* libiMonkey.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27167ECD13C4E64B001CC5B6 /* libiMonkey.a */; }; 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 */; }; 27A74EAF13D4E64D00522F59 /* default_ios.ini in Copy into CouchbaseResources */ = {isa = PBXBuildFile; fileRef = 3D4791CC12A19F6A00581D10 /* default_ios.ini */; };
Expand All @@ -37,7 +37,7 @@
dstPath = Headers; dstPath = Headers;
dstSubfolderSpec = 1; dstSubfolderSpec = 1;
files = ( files = (
273A733613BD473D0078870D /* CouchbaseEmbeddedServer.h in Copy Header(s) */, 273A733613BD473D0078870D /* CouchbaseMobile.h in Copy Header(s) */,
); );
name = "Copy Header(s)"; name = "Copy Header(s)";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -76,8 +76,8 @@
3D4791CB12A19F6A00581D10 /* default.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default.ini; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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>"; }; 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CouchbaseMobile.h; sourceTree = "<group>"; };
79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CouchbaseEmbeddedServer.m; sourceTree = "<group>"; }; 79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CouchbaseMobile.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */


/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
Expand All @@ -100,8 +100,8 @@
080E96DDFE201D6D7F000001 /* Classes */ = { 080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
79C3C6F4131F011A00C8B96D /* CouchbaseEmbeddedServer.h */, 79C3C6F4131F011A00C8B96D /* CouchbaseMobile.h */,
79C3C6F5131F011A00C8B96D /* CouchbaseEmbeddedServer.m */, 79C3C6F5131F011A00C8B96D /* CouchbaseMobile.m */,
); );
path = Classes; path = Classes;
sourceTree = "<group>"; sourceTree = "<group>";
Expand Down Expand Up @@ -173,7 +173,7 @@
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
27167C5C13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.h in Headers */, 27167C5C13C4DB53001CC5B6 /* CouchbaseMobile.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -308,7 +308,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
27167C5E13C4DB53001CC5B6 /* CouchbaseEmbeddedServer.m in Sources */, 27167C5E13C4DB53001CC5B6 /* CouchbaseMobile.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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: # 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}" 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 ## License
Expand Down

0 comments on commit 03dedb1

Please sign in to comment.