xref: /onnv-gate/usr/src/cmd/lms/tools/ATVersion.h (revision 9203:3ebffd0a1b10)
1*9203SMark.Logan@Sun.COM /*******************************************************************************
2*9203SMark.Logan@Sun.COM  * Copyright (C) 2004-2008 Intel Corp. All rights reserved.
3*9203SMark.Logan@Sun.COM  *
4*9203SMark.Logan@Sun.COM  * Redistribution and use in source and binary forms, with or without
5*9203SMark.Logan@Sun.COM  * modification, are permitted provided that the following conditions are met:
6*9203SMark.Logan@Sun.COM  *
7*9203SMark.Logan@Sun.COM  *  - Redistributions of source code must retain the above copyright notice,
8*9203SMark.Logan@Sun.COM  *    this list of conditions and the following disclaimer.
9*9203SMark.Logan@Sun.COM  *
10*9203SMark.Logan@Sun.COM  *  - Redistributions in binary form must reproduce the above copyright notice,
11*9203SMark.Logan@Sun.COM  *    this list of conditions and the following disclaimer in the documentation
12*9203SMark.Logan@Sun.COM  *    and/or other materials provided with the distribution.
13*9203SMark.Logan@Sun.COM  *
14*9203SMark.Logan@Sun.COM  *  - Neither the name of Intel Corp. nor the names of its
15*9203SMark.Logan@Sun.COM  *    contributors may be used to endorse or promote products derived from this
16*9203SMark.Logan@Sun.COM  *    software without specific prior written permission.
17*9203SMark.Logan@Sun.COM  *
18*9203SMark.Logan@Sun.COM  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19*9203SMark.Logan@Sun.COM  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*9203SMark.Logan@Sun.COM  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*9203SMark.Logan@Sun.COM  * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
22*9203SMark.Logan@Sun.COM  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*9203SMark.Logan@Sun.COM  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*9203SMark.Logan@Sun.COM  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*9203SMark.Logan@Sun.COM  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*9203SMark.Logan@Sun.COM  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*9203SMark.Logan@Sun.COM  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*9203SMark.Logan@Sun.COM  * POSSIBILITY OF SUCH DAMAGE.
29*9203SMark.Logan@Sun.COM  *******************************************************************************/
30*9203SMark.Logan@Sun.COM 
31*9203SMark.Logan@Sun.COM #ifndef _AT_VERSION_TOOL_H_
32*9203SMark.Logan@Sun.COM #define _AT_VERSION_TOOL_H_
33*9203SMark.Logan@Sun.COM 
34*9203SMark.Logan@Sun.COM #include <string>
35*9203SMark.Logan@Sun.COM #include <list>
36*9203SMark.Logan@Sun.COM 
37*9203SMark.Logan@Sun.COM class ATVersion
38*9203SMark.Logan@Sun.COM {
39*9203SMark.Logan@Sun.COM public:
40*9203SMark.Logan@Sun.COM 	/**
41*9203SMark.Logan@Sun.COM 	function check if user requested version information to be displayed on std output
42*9203SMark.Logan@Sun.COM 	and show version number
43*9203SMark.Logan@Sun.COM 	@param argc Argument count
44*9203SMark.Logan@Sun.COM 	@param argv Argument array
45*9203SMark.Logan@Sun.COM 	@param versionStr Version string to be displayed
46*9203SMark.Logan@Sun.COM 	@return bool true if version user requested version to be displayed
47*9203SMark.Logan@Sun.COM 		     false if version information was not displayed
48*9203SMark.Logan@Sun.COM 	*/
49*9203SMark.Logan@Sun.COM 	static bool ShowVersionIfArg(int argc, const char **argv, const char *versionStr);
50*9203SMark.Logan@Sun.COM 
51*9203SMark.Logan@Sun.COM 	/**
52*9203SMark.Logan@Sun.COM 	function gets application version - if target application uses this class to show version
53*9203SMark.Logan@Sun.COM 	@param appName application name
54*9203SMark.Logan@Sun.COM 	@param version string returning version or empty string if version not determined
55*9203SMark.Logan@Sun.COM 	@return true - if application is running, false - if not.
56*9203SMark.Logan@Sun.COM 	*/
57*9203SMark.Logan@Sun.COM 	static bool GetAppVersion(const char *appName, std::string &version);
58*9203SMark.Logan@Sun.COM 
59*9203SMark.Logan@Sun.COM 	/**
60*9203SMark.Logan@Sun.COM 	function gets process version - if target application uses this class to show version
61*9203SMark.Logan@Sun.COM 	@param cmd path to application
62*9203SMark.Logan@Sun.COM 	@return string version or empty string if version not determined
63*9203SMark.Logan@Sun.COM 	*/
64*9203SMark.Logan@Sun.COM 	static std::string GetProcessVersion(std::string cmd);
65*9203SMark.Logan@Sun.COM 
66*9203SMark.Logan@Sun.COM 	/**
67*9203SMark.Logan@Sun.COM 	Checks if an application is running in the system.
68*9203SMark.Logan@Sun.COM 	@param app_name Application binary name (not including path).
69*9203SMark.Logan@Sun.COM 	@param pids returned list of pids of searched application
70*9203SMark.Logan@Sun.COM 	@return true - if application is running, false - if not.
71*9203SMark.Logan@Sun.COM 	*/
72*9203SMark.Logan@Sun.COM 	static bool IsAppRunning(const char *app_name, std::list<unsigned long> &pids);
73*9203SMark.Logan@Sun.COM 
74*9203SMark.Logan@Sun.COM 	/**
75*9203SMark.Logan@Sun.COM 	Returns path associated with application with given PID. Note that to access this information for all processes
76*9203SMark.Logan@Sun.COM 	the function must be called with elevated privileges.
77*9203SMark.Logan@Sun.COM 	@param pid PID of application of interest.
78*9203SMark.Logan@Sun.COM 	@return Application path if possible.
79*9203SMark.Logan@Sun.COM 		Empty string if access is not possbile.
80*9203SMark.Logan@Sun.COM 		NULL if the application isn't runnig.
81*9203SMark.Logan@Sun.COM 	*/
82*9203SMark.Logan@Sun.COM 	static std::string GetAppPathByPid(unsigned long pid);
83*9203SMark.Logan@Sun.COM 
84*9203SMark.Logan@Sun.COM 	static const std::string appSearchPath;
85*9203SMark.Logan@Sun.COM };
86*9203SMark.Logan@Sun.COM 
87*9203SMark.Logan@Sun.COM #endif /* _AT_VERSION_TOOL_H_ */
88