Skip to content

Commit 98f4409

Browse files
committed
Add libflex
1 parent e616004 commit 98f4409

File tree

175 files changed

+6818
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+6818
-0
lines changed

FLEX/ActivityStreamAPI.h

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
//
2+
// Taken from https://github.com/llvm-mirror/lldb/blob/master/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
3+
// by Tanner Bennett on 03/03/2019 with minimal modifications.
4+
//
5+
6+
//===-- ActivityStreamAPI.h -------------------------------------*- C++ -*-===//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef ActivityStreamSPI_h
15+
#define ActivityStreamSPI_h
16+
17+
#include <Foundation/Foundation.h>
18+
19+
#include <sys/time.h>
20+
// #include <xpc/xpc.h>
21+
22+
/* By default, XPC objects are declared as Objective-C types when building with
23+
* an Objective-C compiler. This allows them to participate in ARC, in RR
24+
* management by the Blocks runtime and in leaks checking by the static
25+
* analyzer, and enables them to be added to Cocoa collections.
26+
*
27+
* See <os/object.h> for details.
28+
*/
29+
#if !TARGET_OS_MACCATALYST
30+
#if OS_OBJECT_USE_OBJC
31+
OS_OBJECT_DECL(xpc_object);
32+
#else
33+
typedef void * xpc_object_t;
34+
#endif
35+
#endif
36+
37+
#define OS_ACTIVITY_MAX_CALLSTACK 32
38+
39+
// Enums
40+
41+
typedef NS_ENUM(uint32_t, os_activity_stream_flag_t) {
42+
OS_ACTIVITY_STREAM_PROCESS_ONLY = 0x00000001,
43+
OS_ACTIVITY_STREAM_SKIP_DECODE = 0x00000002,
44+
OS_ACTIVITY_STREAM_PAYLOAD = 0x00000004,
45+
OS_ACTIVITY_STREAM_HISTORICAL = 0x00000008,
46+
OS_ACTIVITY_STREAM_CALLSTACK = 0x00000010,
47+
OS_ACTIVITY_STREAM_DEBUG = 0x00000020,
48+
OS_ACTIVITY_STREAM_BUFFERED = 0x00000040,
49+
OS_ACTIVITY_STREAM_NO_SENSITIVE = 0x00000080,
50+
OS_ACTIVITY_STREAM_INFO = 0x00000100,
51+
OS_ACTIVITY_STREAM_PROMISCUOUS = 0x00000200,
52+
OS_ACTIVITY_STREAM_PRECISE_TIMESTAMPS = 0x00000200
53+
};
54+
55+
typedef NS_ENUM(uint32_t, os_activity_stream_type_t) {
56+
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE = 0x0201,
57+
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION = 0x0202,
58+
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_USERACTION = 0x0203,
59+
60+
OS_ACTIVITY_STREAM_TYPE_TRACE_MESSAGE = 0x0300,
61+
62+
OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400,
63+
OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480,
64+
65+
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_BEGIN = 0x0601,
66+
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602,
67+
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603,
68+
69+
OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00,
70+
};
71+
72+
typedef NS_ENUM(uint32_t, os_activity_stream_event_t) {
73+
OS_ACTIVITY_STREAM_EVENT_STARTED = 1,
74+
OS_ACTIVITY_STREAM_EVENT_STOPPED = 2,
75+
OS_ACTIVITY_STREAM_EVENT_FAILED = 3,
76+
OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED = 4,
77+
OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED = 5,
78+
};
79+
80+
// Types
81+
82+
typedef uint64_t os_activity_id_t;
83+
typedef struct os_activity_stream_s *os_activity_stream_t;
84+
typedef struct os_activity_stream_entry_s *os_activity_stream_entry_t;
85+
86+
#define OS_ACTIVITY_STREAM_COMMON() \
87+
uint64_t trace_id; \
88+
uint64_t timestamp; \
89+
uint64_t thread; \
90+
const uint8_t *image_uuid; \
91+
const char *image_path; \
92+
struct timeval tv_gmt; \
93+
struct timezone tz; \
94+
uint32_t offset
95+
96+
typedef struct os_activity_stream_common_s {
97+
OS_ACTIVITY_STREAM_COMMON();
98+
} * os_activity_stream_common_t;
99+
100+
struct os_activity_create_s {
101+
OS_ACTIVITY_STREAM_COMMON();
102+
const char *name;
103+
os_activity_id_t creator_aid;
104+
uint64_t unique_pid;
105+
};
106+
107+
struct os_activity_transition_s {
108+
OS_ACTIVITY_STREAM_COMMON();
109+
os_activity_id_t transition_id;
110+
};
111+
112+
typedef struct os_log_message_s {
113+
OS_ACTIVITY_STREAM_COMMON();
114+
const char *format;
115+
const uint8_t *buffer;
116+
size_t buffer_sz;
117+
const uint8_t *privdata;
118+
size_t privdata_sz;
119+
const char *subsystem;
120+
const char *category;
121+
uint32_t oversize_id;
122+
uint8_t ttl;
123+
bool persisted;
124+
} * os_log_message_t;
125+
126+
typedef struct os_trace_message_v2_s {
127+
OS_ACTIVITY_STREAM_COMMON();
128+
const char *format;
129+
const void *buffer;
130+
size_t bufferLen;
131+
xpc_object_t __unsafe_unretained payload;
132+
} * os_trace_message_v2_t;
133+
134+
typedef struct os_activity_useraction_s {
135+
OS_ACTIVITY_STREAM_COMMON();
136+
const char *action;
137+
bool persisted;
138+
} * os_activity_useraction_t;
139+
140+
typedef struct os_signpost_s {
141+
OS_ACTIVITY_STREAM_COMMON();
142+
const char *format;
143+
const uint8_t *buffer;
144+
size_t buffer_sz;
145+
const uint8_t *privdata;
146+
size_t privdata_sz;
147+
const char *subsystem;
148+
const char *category;
149+
uint64_t duration_nsec;
150+
uint32_t callstack_depth;
151+
uint64_t callstack[OS_ACTIVITY_MAX_CALLSTACK];
152+
} * os_signpost_t;
153+
154+
typedef struct os_activity_statedump_s {
155+
OS_ACTIVITY_STREAM_COMMON();
156+
char *message;
157+
size_t message_size;
158+
char image_path_buffer[PATH_MAX];
159+
} * os_activity_statedump_t;
160+
161+
struct os_activity_stream_entry_s {
162+
os_activity_stream_type_t type;
163+
164+
// information about the process streaming the data
165+
pid_t pid;
166+
uint64_t proc_id;
167+
const uint8_t *proc_imageuuid;
168+
const char *proc_imagepath;
169+
170+
// the activity associated with this streamed event
171+
os_activity_id_t activity_id;
172+
os_activity_id_t parent_id;
173+
174+
union {
175+
struct os_activity_stream_common_s common;
176+
struct os_activity_create_s activity_create;
177+
struct os_activity_transition_s activity_transition;
178+
struct os_log_message_s log_message;
179+
struct os_trace_message_v2_s trace_message;
180+
struct os_activity_useraction_s useraction;
181+
struct os_signpost_s signpost;
182+
struct os_activity_statedump_s statedump;
183+
};
184+
};
185+
186+
// Blocks
187+
188+
typedef bool (^os_activity_stream_block_t)(os_activity_stream_entry_t entry,
189+
int error);
190+
191+
typedef void (^os_activity_stream_event_block_t)(
192+
os_activity_stream_t stream, os_activity_stream_event_t event);
193+
194+
// SPI entry point prototypes
195+
196+
typedef os_activity_stream_t (*os_activity_stream_for_pid_t)(
197+
pid_t pid, os_activity_stream_flag_t flags,
198+
os_activity_stream_block_t stream_block);
199+
200+
typedef void (*os_activity_stream_resume_t)(os_activity_stream_t stream);
201+
202+
typedef void (*os_activity_stream_cancel_t)(os_activity_stream_t stream);
203+
204+
typedef char *(*os_log_copy_formatted_message_t)(os_log_message_t log_message);
205+
206+
typedef void (*os_activity_stream_set_event_handler_t)(
207+
os_activity_stream_t stream, os_activity_stream_event_block_t block);
208+
209+
#endif /* ActivityStreamSPI_h */

