]> git.saurik.com Git - wxWidgets.git/blame - src/mac/corefoundation/utilsexc_cf.cpp
document On{Open,Save}Document()
[wxWidgets.git] / src / mac / corefoundation / utilsexc_cf.cpp
CommitLineData
5d553c56
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/corefoundation/utilsexec_cf.cpp
3// Purpose: Execution-related utilities for Darwin
62705a27 4// Author: David Elliott, Ryan Norton (wxMacExecute)
5d553c56
DE
5// Modified by: Stefan Csomor (added necessary wxT for unicode builds)
6// Created: 2004-11-04
7// RCS-ID: $Id$
62705a27 8// Copyright: (c) David Elliott, Ryan Norton
24498521 9// Licence: wxWindows licence
5d553c56
DE
10// Notes: This code comes from src/mac/carbon/utilsexc.cpp,1.11
11/////////////////////////////////////////////////////////////////////////////
12
13#include "wx/wxprec.h"
14#ifndef WX_PRECOMP
15 #include "wx/log.h"
16 #include "wx/utils.h"
17#endif //ndef WX_PRECOMP
18#include "wx/unix/execute.h"
fc480dc1 19#include "wx/stdpaths.h"
5a9d14c1 20#include "wx/app.h"
fc480dc1 21#include "wx/apptrait.h"
110ffa16
JS
22#include "wx/thread.h"
23#include "wx/process.h"
5d553c56 24
f523d7ce
VZ
25#include <sys/wait.h>
26
a3261ffb
DE
27#include <CoreFoundation/CFSocket.h>
28
29/*!
30 Called due to source signal detected by the CFRunLoop.
31 This is nearly identical to the wxGTK equivalent.
32 */
89954433
VZ
33extern "C" void WXCF_EndProcessDetector(CFSocketRef s,
34 CFSocketCallBackType WXUNUSED(callbackType),
35 CFDataRef WXUNUSED(address),
36 void const *WXUNUSED(data),
37 void *info)
a3261ffb 38{
a3261ffb 39 /*
b827d647 40 Either our pipe was closed or the process ended successfully. Either way,
a3261ffb
DE
41 we're done. It's not if waitpid is going to magically succeed when
42 we get fired again. CFSocketInvalidate closes the fd for us and also
43 invalidates the run loop source for us which should cause it to
44 release the CFSocket (thus causing it to be deallocated) and remove
45 itself from the runloop which should release it and cause it to also
46 be deallocated. Of course, it's possible the RunLoop hangs onto
47 one or both of them by retaining/releasing them within its stack
48 frame. However, that shouldn't be depended on. Assume that s is
49 deallocated due to the following call.
50 */
51 CFSocketInvalidate(s);
52
53 // Now tell wx that the process has ended.
b827d647 54 wxHandleProcessTermination(static_cast<wxEndProcessData *>(info));
a3261ffb
DE
55}
56
57/*!
1d043598 58 Implements the GUI-specific AddProcessCallback() for both wxMac and
a3261ffb
DE
59 wxCocoa using the CFSocket/CFRunLoop API which is available to both.
60 Takes advantage of the fact that sockets on UNIX are just regular
61 file descriptors and thus even a non-socket file descriptor can
62 apparently be used with CFSocket so long as you only tell CFSocket
63 to do things with it that would be valid for a non-socket fd.
64 */
1d043598 65int wxGUIAppTraits::AddProcessCallback(wxEndProcessData *proc_data, int fd)
a3261ffb
DE
66{
67 static int s_last_tag = 0;
68 CFSocketContext context =
69 { 0
70 , static_cast<void*>(proc_data)
71 , NULL
72 , NULL
73 , NULL
74 };
75 CFSocketRef cfSocket = CFSocketCreateWithNative(kCFAllocatorDefault,fd,kCFSocketReadCallBack,&WXCF_EndProcessDetector,&context);
76 if(cfSocket == NULL)
77 {
2263f62d 78 wxLogError(wxT("Failed to create socket for end process detection"));
a3261ffb
DE
79 return 0;
80 }
81 CFRunLoopSourceRef runLoopSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault, cfSocket, /*highest priority:*/0);
82 if(runLoopSource == NULL)
83 {
2263f62d 84 wxLogError(wxT("Failed to create CFRunLoopSource from CFSocket for end process detection"));
a3261ffb
DE
85 // closes the fd.. we can't really stop it, nor do we necessarily want to.
86 CFSocketInvalidate(cfSocket);
87 CFRelease(cfSocket);
88 return 0;
89 }
90 // Now that the run loop source has the socket retained and we no longer
91 // need to refer to it within this method, we can release it.
92 CFRelease(cfSocket);
93
94 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
95 // Now that the run loop has the source retained we can release it.
96 CFRelease(runLoopSource);
97
98 /*
99 Feed wx some bullshit.. we don't use it since CFSocket helpfully passes
100 itself into our callback and that's enough to be able to
101 CFSocketInvalidate it which is all we need to do to get everything we
102 just created to be deallocated.
103 */
104 return ++s_last_tag;
105}
106
107/////////////////////////////////////////////////////////////////////////////
108
9e34f56b 109// NOTE: This doesn't really belong here but this was a handy file to
fc480dc1 110// put it in because it's already compiled for wxCocoa and wxMac GUI lib.
531814a7 111#if wxUSE_STDPATHS
fc480dc1
DE
112static wxStandardPathsCF gs_stdPaths;
113wxStandardPathsBase& wxGUIAppTraits::GetStandardPaths()
114{
115 return gs_stdPaths;
116}
531814a7 117#endif
fc480dc1 118