Ignite Tools
Shared/Airship/Common/UAAnalytics.h
00001 /*
00002  Copyright 2009-2011 Urban Airship Inc. All rights reserved.
00003 
00004  Redistribution and use in source and binary forms, with or without
00005  modification, are permitted provided that the following conditions are met:
00006 
00007  1. Redistributions of source code must retain the above copyright notice, this
00008  list of conditions and the following disclaimer.
00009 
00010  2. Redistributions in binaryform must reproduce the above copyright notice,
00011  this list of conditions and the following disclaimer in the documentation
00012  and/or other materials provided withthe distribution.
00013 
00014  THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR
00015  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00016  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00017  EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00018  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00019  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00021  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00022  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00023  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 #import <Foundation/Foundation.h>
00026 #import "UAHTTPConnection.h"
00027 #import "UAAnalyticsDBManager.h"
00028 #import "UAEvent.h"
00029 
00030 // Used for init local size if server didn't response, or server sends bad data
00031 
00032 //total size in kilobytes that the event queue is allowed to grow to.
00033 #define X_UA_MAX_TOTAL 5*1024*1024      // local max of 5MB
00034 
00035 // total size in kilobytes that a given event post is allowed to send.
00036 #define X_UA_MAX_BATCH 500*1024         // local max of 500kb
00037 
00038 // maximum amount of time in seconds that events should queue for
00039 #define X_UA_MAX_WAIT 7*24*3600         // local max of 7 days
00040 
00041 // minimum amount of time in seconds that should elapse between event-server posts
00042 #define X_UA_MIN_BATCH_INTERVAL 60      // local min of 60s
00043 
00044 extern NSString * const UAAnalyticsOptionsRemoteNotificationKey;
00045 extern NSString * const UAAnalyticsOptionsServerKey;
00046 
00047 @interface UAAnalytics : NSObject<UAHTTPConnectionDelegate> {
00048     NSString *server;
00049     NSMutableDictionary *session;
00050 
00051     NSDictionary *notificationUserInfo;
00052 
00053     BOOL wasBackgrounded;
00054     UAHTTPConnection *connection;
00055 
00056     int x_ua_max_total;
00057     int x_ua_max_batch;
00058     int x_ua_max_wait;
00059     int x_ua_min_batch_interval;
00060         
00061         int sendInterval;
00062 
00063     int databaseSize;
00064     NSTimeInterval oldestEventTime;
00065     NSDate *lastSendTime;
00066     NSTimer *reSendTimer;
00067 }
00068 
00069 @property (retain) NSString *server;
00070 @property (retain, readonly) NSMutableDictionary *session;
00071 @property (assign, readonly) int databaseSize;
00072 @property (assign, readonly) int x_ua_max_total;
00073 @property (assign, readonly) int x_ua_max_batch;
00074 @property (assign, readonly) int x_ua_max_wait;
00075 @property (assign, readonly) int x_ua_min_batch_interval;
00076 @property (assign, nonatomic) int sendInterval;
00077 @property (assign, readonly) NSTimeInterval oldestEventTime;
00078 @property (retain, readonly) NSDate *lastSendTime;
00079 
00080 - (id)initWithOptions:(NSDictionary *)options;
00081 - (void)restoreFromDefault;
00082 - (void)saveDefault;
00083 
00084 - (void)addEvent:(UAEvent *)event;
00085 - (void)handleNotification:(NSDictionary *)userInfo;
00086 
00087 - (void)resetEventsDatabaseStatus;
00088 - (void)sendIfNeeded;
00089 
00090 @end
 All Classes Functions Variables Properties