//
//  AliyunCrashHandler.h
//
//  Created by 顾鹿 on 2026/2/11.
//  Copyright © 2026 aliyun.com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AliyunCrashKit/AliyunLogFileManager.h>
NS_ASSUME_NONNULL_BEGIN

#define DECLARE_OC_START_EXCEPTION_GUARD(classname) \
- (void)classname##_oc_start_exception_guard {}

#define DECLARE_OC_END_EXCEPTION_GUARD(classname) \
- (void)classname##_oc_end_exception_guard {}

#define DECLARE_C_START_EXCEPTION_GUARD(classname) \
void classname##_c_start_exception_guard() {}

#define DECLARE_C_END_EXCEPTION_GUARD(classname) \
void classname##_c_end_exception_guard() {} \
void classname##_c_register_exception_guard() { \
    [[AliyunCrashHandler sharedInstance] addFilterStartAddr:(NSUInteger)classname##_c_start_exception_guard withEndAddr:(NSUInteger)classname##_c_end_exception_guard]; \
}

#define DECLARE_REGISTER_OC_EXCEPTION_GUARD(classname) \
[[AliyunCrashHandler sharedInstance] addFilter:@""#classname""];

#define DECLARE_REGISTER_C_EXCEPTION_GUARD(classname) \
    classname##_c_register_exception_guard();

typedef void (^AliyunCrashBlock)(NSString *deviceInfo, NSString *crashContent);

@interface AliyunCrashHandler : NSObject

+ (instancetype)sharedInstance;

/// 设置 meta 信息（在 initWithBlock: 之前调用）
/// @param appVersion  宿主 App 版本号
/// @param sdkVersion  SDK 版本号
- (void)setMetaWithAppVersion:(NSString *)appVersion sdkVersion:(NSString *)sdkVersion;

- (void)initWithBlock:(AliyunCrashBlock) crashBlock;

- (void)addFilter:(NSString *) filterClassName;

- (void)addFilterStartAddr:(NSUInteger) startAddr withEndAddr:(NSUInteger) endAddr;

- (void)clearFilter;

- (void)restoreExceptionHandlers;

@end

NS_ASSUME_NONNULL_END