FLEX/CALayer+FLEX.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// CALayer+FLEX.h
3+
// FLEX
4+
//
5+
// Created by Tanner on 2/28/20.
6+
// Copyright © 2020 FLEX Team. All rights reserved.
7+
//
8+
9+
#import <QuartzCore/QuartzCore.h>
10+
11+
@interface CALayer (FLEX)
12+
13+
@property (nonatomic) BOOL flex_continuousCorners;
14+
15+
@end

FLEX/FHSRangeSlider.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// FHSRangeSlider.h
3+
// FLEX
4+
//
5+
// Created by Tanner Bennett on 1/7/20.
6+
// Copyright © 2020 FLEX Team. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface FHSRangeSlider : UIControl
14+
15+
@property (nonatomic) CGFloat allowedMinValue;
16+
@property (nonatomic) CGFloat allowedMaxValue;
17+
@property (nonatomic) CGFloat minValue;
18+
@property (nonatomic) CGFloat maxValue;
19+
20+
@end
21+
22+
NS_ASSUME_NONNULL_END

FLEX/FHSSnapshotNodes.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// FHSSnapshotNodes.h
3+
// FLEX
4+
//
5+
// Created by Tanner Bennett on 1/7/20.
6+
//
7+
8+
#import "FHSViewSnapshot.h"
9+
#import <SceneKit/SceneKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
/// Container that holds references to the SceneKit nodes associated with a snapshot.
14+
@interface FHSSnapshotNodes : NSObject
15+
16+
+ (instancetype)snapshot:(FHSViewSnapshot *)snapshot depth:(NSInteger)depth;
17+
18+
@property (nonatomic, readonly) FHSViewSnapshot *snapshotItem;
19+
@property (nonatomic, readonly) NSInteger depth;
20+
21+
/// The view image itself
22+
@property (nonatomic, nullable) SCNNode *snapshot;
23+
/// Goes on top of the snapshot, has rounded top corners
24+
@property (nonatomic, nullable) SCNNode *header;
25+
/// The bounding box drawn around the snapshot
26+
@property (nonatomic, nullable) SCNNode *border;
27+
28+
/// Used to indicate when a view is selected
29+
@property (nonatomic, getter=isHighlighted) BOOL highlighted;
30+
/// Used to indicate when a view is de-emphasized
31+
@property (nonatomic, getter=isDimmed) BOOL dimmed;
32+
33+
@property (nonatomic) BOOL forceHideHeader;
34+
35+
@end
36+
37+
NS_ASSUME_NONNULL_END

FLEX/FHSSnapshotView.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// FHSSnapshotView.h
3+
// FLEX
4+
//
5+
// Created by Tanner Bennett on 1/7/20.
6+
// Copyright © 2020 FLEX Team. All rights reserved.
7+
//
8+
9+
#import "FHSViewSnapshot.h"
10+
#import "FHSRangeSlider.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@protocol FHSSnapshotViewDelegate <NSObject>
15+
16+
- (void)didSelectView:(FHSViewSnapshot *)snapshot;
17+
- (void)didDeselectView:(FHSViewSnapshot *)snapshot;
18+
- (void)didLongPressView:(FHSViewSnapshot *)snapshot;
19+
20+
@end
21+
22+
@interface FHSSnapshotView : UIView
23+
24+
+ (instancetype)delegate:(id<FHSSnapshotViewDelegate>)delegate;
25+
26+
@property (nonatomic, weak) id<FHSSnapshotViewDelegate> delegate;
27+
28+
@property (nonatomic) NSArray<FHSViewSnapshot *> *snapshots;
29+
@property (nonatomic, nullable) FHSViewSnapshot *selectedView;
30+
31+
/// Views of these classes will have their headers hidden
32+
@property (nonatomic) NSArray<Class> *headerExclusions;
33+
34+
@property (nonatomic, readonly) UISlider *spacingSlider;
35+
@property (nonatomic, readonly) FHSRangeSlider *depthSlider;
36+
37+
- (void)emphasizeViews:(NSArray<UIView *> *)emphasizedViews;
38+
39+
- (void)toggleShowHeaders;
40+
- (void)toggleShowBorders;
41+
42+
- (void)hideView:(FHSViewSnapshot *)view;
43+
44+
@end
45+
46+
NS_ASSUME_NONNULL_END

FLEX/FHSView.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// FHSView.h
3+
// FLEX
4+
//
5+
// Created by Tanner Bennett on 1/6/20.
6+
//
7+
8+
#import <UIKit/UIKit.h>
9+
10+
@interface FHSView : NSObject {
11+
@private
12+
BOOL _inScrollView;
13+
}
14+
15+
+ (instancetype)forView:(UIView *)view isInScrollView:(BOOL)inScrollView;
16+
17+
/// Intentionally not weak
18+
@property (nonatomic, readonly) UIView *view;
19+
@property (nonatomic, readonly) NSString *identifier;
20+
21+
@property (nonatomic, readonly) NSString *title;
22+
/// Whether or not this view item should be visually distinguished
23+
@property (nonatomic, readwrite) BOOL important;
24+
25+
@property (nonatomic, readonly) CGRect frame;
26+
@property (nonatomic, readonly) BOOL hidden;
27+
@property (nonatomic, readonly) UIImage *snapshotImage;
28+
29+
@property (nonatomic, readonly) NSArray<FHSView *> *children;
30+
@property (nonatomic, readonly) NSString *summary;
31+
32+
/// @return importantAttr if .important, otherwise normalAttr
33+
//- (id)ifImportant:(id)importantAttr ifNormal:(id)normalAttr;
34+
35+
@end

FLEX/FHSViewController.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// FHSViewController.h
3+
// FLEX
4+
//
5+
// Created by Tanner Bennett on 1/6/20.
6+
// Copyright © 2020 FLEX Team. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
/// The view controller
14+
/// "FHS" stands for "FLEX (view) hierarchy snapshot"
15+
@interface FHSViewController : UIViewController
16+
17+
/// Use this when you want to snapshot a set of windows.
18+
+ (instancetype)snapshotWindows:(NSArray<UIWindow *> *)windows;
19+
/// Use this when you want to snapshot a specific slice of the view hierarchy.
20+
+ (instancetype)snapshotView:(UIView *)view;
21+
/// Use this when you want to emphasize specific views on the screen.
22+
/// These views must all be in the same window as the selected view.
23+
+ (instancetype)snapshotViewsAtTap:(NSArray<UIView *> *)viewsAtTap selectedView:(UIView *)view;
24+
25+
@property (nonatomic, nullable) UIView *selectedView;
26+
27+
@end
28+
29+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)