Skip to content

Commit

Permalink
Merge pull request kstenerud#274 from bamx23/improve-public-api
Browse files Browse the repository at this point in the history
Improve public api
  • Loading branch information
kstenerud authored Feb 27, 2018
2 parents 3da5b1d + fd3fe56 commit eb64c19
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 13 deletions.
4 changes: 2 additions & 2 deletions KSCrash.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Pod::Spec.new do |s|
recording.public_header_files = 'Source/KSCrash/Recording/KSCrash.h',
'Source/KSCrash/Recording/KSCrashC.h',
'Source/KSCrash/Recording/KSCrashReportWriter.h',
'Source/KSCrash/Recording/KSCrashReportFields.h',
'Source/KSCrash/Recording/Monitors/KSCrashMonitorType.h',
'Source/KSCrash/Reporting/Filters/KSCrashReportFilter.h',
'Source/KSCrash/Reporting/Filters/KSCrashReportFields.h'
'Source/KSCrash/Reporting/Filters/KSCrashReportFilter.h'

recording.subspec 'Tools' do |tools|
tools.source_files = 'Source/KSCrash/Recording/Tools/*.h'
Expand Down
20 changes: 20 additions & 0 deletions Source/KSCrash/Recording/KSCrash.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,30 @@ typedef enum
*/
- (void) sendAllReportsWithCompletion:(KSCrashReportFilterCompletion) onCompletion;

/** Get all unsent report IDs.
*
* @return An array with report IDs.
*/
- (NSArray*) reportIDs;

/** Get report.
*
* @param reportID An ID of report.
*
* @return A dictionary with report fields. See KSCrashReportFields.h for available fields.
*/
- (NSDictionary*) reportWithID:(NSNumber*) reportID;

/** Delete all unsent reports.
*/
- (void) deleteAllReports;

/** Delete report.
*
* @param reportID An ID of report to delete.
*/
- (void) deleteReportWithID:(NSNumber*) reportID;

/** Report a custom, user defined exception.
* This can be useful when dealing with scripting languages.
*
Expand Down
27 changes: 25 additions & 2 deletions Source/KSCrash/Recording/KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ - (void) deleteAllReports
kscrash_deleteAllReports();
}

- (void) deleteReportWithID:(NSNumber*) reportID
{
kscrash_deleteReportWithID([reportID longValue]);
}

- (void) reportUserException:(NSString*) name
reason:(NSString*) reason
language:(NSString*) language
Expand Down Expand Up @@ -470,7 +475,25 @@ - (void) doctorReport:(NSMutableDictionary*) report
}
}

- (NSDictionary*) reportWithID:(int64_t) reportID
- (NSArray*)reportIDs
{
int reportCount = kscrash_getReportCount();
int64_t reportIDsC[reportCount];
reportCount = kscrash_getReportIDs(reportIDsC, reportCount);
NSMutableArray* reportIDs = [NSMutableArray arrayWithCapacity:(NSUInteger)reportCount];
for(int i = 0; i < reportCount; i++)
{
[reportIDs addObject:@(reportIDsC[i])];
}
return reportIDs;
}

- (NSDictionary*) reportWithID:(NSNumber*) reportID
{
return [self reportWithIntID:[reportID longValue]];
}

- (NSDictionary*) reportWithIntID:(int64_t) reportID
{
NSData* jsonData = [self loadCrashReportJSONWithID:reportID];
if(jsonData == nil)
Expand Down Expand Up @@ -506,7 +529,7 @@ - (NSArray*) allReports
NSMutableArray* reports = [NSMutableArray arrayWithCapacity:(NSUInteger)reportCount];
for(int i = 0; i < reportCount; i++)
{
NSDictionary* report = [self reportWithID:reportIDs[i]];
NSDictionary* report = [self reportWithIntID:reportIDs[i]];
if(report != nil)
{
[reports addObject:report];
Expand Down
5 changes: 5 additions & 0 deletions Source/KSCrash/Recording/KSCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,8 @@ void kscrash_deleteAllReports()
{
kscrs_deleteAllReports();
}

void kscrash_deleteReportWithID(int64_t reportID)
{
kscrs_deleteReportWithID(reportID);
}
6 changes: 6 additions & 0 deletions Source/KSCrash/Recording/KSCrashC.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ int64_t kscrash_addUserReport(const char* report, int reportLength);
*/
void kscrash_deleteAllReports(void);

/** Delete report.
*
* @param reportID An ID of report to delete.
*/
void kscrash_deleteReportWithID(int64_t reportID);


#ifdef __cplusplus
}
Expand Down
16 changes: 8 additions & 8 deletions Source/KSCrash/Recording/KSCrashReportStore.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ static int64_t getReportIDFromFilename(const char* filename)
return reportID;
}

static void deleteReportWithID(int64_t id)
{
char path[KSCRS_MAX_PATH_LENGTH];
getCrashReportPathByID(id, path);
ksfu_removeFile(path, true);
}

static int getReportCount()
{
int count = 0;
Expand Down Expand Up @@ -155,7 +148,7 @@ static void pruneReports()

for(int i = 0; i < reportCount - g_maxReportCount; i++)
{
deleteReportWithID(reportIDs[i]);
kscrs_deleteReportWithID(reportIDs[i]);
}
}
}
Expand Down Expand Up @@ -265,6 +258,13 @@ void kscrs_deleteAllReports()
pthread_mutex_unlock(&g_mutex);
}

void kscrs_deleteReportWithID(int64_t reportID)
{
char path[KSCRS_MAX_PATH_LENGTH];
getCrashReportPathByID(reportID, path);
ksfu_removeFile(path, true);
}

void kscrs_setMaxReportCount(int maxReportCount)
{
g_maxReportCount = maxReportCount;
Expand Down
6 changes: 6 additions & 0 deletions Source/KSCrash/Recording/KSCrashReportStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ int64_t kscrs_addUserReport(const char* report, int reportLength);
*/
void kscrs_deleteAllReports(void);

/** Delete report.
*
* @param reportID An ID of report to delete.
*/
void kscrs_deleteReportWithID(int64_t reportID);

/** Set the maximum number of reports allowed on disk before old ones get deleted.
*
* @param maxReportCount The maximum number of reports.
Expand Down
4 changes: 4 additions & 0 deletions Source/KSCrash/Recording/Monitors/KSCrashMonitor_System.m
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ static bool isSimulatorBuild()
NSString* path = nil;
#if KSCRASH_HOST_IOS
// For iOS 6 compatibility
#ifdef __IPHONE_11_0
if (@available(iOS 7, *)) {
#else
if ([[UIDevice currentDevice].systemVersion compare:@"7" options:NSNumericSearch] != NSOrderedAscending) {
#endif
#endif
path = [NSBundle mainBundle].appStoreReceiptURL.path;
#if KSCRASH_HOST_IOS
Expand Down
2 changes: 1 addition & 1 deletion Source/KSCrash/Recording/Tools/KSThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool ksthread_getQueueName(const KSThread thread, char* const buffer, int bufLen
}

thread_identifier_info_t idInfo = (thread_identifier_info_t)info;
if(ksmem_isMemoryReadable(idInfo, sizeof(*idInfo)))
if(!ksmem_isMemoryReadable(idInfo, sizeof(*idInfo)))
{
KSLOG_DEBUG("Thread %p has an invalid thread identifier info %p", thread, idInfo);
return false;
Expand Down

0 comments on commit eb64c19

Please sign in to comment.