001: package org.tanukisoftware.wrapper;
002:
003: /*
004: * Copyright (c) 1999, 2006 Tanuki Software Inc.
005: *
006: * Permission is hereby granted, free of charge, to any person
007: * obtaining a copy of the Java Service Wrapper and associated
008: * documentation files (the "Software"), to deal in the Software
009: * without restriction, including without limitation the rights
010: * to use, copy, modify, merge, publish, distribute, sub-license,
011: * and/or sell copies of the Software, and to permit persons to
012: * whom the Software is furnished to do so, subject to the
013: * following conditions:
014: *
015: * The above copyright notice and this permission notice shall be
016: * included in all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
020: * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
021: * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
022: * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
023: * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
024: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
025: * OTHER DEALINGS IN THE SOFTWARE.
026: */
027:
028: /**
029: * A WrapperWin32Service contains information about an individual service
030: * registered with the current system.
031: *
032: * @author Leif Mortenson <leif@tanukisoftware.com>
033: */
034: public class WrapperWin32Service {
035: public static final int SERVICE_STATE_STOPPED = 0x00000001;
036: public static final int SERVICE_STATE_START_PENDING = 0x00000002;
037: public static final int SERVICE_STATE_STOP_PENDING = 0x00000003;
038: public static final int SERVICE_STATE_RUNNING = 0x00000004;
039: public static final int SERVICE_STATE_CONTINUE_PENDING = 0x00000005;
040: public static final int SERVICE_STATE_PAUSE_PENDING = 0x00000006;
041: public static final int SERVICE_STATE_PAUSED = 0x00000007;
042:
043: /** The name of the service. */
044: private String m_name;
045:
046: /** The display name of the service. */
047: private String m_displayName;
048:
049: /** The last known state of the service. */
050: private int m_serviceState;
051:
052: /** The exit of the service. */
053: private int m_exitCode;
054:
055: /*---------------------------------------------------------------
056: * Constructors
057: *-------------------------------------------------------------*/
058: WrapperWin32Service(byte[] name, byte[] displayName,
059: int serviceState, int exitCode) {
060: // Decode the parameters using the default system encoding.
061: m_name = new String(name);
062: m_displayName = new String(displayName);
063:
064: m_serviceState = serviceState;
065: m_exitCode = exitCode;
066: }
067:
068: /*---------------------------------------------------------------
069: * Methods
070: *-------------------------------------------------------------*/
071: /**
072: * Returns the name of the service.
073: *
074: * @return The name of the service.
075: */
076: public String getName() {
077: return m_name;
078: }
079:
080: /**
081: * Returns the display name of the service.
082: *
083: * @return The display name of the service.
084: */
085: public String getDisplayName() {
086: return m_displayName;
087: }
088:
089: /**
090: * Returns the last known state name of the service.
091: *
092: * @return The last known state name of the service.
093: */
094: public String getServiceStateName() {
095: int serviceState = getServiceState();
096: switch (serviceState) {
097: case SERVICE_STATE_STOPPED:
098: return "STOPPED";
099:
100: case SERVICE_STATE_START_PENDING:
101: return "START_PENDING";
102:
103: case SERVICE_STATE_STOP_PENDING:
104: return "STOP_PENDING";
105:
106: case SERVICE_STATE_RUNNING:
107: return "RUNNING";
108:
109: case SERVICE_STATE_CONTINUE_PENDING:
110: return "CONTINUE_PENDING";
111:
112: case SERVICE_STATE_PAUSE_PENDING:
113: return "PAUSE_PENDING";
114:
115: case SERVICE_STATE_PAUSED:
116: return "PAUSED";
117:
118: default:
119: return "UNKNOWN(" + serviceState + ")";
120: }
121: }
122:
123: /**
124: * Returns the last known state of the service.
125: *
126: * @return The last known state of the service.
127: */
128: public int getServiceState() {
129: return m_serviceState;
130: }
131:
132: /**
133: * Returns the exit of the service, or 0 if it is still running.
134: *
135: * @return The exit of the service.
136: */
137: public int getExitCode() {
138: return m_exitCode;
139: }
140:
141: /**
142: * Returns a string representation of the user.
143: *
144: * @return A string representation of the user.
145: */
146: public String toString() {
147: StringBuffer sb = new StringBuffer();
148: sb.append("WrapperWin32Service[name=\"");
149: sb.append(getName());
150: sb.append("\", displayName=\"");
151: sb.append(getDisplayName());
152:
153: sb.append("\", state=");
154: sb.append(getServiceStateName());
155: sb.append(", exitCode=");
156: sb.append(getExitCode());
157: sb.append("]");
158: return sb.toString();
159: }
160: }
|