VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/threads/nsProcessMac.cpp@ 36233

最後變更 在這個檔案從36233是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.2 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Don Bragg <[email protected]>
25 * Samir Gehani <[email protected]>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41/*****************************************************************************
42 *
43 * nsProcess is used to execute new processes and specify if you want to
44 * wait (blocking) or continue (non-blocking).
45 *
46 *****************************************************************************
47 */
48
49#include "nsCOMPtr.h"
50#include "nsMemory.h"
51
52#include "nsProcess.h"
53
54#include "prtypes.h"
55#include "prio.h"
56#include "prenv.h"
57#include "nsCRT.h"
58#include "prthread.h"
59
60#include <stdlib.h>
61#include <Processes.h>
62
63#include "nsILocalFileMac.h"
64
65//-------------------------------------------------------------------//
66// nsIProcess implementation
67//-------------------------------------------------------------------//
68NS_IMPL_ISUPPORTS1(nsProcess, nsIProcess)
69
70//Constructor
71nsProcess::nsProcess()
72:mExitValue(-1),
73 mProcess(nsnull)
74{
75}
76
77NS_IMETHODIMP
78nsProcess::Init(nsIFile* executable)
79{
80 PRBool isFile;
81
82 //First make sure the file exists
83 nsresult rv = executable->IsFile(&isFile);
84 if (NS_FAILED(rv)) return rv;
85
86 if (!isFile)
87 return NS_ERROR_FAILURE;
88
89 mExecutable = executable;
90
91 return NS_OK;
92}
93
94
95NS_IMETHODIMP
96nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid)
97{
98 OSErr err = noErr;
99 LaunchParamBlockRec launchPB;
100 FSSpec resolvedSpec;
101 Boolean bDone = false;
102 ProcessInfoRec info;
103
104 nsCOMPtr<nsILocalFileMac> macExecutable = do_QueryInterface(mExecutable);
105 macExecutable->GetFSSpec(&resolvedSpec);
106
107 launchPB.launchAppSpec = &resolvedSpec;
108 launchPB.launchAppParameters = NULL;
109 launchPB.launchBlockID = extendedBlock;
110 launchPB.launchEPBLength = extendedBlockLen;
111 launchPB.launchFileFlags = NULL;
112 launchPB.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum;
113 if (!blocking)
114 launchPB.launchControlFlags += launchDontSwitch;
115
116 err = LaunchApplication(&launchPB);
117 if (err != noErr)
118 return NS_ERROR_FAILURE;
119
120 // NOTE: blocking mode assumes you are running on a thread
121 // other than the UI thread that has teh main event loop
122 if (blocking)
123 {
124 do
125 {
126 info.processInfoLength = sizeof(ProcessInfoRec);
127 info.processName = nil;
128 info.processAppSpec = nil;
129 err = GetProcessInformation(&launchPB.launchProcessSN, &info);
130
131 if (err == noErr)
132 {
133 // still running so sleep some more (200 msecs)
134 PR_Sleep(200);
135 }
136 else
137 {
138 // no longer in process manager's internal list: so assume done
139 bDone = true;
140 }
141 }
142 while (!bDone);
143 }
144
145 return NS_OK;
146}
147
148NS_IMETHODIMP nsProcess::InitWithPid(PRUint32 pid)
149{
150 return NS_ERROR_NOT_IMPLEMENTED;
151}
152
153NS_IMETHODIMP
154nsProcess::GetLocation(nsIFile** aLocation)
155{
156 return NS_ERROR_NOT_IMPLEMENTED;
157}
158
159NS_IMETHODIMP
160nsProcess::GetPid(PRUint32 *aPid)
161{
162 return NS_ERROR_NOT_IMPLEMENTED;
163}
164
165NS_IMETHODIMP
166nsProcess::GetProcessName(char** aProcessName)
167{
168 return NS_ERROR_NOT_IMPLEMENTED;
169}
170
171NS_IMETHODIMP
172nsProcess::GetProcessSignature(PRUint32 *aProcessSignature)
173{
174 return NS_ERROR_NOT_IMPLEMENTED;
175}
176
177NS_IMETHODIMP
178nsProcess::Kill()
179{
180 return NS_ERROR_NOT_IMPLEMENTED;
181}
182
183NS_IMETHODIMP
184nsProcess::GetExitValue(PRInt32 *aExitValue)
185{
186 return NS_ERROR_NOT_IMPLEMENTED;
187}
188
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette