hal/cocoa/smslib.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * smslib.h
michael@0 3 *
michael@0 4 * SMSLib Sudden Motion Sensor Access Library
michael@0 5 * Copyright (c) 2010 Suitable Systems
michael@0 6 * All rights reserved.
michael@0 7 *
michael@0 8 * Developed by: Daniel Griscom
michael@0 9 * Suitable Systems
michael@0 10 * http://www.suitable.com
michael@0 11 *
michael@0 12 * Permission is hereby granted, free of charge, to any person obtaining a
michael@0 13 * copy of this software and associated documentation files (the
michael@0 14 * "Software"), to deal with the Software without restriction, including
michael@0 15 * without limitation the rights to use, copy, modify, merge, publish,
michael@0 16 * distribute, sublicense, and/or sell copies of the Software, and to
michael@0 17 * permit persons to whom the Software is furnished to do so, subject to
michael@0 18 * the following conditions:
michael@0 19 *
michael@0 20 * - Redistributions of source code must retain the above copyright notice,
michael@0 21 * this list of conditions and the following disclaimers.
michael@0 22 *
michael@0 23 * - Redistributions in binary form must reproduce the above copyright
michael@0 24 * notice, this list of conditions and the following disclaimers in the
michael@0 25 * documentation and/or other materials provided with the distribution.
michael@0 26 *
michael@0 27 * - Neither the names of Suitable Systems nor the names of its
michael@0 28 * contributors may be used to endorse or promote products derived from
michael@0 29 * this Software without specific prior written permission.
michael@0 30 *
michael@0 31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
michael@0 32 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
michael@0 33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
michael@0 34 * IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
michael@0 35 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
michael@0 36 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
michael@0 37 * SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
michael@0 38 *
michael@0 39 * For more information about SMSLib, see
michael@0 40 * <http://www.suitable.com/tools/smslib.html>
michael@0 41 * or contact
michael@0 42 * Daniel Griscom
michael@0 43 * Suitable Systems
michael@0 44 * 1 Centre Street, Suite 204
michael@0 45 * Wakefield, MA 01880
michael@0 46 * (781) 665-0053
michael@0 47 *
michael@0 48 */
michael@0 49
michael@0 50 #import <Foundation/Foundation.h>
michael@0 51
michael@0 52 #define SMSLIB_VERSION "1.8"
michael@0 53
michael@0 54 #pragma mark Structure definitions
michael@0 55
michael@0 56 // Structure for specifying a 3-axis acceleration. 0.0 means "zero gravities",
michael@0 57 // 1.0 means "one gravity".
michael@0 58 typedef struct sms_acceleration {
michael@0 59 float x; // Right-left acceleration (positive is rightwards)
michael@0 60 float y; // Front-rear acceleration (positive is rearwards)
michael@0 61 float z; // Up-down acceleration (positive is upwards)
michael@0 62 } sms_acceleration;
michael@0 63
michael@0 64 // Structure for specifying a calibration.
michael@0 65 typedef struct sms_calibration {
michael@0 66 float zeros[3]; // Zero points for three axes (X, Y, Z)
michael@0 67 float onegs[3]; // One gravity values for three axes
michael@0 68 } sms_calibration;
michael@0 69
michael@0 70 #pragma mark Return value definitions
michael@0 71
michael@0 72 // These are the return values for accelStartup(), giving the
michael@0 73 // various stages where the most successful attempt at accessing
michael@0 74 // the accelerometer failed. The higher the value, the further along the
michael@0 75 // software progressed before failing. The options are:
michael@0 76 // - Didn't match model name
michael@0 77 #define SMS_FAIL_MODEL (-7)
michael@0 78 // - Failure getting dictionary matching desired services
michael@0 79 #define SMS_FAIL_DICTIONARY (-6)
michael@0 80 // - Failure getting list of services
michael@0 81 #define SMS_FAIL_LIST_SERVICES (-5)
michael@0 82 // - Failure if list of services is empty. The process generally fails
michael@0 83 // here if run on a machine without a Sudden Motion Sensor.
michael@0 84 #define SMS_FAIL_NO_SERVICES (-4)
michael@0 85 // - Failure if error opening device.
michael@0 86 #define SMS_FAIL_OPENING (-3)
michael@0 87 // - Failure if opened, but didn't get a connection
michael@0 88 #define SMS_FAIL_CONNECTION (-2)
michael@0 89 // - Failure if couldn't access connction using given function and size. This
michael@0 90 // is where the process would probably fail with a change in Apple's API.
michael@0 91 // Driver problems often also cause failures here.
michael@0 92 #define SMS_FAIL_ACCESS (-1)
michael@0 93 // - Success!
michael@0 94 #define SMS_SUCCESS (0)
michael@0 95
michael@0 96 #pragma mark Function declarations
michael@0 97
michael@0 98 // This starts up the accelerometer code, trying each possible sensor
michael@0 99 // specification. Note that for logging purposes it
michael@0 100 // takes an object and a selector; the object's selector is then invoked
michael@0 101 // with a single NSString as argument giving progress messages. Example
michael@0 102 // logging method:
michael@0 103 // - (void)logMessage: (NSString *)theString
michael@0 104 // which would be used in accelStartup's invocation thusly:
michael@0 105 // result = accelStartup(self, @selector(logMessage:));
michael@0 106 // If the object is nil, then no logging is done. Sets calibation from built-in
michael@0 107 // value table. Returns ACCEL_SUCCESS for success, and other (negative)
michael@0 108 // values for various failures (returns value indicating result of
michael@0 109 // most successful trial).
michael@0 110 int smsStartup(id logObject, SEL logSelector);
michael@0 111
michael@0 112 // This starts up the library in debug mode, ignoring the actual hardware.
michael@0 113 // Returned data is in the form of 1Hz sine waves, with the X, Y and Z
michael@0 114 // axes 120 degrees out of phase; "calibrated" data has range +/- (1.0/5);
michael@0 115 // "uncalibrated" data has range +/- (256/5). X and Y axes centered on 0.0,
michael@0 116 // Z axes centered on 1 (calibrated) or 256 (uncalibrated).
michael@0 117 // Don't use smsGetBufferLength or smsGetBufferData. Always returns SMS_SUCCESS.
michael@0 118 int smsDebugStartup(id logObject, SEL logSelector);
michael@0 119
michael@0 120 // Returns the current calibration values.
michael@0 121 void smsGetCalibration(sms_calibration *calibrationRecord);
michael@0 122
michael@0 123 // Sets the calibration, but does NOT store it as a preference. If the argument
michael@0 124 // is nil then the current calibration is set from the built-in value table.
michael@0 125 void smsSetCalibration(sms_calibration *calibrationRecord);
michael@0 126
michael@0 127 // Stores the current calibration values as a stored preference.
michael@0 128 void smsStoreCalibration(void);
michael@0 129
michael@0 130 // Loads the stored preference values into the current calibration.
michael@0 131 // Returns YES if successful.
michael@0 132 BOOL smsLoadCalibration(void);
michael@0 133
michael@0 134 // Deletes any stored calibration, and then takes the current calibration values
michael@0 135 // from the built-in value table.
michael@0 136 void smsDeleteCalibration(void);
michael@0 137
michael@0 138 // Fills in the accel record with calibrated acceleration data. Takes
michael@0 139 // 1-2ms to return a value. Returns 0 if success, error number if failure.
michael@0 140 int smsGetData(sms_acceleration *accel);
michael@0 141
michael@0 142 // Fills in the accel record with uncalibrated acceleration data.
michael@0 143 // Returns 0 if success, error number if failure.
michael@0 144 int smsGetUncalibratedData(sms_acceleration *accel);
michael@0 145
michael@0 146 // Returns the length of a raw block of data for the current type of sensor.
michael@0 147 int smsGetBufferLength(void);
michael@0 148
michael@0 149 // Takes a pointer to accelGetRawLength() bytes; sets those bytes
michael@0 150 // to return value from sensor. Make darn sure the buffer length is right!
michael@0 151 void smsGetBufferData(char *buffer);
michael@0 152
michael@0 153 // This returns an NSString describing the current calibration in
michael@0 154 // human-readable form. Also include a description of the machine.
michael@0 155 NSString *smsGetCalibrationDescription(void);
michael@0 156
michael@0 157 // Shuts down the accelerometer.
michael@0 158 void smsShutdown(void);
michael@0 159

mercurial