/
AGProcess-GLProc.m
99 lines (81 loc) · 2.29 KB
/
AGProcess-GLProc.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
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// AGProcess_GLProc.m
// GameLauncher
//
// Created by Adam on 19/08/05.
// Copyright 2005 2Sublime.com. All rights reserved.
//
#import "AGProcess-GLProc.h"
@implementation AGProcess (GLProc)
- (BOOL)isRunning
{
if ([self state] != AGProcessStateExited) {
return YES;
}
return NO;
}
- (BOOL)moveToFrontProcess
{
CPSProcessSerNum CPSpsn = {
kNoProcess, kNoProcess
};
ProcessSerialNumber psn;
pid_t pid = process;
OSStatus err = GetProcessForPID(pid , &psn);
CPSpsn.lo = psn.highLongOfPSN;
CPSpsn.hi = psn.lowLongOfPSN;
err = CPSPostShowReq(&CPSpsn) || CPSSetFrontProcess(&CPSpsn);
if (err != noErr) {
NSLog(@"%@: Can't move process to front", command);
return NO;
}
return YES;
}
- (BOOL)quitGracefully
{
ProcessSerialNumber psn;
pid_t pid = process;
OSStatus err = GetProcessForPID(pid , &psn);
err = SendQuitAppleEventToApplication(psn);
if (err != noErr) {
NSLog(@"%@: AEQuit event failed", command);
return NO;
}
return YES;
}
- (BOOL)isEqual:(AGProcess *)proc
{
return (process == [proc processIdentifier]);
}
@end
/*****************************************************
* **** taken from Apple Killeveryonebutme sample code *****
*
* SendQuitAppleEventToApplication(ProcessToQuit)
*
* Purpose: called to send a 'quit' AppleEvent to the process passed as parameter
*
* Inputs: none
*
* Returns: OSStatus - error code (0 == no error)
*/
OSStatus SendQuitAppleEventToApplication(ProcessSerialNumber ProcessToQuit)
{
OSStatus status;
AEDesc targetProcess = {typeNull, NULL};
AppleEvent theEvent = {typeNull, NULL};
AppleEvent eventReply = {typeNull, NULL};
status = AECreateDesc(typeProcessSerialNumber, &ProcessToQuit, sizeof(ProcessToQuit), &targetProcess);
require_noerr(status, AECreateDesc);
status = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &targetProcess, kAutoGenerateReturnID, kAnyTransactionID, &theEvent);
require_noerr(status, AECreateAppleEvent);
status = AESend(&theEvent, &eventReply, kAENoReply + kAEAlwaysInteract, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
require_noerr(status, AESend);
AESend:
AECreateAppleEvent:
AECreateDesc:
AEDisposeDesc(&eventReply);
AEDisposeDesc(&theEvent);
AEDisposeDesc(&targetProcess);
return(status);
} // SendQuitAppleEventToApplication