![]() |
IOS Streaming Browser 1.0
An IOS streaming browser to stream the display to others or to a projector
|
00001 #import <Foundation/Foundation.h> 00002 #import "DDLog.h" 00003 00004 @class DDLogFileInfo; 00005 00006 00007 // Default configuration and safety/sanity values. 00008 // 00009 // maximumFileSize -> DEFAULT_LOG_MAX_FILE_SIZE 00010 // rollingFrequency -> DEFAULT_LOG_ROLLING_FREQUENCY 00011 // maximumNumberOfLogFiles -> DEFAULT_LOG_MAX_NUM_LOG_FILES 00012 // 00013 // You should carefully consider the proper configuration values for your application. 00014 00015 #define DEFAULT_LOG_MAX_FILE_SIZE (1024 * 1024) // 1 MB 00016 #define DEFAULT_LOG_ROLLING_FREQUENCY (60 * 60 * 24) // 24 Hours 00017 #define DEFAULT_LOG_MAX_NUM_LOG_FILES (5) // 5 Files 00018 00019 00020 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00021 #pragma mark - 00022 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00023 00024 // The LogFileManager protocol is designed to allow you to control all aspects of your log files. 00025 // 00026 // The primary purpose of this is to allow you to do something with the log files after they have been rolled. 00027 // Perhaps you want to compress them to save disk space. 00028 // Perhaps you want to upload them to an FTP server. 00029 // Perhaps you want to run some analytics on the file. 00030 // 00031 // A default LogFileManager is, of course, provided. 00032 // The default LogFileManager simply deletes old log files according to the maximumNumberOfLogFiles property. 00033 // 00034 // This protocol provides various methods to fetch the list of log files. 00035 // 00036 // There are two variants: sorted and unsorted. 00037 // If sorting is not necessary, the unsorted variant is obviously faster. 00038 // The sorted variant will return an array sorted by when the log files were created, 00039 // with the most recently created log file at index 0, and the oldest log file at the end of the array. 00040 // 00041 // You can fetch only the log file paths (full path including name), log file names (name only), 00042 // or an array of DDLogFileInfo objects. 00043 // The DDLogFileInfo class is documented below, and provides a handy wrapper that 00044 // gives you easy access to various file attributes such as the creation date or the file size. 00045 00046 @protocol DDLogFileManager <NSObject> 00047 @required 00048 00049 // Public properties 00050 00051 @property (readwrite, assign) NSUInteger maximumNumberOfLogFiles; 00052 00053 // Public methods 00054 00055 /** 00056 00057 **/ 00058 - (NSString *)logsDirectory; 00059 00060 /** 00061 00062 **/ 00063 - (NSArray *)unsortedLogFilePaths; 00064 00065 /** 00066 Gets unsorted array with the log file names 00067 returns NSArray 00068 **/ 00069 - (NSArray *)unsortedLogFileNames; 00070 00071 /** 00072 00073 returns NSArray 00074 **/ 00075 - (NSArray *)unsortedLogFileInfos; 00076 00077 /** 00078 returns NSArray 00079 **/ 00080 - (NSArray *)sortedLogFilePaths; 00081 00082 /** 00083 returns NSArray 00084 **/ 00085 - (NSArray *)sortedLogFileNames; 00086 00087 /** 00088 returns NSArray 00089 **/ 00090 - (NSArray *)sortedLogFileInfos; 00091 00092 // Private methods (only to be used by DDFileLogger) 00093 00094 /** 00095 returns NSString 00096 **/ 00097 - (NSString *)createNewLogFile; 00098 00099 @optional 00100 00101 ////////////////////////////////////// 00102 // Notifications from DDFileLogger 00103 ////////////////////////////////////// 00104 00105 /** 00106 param NSString 00107 **/ 00108 - (void)didArchiveLogFile:(NSString *)logFilePath; 00109 00110 /** 00111 param NSString 00112 **/ 00113 - (void)didRollAndArchiveLogFile:(NSString *)logFilePath; 00114 00115 @end 00116 00117 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00118 #pragma mark - 00119 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00120 00121 // Default log file manager. 00122 // 00123 // All log files are placed inside the logsDirectory. 00124 // On Mac, this is in ~/Library/Application Support/<Application Name>/Logs. 00125 // On iPhone, this is in ~/Documents/Logs. 00126 // 00127 // Log files are named "log-<uuid>.txt", 00128 // where uuid is a 6 character hexadecimal consisting of the set [0123456789ABCDEF]. 00129 // 00130 // Archived log files are automatically deleted according to the maximumNumberOfLogFiles property. 00131 00132 @interface DDLogFileManagerDefault : NSObject <DDLogFileManager> 00133 { 00134 /** 00135 The maximum number of log files 00136 **/ 00137 NSUInteger maximumNumberOfLogFiles; 00138 } 00139 00140 @end 00141 00142 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00143 #pragma mark - 00144 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00145 00146 // Most users will want file log messages to be prepended with the date and time. 00147 // Rather than forcing the majority of users to write their own formatter, 00148 // we will supply a logical default formatter. 00149 // Users can easily replace this formatter with their own by invoking the setLogFormatter method. 00150 // It can also be removed by calling setLogFormatter, and passing a nil parameter. 00151 // 00152 // In addition to the convenience of having a logical default formatter, 00153 // it will also provide a template that makes it easy for developers to copy and change. 00154 00155 @interface DDLogFileFormatterDefault : NSObject <DDLogFormatter> 00156 { 00157 /** 00158 00159 **/ 00160 NSDateFormatter *dateFormatter; 00161 } 00162 00163 @end 00164 00165 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00166 #pragma mark - 00167 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00168 00169 @interface DDFileLogger : DDAbstractLogger <DDLogger> 00170 { 00171 /** 00172 00173 **/ 00174 id <DDLogFileManager> logFileManager; 00175 00176 /** 00177 00178 **/ 00179 DDLogFileInfo *currentLogFileInfo; 00180 00181 /** 00182 The NSFileHandle class is an object-oriented wrapper for a file descriptor 00183 **/ 00184 NSFileHandle *currentLogFileHandle; 00185 00186 /** 00187 00188 **/ 00189 NSTimer *rollingTimer; 00190 00191 /** 00192 The maximum file size has to be between 0 and 9,223,372,036,854,775,807 00193 **/ 00194 unsigned long long maximumFileSize; 00195 00196 /** 00197 00198 **/ 00199 NSTimeInterval rollingFrequency; 00200 } 00201 00202 /** 00203 Initialize the DDFileLogger 00204 **/ 00205 - (id)init; 00206 00207 /** 00208 Initialize the DDFileLogger with a file manager 00209 **/ 00210 - (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager; 00211 00212 // Configuration 00213 // 00214 // maximumFileSize: 00215 // The approximate maximum size to allow log files to grow. 00216 // If a log file is larger than this value after a write, 00217 // then the log file is rolled. 00218 // 00219 // rollingFrequency 00220 // How often to roll the log file. 00221 // The frequency is given as an NSTimeInterval, which is a double that specifies the interval in seconds. 00222 // Once the log file gets to be this old, it is rolled. 00223 // 00224 // Both the maximumFileSize and the rollingFrequency are used to manage rolling. 00225 // Whichever occurs first will cause the log file to be rolled. 00226 // 00227 // For example: 00228 // The rollingFrequency is 24 hours, 00229 // but the log file surpasses the maximumFileSize after only 20 hours. 00230 // The log file will be rolled at that 20 hour mark. 00231 // A new log file will be created, and the 24 hour timer will be restarted. 00232 // 00233 // logFileManager 00234 // Allows you to retrieve the list of log files, 00235 // and configure the maximum number of archived log files to keep. 00236 00237 00238 // The maximum file size has to be between 0 and 9,223,372,036,854,775,807 00239 @property (readwrite, assign) unsigned long long maximumFileSize; 00240 00241 00242 @property (readwrite, assign) NSTimeInterval rollingFrequency; 00243 00244 @property (nonatomic, readonly) id <DDLogFileManager> logFileManager; 00245 00246 00247 /** 00248 You can optionally force the current log file to be rolled with this method. 00249 **/ 00250 - (void)rollLogFile; 00251 00252 // Inherited from DDAbstractLogger 00253 00254 // - (id <DDLogFormatter>)logFormatter; 00255 // - (void)setLogFormatter:(id <DDLogFormatter>)formatter; 00256 00257 @end 00258 00259 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00260 #pragma mark - 00261 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00262 00263 // DDLogFileInfo is a simple class that provides access to various file attributes. 00264 // It provides good performance as it only fetches the information if requested, 00265 // and it caches the information to prevent duplicate fetches. 00266 // 00267 // It was designed to provide quick snapshots of the current state of log files, 00268 // and to help sort log files in an array. 00269 // 00270 // This class does not monitor the files, or update it's cached attribute values if the file changes on disk. 00271 // This is not what the class was designed for. 00272 // 00273 // If you absolutely must get updated values, 00274 // you can invoke the reset method which will clear the cache. 00275 00276 @interface DDLogFileInfo : NSObject 00277 { 00278 /** 00279 The file path of the log file 00280 **/ 00281 NSString *filePath; 00282 00283 /** 00284 The log file name 00285 **/ 00286 NSString *fileName; 00287 00288 /** 00289 00290 **/ 00291 NSDictionary *fileAttributes; 00292 00293 /** 00294 The creation date 00295 **/ 00296 NSDate *creationDate; 00297 00298 /** 00299 The modification date 00300 **/ 00301 NSDate *modificationDate; 00302 00303 00304 // The filesize can be between 0 and 9,223,372,036,854,775,807 00305 unsigned long long fileSize; 00306 } 00307 00308 @property (nonatomic, readonly) NSString *filePath; // the file path 00309 @property (nonatomic, readonly) NSString *fileName; // the file name 00310 00311 @property (nonatomic, readonly) NSDictionary *fileAttributes; // the file attributes 00312 00313 @property (nonatomic, readonly) NSDate *creationDate; // the file creation date 00314 @property (nonatomic, readonly) NSDate *modificationDate; // the file modification date 00315 00316 @property (nonatomic, readonly) unsigned long long fileSize; // the size of the file 00317 00318 @property (nonatomic, readonly) NSTimeInterval age; 00319 00320 @property (nonatomic, readwrite) BOOL isArchived; // whether the file is archived 00321 00322 00323 /** 00324 Class method 00325 param NSString 00326 returns id 00327 **/ 00328 + (id)logFileWithPath:(NSString *)filePath; 00329 00330 00331 /** 00332 Initialize the DDLogFileInfo with a file path 00333 param NSString 00334 returns id 00335 **/ 00336 - (id)initWithFilePath:(NSString *)filePath; 00337 00338 /** 00339 00340 **/ 00341 - (void)reset; 00342 00343 /** 00344 param NSString 00345 **/ 00346 - (void)renameFile:(NSString *)newFileName; 00347 00348 #if TARGET_IPHONE_SIMULATOR 00349 00350 // So here's the situation. 00351 // Extended attributes are perfect for what we're trying to do here (marking files as archived). 00352 // This is exactly what extended attributes were designed for. 00353 // 00354 // But Apple screws us over on the simulator. 00355 // Everytime you build-and-go, they copy the application into a new folder on the hard drive, 00356 // and as part of the process they strip extended attributes from our log files. 00357 // Normally, a copy of a file preserves extended attributes. 00358 // So obviously Apple has gone to great lengths to piss us off. 00359 // 00360 // Thus we use a slightly different tactic for marking log files as archived in the simulator. 00361 // That way it "just works" and there's no confusion when testing. 00362 // 00363 // The difference in method names is indicative of the difference in functionality. 00364 // On the simulator we add an attribute by appending a filename extension. 00365 // 00366 // For example: 00367 // log-ABC123.txt -> log-ABC123.archived.txt 00368 00369 00370 /** 00371 param NSString 00372 returns BOOL 00373 **/ 00374 - (BOOL)hasExtensionAttributeWithName:(NSString *)attrName; 00375 00376 /** 00377 param NSString 00378 **/ 00379 - (void)addExtensionAttributeWithName:(NSString *)attrName; 00380 00381 /** 00382 param NSString 00383 **/ 00384 - (void)removeExtensionAttributeWithName:(NSString *)attrName; 00385 00386 #else 00387 00388 // Normal use of extended attributes used everywhere else, 00389 // such as on Macs and on iPhone devices. 00390 00391 /** 00392 param NSString 00393 returns BOOL 00394 **/ 00395 - (BOOL)hasExtendedAttributeWithName:(NSString *)attrName; 00396 00397 /** 00398 param NSString 00399 **/ 00400 - (void)addExtendedAttributeWithName:(NSString *)attrName; 00401 00402 /** 00403 param NSString 00404 **/ 00405 - (void)removeExtendedAttributeWithName:(NSString *)attrName; 00406 00407 #endif 00408 00409 /** 00410 param DDLogFileInfo 00411 returns NSComparisonResult 00412 **/ 00413 - (NSComparisonResult)reverseCompareByCreationDate:(DDLogFileInfo *)another; 00414 00415 /** 00416 param DDLogFileInfo 00417 returns NSComparisonResult 00418 **/ 00419 - (NSComparisonResult)reverseCompareByModificationDate:(DDLogFileInfo *)another; 00420 00421 @end