PageRenderTime 130ms CodeModel.GetById 121ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llprocesslauncher.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 90 lines | 38 code | 16 blank | 36 comment | 0 complexity | 9f61ecc170b1551b63d83d74b4b7e65c MD5 | raw file
 1/** 
 2 * @file llprocesslauncher.h
 3 * @brief Utility class for launching, terminating, and tracking the state of processes.
 4 *
 5 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26 
27#ifndef LL_LLPROCESSLAUNCHER_H
28#define LL_LLPROCESSLAUNCHER_H
29
30#if LL_WINDOWS
31#include <windows.h>
32#endif
33
34
35/*
36	LLProcessLauncher handles launching external processes with specified command line arguments.
37	It also keeps track of whether the process is still running, and can kill it if required.
38*/
39
40class LL_COMMON_API LLProcessLauncher
41{
42	LOG_CLASS(LLProcessLauncher);
43public:
44	LLProcessLauncher();
45	virtual ~LLProcessLauncher();
46	
47	void setExecutable(const std::string &executable);
48	void setWorkingDirectory(const std::string &dir);
49
50	const std::string& getExecutable() const;
51
52	void clearArguments();
53	void addArgument(const std::string &arg);
54	void addArgument(const char *arg);
55		
56	int launch(void);
57	bool isRunning(void);
58	
59	// Attempt to kill the process -- returns true if the process is no longer running when it returns.
60	// Note that even if this returns false, the process may exit some time after it's called.
61	bool kill(void);
62	
63	// Use this if you want the external process to continue execution after the LLProcessLauncher instance controlling it is deleted.
64	// Normally, the destructor will attempt to kill the process and wait for termination.
65	// This should only be used if the viewer is about to exit -- otherwise, the child process will become a zombie after it exits.
66	void orphan(void);	
67	
68	// This needs to be called periodically on Mac/Linux to clean up zombie processes.
69	static void reap(void);
70	
71	// Accessors for platform-specific process ID
72#if LL_WINDOWS
73	HANDLE getProcessHandle() { return mProcessHandle; };
74#else
75	pid_t getProcessID() { return mProcessID; };
76#endif	
77	
78private:
79	std::string mExecutable;
80	std::string mWorkingDir;
81	std::vector<std::string> mLaunchArguments;
82	
83#if LL_WINDOWS
84	HANDLE mProcessHandle;
85#else
86	pid_t mProcessID;
87#endif
88};
89
90#endif // LL_LLPROCESSLAUNCHER_H