forked from Code-Hex/vz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualization_vnc.m
85 lines (70 loc) · 2.66 KB
/
virtualization_vnc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "virtualization_vnc.h"
#import "virtualization_helper.h"
#import <Foundation/Foundation.h>
#import <Virtualization/Virtualization.h>
@interface _VZVNCSecurityConfiguration : NSObject <NSCopying>
@end
@interface _VZVNCNoSecuritySecurityConfiguration : _VZVNCSecurityConfiguration
@end
@interface _VZVNCAuthenticationSecurityConfiguration : _VZVNCSecurityConfiguration
@property (readonly, copy) NSString *password;
- (instancetype)initWithPassword : (NSString *)password;
@end
@protocol _VZFramebufferObserver <NSObject>
@end
@protocol _VZVNCServerDelegate;
@interface _VZVNCServer : NSObject <_VZFramebufferObserver>
@property long long state;
@property (weak) id<_VZVNCServerDelegate> delegate;
@property (readonly) dispatch_queue_t queue;
@property (readonly) short port;
@property (readonly, copy) _VZVNCSecurityConfiguration *securityConfiguration;
@property (retain) VZVirtualMachine *virtualMachine;
- (instancetype)initWithPort:(NSInteger)port
queue:(dispatch_queue_t)queue
securityConfiguration:(_VZVNCSecurityConfiguration *)securityConfiguration;
- (void)start;
- (void)stop;
@end
void *newVZVNCServer(int port, void *vmQueue, const char *password)
{
if (@available(macOS 12, *)) {
_VZVNCSecurityConfiguration *securityConfiguration;
if (password != NULL) {
NSString *passwordNSString = [NSString stringWithUTF8String:password]; // not owned
securityConfiguration = [[_VZVNCAuthenticationSecurityConfiguration alloc] initWithPassword:passwordNSString];
} else {
securityConfiguration = [[_VZVNCNoSecuritySecurityConfiguration alloc] init];
}
_VZVNCServer *server = [[_VZVNCServer alloc] initWithPort:(NSInteger)port queue:vmQueue securityConfiguration:securityConfiguration];
[securityConfiguration release]; // the constructor retained or made a copy
return server;
}
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
void setVirtualMachineVZVNCServer(void *server, void *vm)
{
if (@available(macOS 12, *)) {
_VZVNCServer *serverObj = (_VZVNCServer *)server;
VZVirtualMachine *vmObj = (VZVirtualMachine *)vm;
serverObj.virtualMachine = vmObj;
return;
}
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
void startVZVNCServer(void *server)
{
if (@available(macOS 12, *)) {
_VZVNCServer *serverObj = (_VZVNCServer *)server;
return [serverObj start];
}
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
void stopVZVNCServer(void *server)
{
if (@available(macOS 12, *)) {
_VZVNCServer *serverObj = (_VZVNCServer *)server;
return [serverObj stop];
}
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}