incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject ios commit: Fixed EXC_BAD_ACCESS error in CDVAccelerometer
Date Wed, 16 May 2012 22:03:05 GMT
Updated Branches:
  refs/heads/464 221210d4d -> d1e633221


Fixed EXC_BAD_ACCESS error in CDVAccelerometer


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/d1e63322
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/d1e63322
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/d1e63322

Branch: refs/heads/464
Commit: d1e6332218aba39a11cad3dda24e7a66c4dfa079
Parents: 221210d
Author: Shazron Abdullah <shazron@apache.org>
Authored: Wed May 16 15:02:55 2012 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Wed May 16 15:02:55 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAccelerometer.h |    4 +--
 CordovaLib/Classes/CDVAccelerometer.m |   47 ++++++++++++++++------------
 2 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/d1e63322/CordovaLib/Classes/CDVAccelerometer.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAccelerometer.h b/CordovaLib/Classes/CDVAccelerometer.h
index dfb6a83..bc125f1 100755
--- a/CordovaLib/Classes/CDVAccelerometer.h
+++ b/CordovaLib/Classes/CDVAccelerometer.h
@@ -24,15 +24,13 @@
 
 @interface CDVAccelerometer : CDVPlugin<UIAccelerometerDelegate> 
 {
-	bool _bIsRunning;
 	double x;
     double y;
     double z;
     NSTimeInterval timestamp;
-    NSMutableArray  *accelCallbacks;
-    NSMutableDictionary  *watchCallbacks;
 }
 
+@property (readonly, assign) BOOL isRunning;
 @property (nonatomic, retain) NSMutableArray* accelCallbacks;
 @property (nonatomic, retain) NSMutableDictionary* watchCallbacks;
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/d1e63322/CordovaLib/Classes/CDVAccelerometer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAccelerometer.m b/CordovaLib/Classes/CDVAccelerometer.m
index 82e43bf..8f8d95b 100644
--- a/CordovaLib/Classes/CDVAccelerometer.m
+++ b/CordovaLib/Classes/CDVAccelerometer.m
@@ -20,9 +20,15 @@
 
 #import "CDVAccelerometer.h"
 
+@interface CDVAccelerometer () {
+}
+@property (readwrite, assign) BOOL isRunning;
+@end
+
+
 @implementation CDVAccelerometer
 
-@synthesize accelCallbacks, watchCallbacks;
+@synthesize accelCallbacks, watchCallbacks, isRunning;
 
 // defaults to 100 msec
 #define kAccelerometerInterval      100 
@@ -42,8 +48,9 @@
         y = 0;
         z = 0;
         timestamp = 0;
-        accelCallbacks = nil;
-        watchCallbacks = nil;
+        self.accelCallbacks = nil;
+        self.watchCallbacks = nil;
+        self.isRunning = NO;
     }
     return self;
 }
@@ -59,16 +66,16 @@
 	UIAccelerometer* pAccel = [UIAccelerometer sharedAccelerometer];
 	// accelerometer expects fractional seconds, but we have msecs
 	pAccel.updateInterval = desiredFrequency_num / 1000;
-    if (!accelCallbacks) {
-        accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
+    if (!self.accelCallbacks) {
+        self.accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
     }
     if (!watchCallbacks) {
-        watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
+        self.watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
     }
-	if(!_bIsRunning)
+	if(!self.isRunning)
 	{
 		pAccel.delegate = self;
-		_bIsRunning = YES;
+		self.isRunning = YES;
 	}
 }
 
@@ -76,7 +83,7 @@
 {
 	UIAccelerometer*  theAccelerometer = [UIAccelerometer sharedAccelerometer];
 	theAccelerometer.delegate = nil;
-	_bIsRunning = NO;
+	self.isRunning = NO;
 }
 
 /**
@@ -86,14 +93,14 @@
 {
 	NSString* callbackId = [arguments objectAtIndex:0];
     
-    if(!_bIsRunning)
+    if(!self.isRunning)
     {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
         [result setKeepCallback:[NSNumber numberWithBool:YES]];
-        if (!accelCallbacks) {
-            accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
+        if (!self.accelCallbacks) {
+            self.accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
         }
-        [accelCallbacks addObject:callbackId];
+        [self.accelCallbacks addObject:callbackId];
         [self start];
         [self writeJavascript:[result toSuccessCallbackString:callbackId]];
     } else {
@@ -106,14 +113,14 @@
     NSString* callbackId = [arguments objectAtIndex:0];
     NSString* timerId = [arguments objectAtIndex:1];
     
-    if (!watchCallbacks) {
-        watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
+    if (!self.watchCallbacks) {
+        self.watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
     }
     
     // add the callbackId into the dictionary so we can call back whenever get data
-    [watchCallbacks setObject:callbackId forKey:timerId];
+    [self.watchCallbacks setObject:callbackId forKey:timerId];
     
-    if (!_bIsRunning) {
+    if (!self.isRunning) {
         [self start];
     }
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
@@ -124,8 +131,8 @@
 {
     NSString* callbackId = [arguments objectAtIndex:0];
     NSString* timerId = [arguments objectAtIndex:1];
-    if (watchCallbacks && [watchCallbacks objectForKey:timerId]) {
-        [watchCallbacks removeObjectForKey:timerId];
+    if (self.watchCallbacks && [self.watchCallbacks objectForKey:timerId]) {
+        [self.watchCallbacks removeObjectForKey:timerId];
     }
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
     NSString* jsString = [result toSuccessCallbackString:callbackId];
@@ -137,7 +144,7 @@
  */
 - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

 {
-	if(_bIsRunning)
+	if(self.isRunning)
 	{
         x = acceleration.x;
         y = acceleration.y;


Mime
View raw message