Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A9A4E7CA5 for ; Wed, 20 Jul 2011 07:15:30 +0000 (UTC) Received: (qmail 34429 invoked by uid 500); 20 Jul 2011 07:15:29 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 34071 invoked by uid 500); 20 Jul 2011 07:15:18 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 34064 invoked by uid 99); 20 Jul 2011 07:15:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jul 2011 07:15:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jul 2011 07:15:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7CE8623888CE for ; Wed, 20 Jul 2011 07:14:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1148632 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/windows/Service.java native/os/win32/registry.c Date: Wed, 20 Jul 2011 07:14:51 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110720071451.7CE8623888CE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed Jul 20 07:14:50 2011 New Revision: 1148632 URL: http://svn.apache.org/viewvc?rev=1148632&view=rev Log: Implement win32 Service description set/get API Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java?rev=1148632&r1=1148631&r2=1148632&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java Wed Jul 20 07:14:50 2011 @@ -23,6 +23,7 @@ import java.util.EnumSet; import java.util.List; import org.apache.commons.runtime.Errno; import org.apache.commons.runtime.Status; +import org.apache.commons.runtime.InvalidArgumentException; import org.apache.commons.runtime.SystemException; import org.apache.commons.runtime.TimeoutException; import org.apache.commons.runtime.util.Utils; @@ -148,12 +149,12 @@ public final class Service implements Cl * Creates a new service object */ public Service(String name) - throws IllegalArgumentException + throws InvalidArgumentException { if (name == null || name.length() < 1 || name.length() > 256) - throw new IllegalArgumentException("invalid service name length"); + throw new InvalidArgumentException("invalid service name length"); if (name.indexOf('/') != -1 || name.indexOf('\\') != -1) - throw new IllegalArgumentException("invalid service name characters"); + throw new InvalidArgumentException("invalid service name characters"); serviceName = name; serviceStatusProcess = new int[9]; } @@ -209,6 +210,9 @@ public final class Service implements Cl return serviceName; } + /** + * Gets the display name used by user interface programs to identify the service. + */ public String getDisplayName() { return displayName; @@ -314,6 +318,39 @@ public final class Service implements Cl } /** + * Get this service's description. + * + * @return description string, or {@code null} if description was + * not set. + * + */ + public String getDescription() + throws IOException + { + RegistryKey key = Registry.LocalMachine.open(SERVICES_KEY + "\\" + serviceName); + String desc = key.getValue("Description"); + key.close(); + return desc; + } + + /** + * Set this service's description. + * + * @param desc description string to set, or {@code null} to remove the + * description. + */ + public void setDescription(String desc) + throws IOException + { + RegistryKey key = Registry.LocalMachine.open(SERVICES_KEY + "\\" + serviceName, RegistryKeyAccessRights.WRITE); + if (desc == null) + key.deleteValue("Description"); + else + key.setValue("Description", desc); + key.close(); + } + + /** * Starts a service. * * @param args strings to be passed to the {@code ServiceMain} function for @@ -382,7 +419,7 @@ public final class Service implements Cl if (handle == 0L) throw new InvalidHandleException(); if (c < 128 || c > 255) - throw new IllegalArgumentException("control code must be in range from 128 to 255"); + throw new InvalidArgumentException("control code must be in range from 128 to 255"); int rc = Win32.ControlService(handle, c, serviceStatusProcess); if (rc != 0) { if (Status.IS_EACCES(rc)) @@ -637,11 +674,30 @@ public final class Service implements Cl } } + /** + * Sets the display name to be used by user interface programs to + * identify the service. + *

+ * This string has a maximum length of (@code 256} characters. + * The name is case-preserved in the service control manager. + * Display name comparisons are always case-insensitive. + *

+ * + * @param name the description string to set. + * + * @throws InvalidArgumentException + * if the name is longer then {@code 256} characters. + */ public void setDisplayName(String name) throws InvalidHandleException, SystemException { if (handle == 0L) throw new InvalidHandleException(); + if (name.length() > 256) { + // We could let the Windows API returns error. + // TODO: localize message. + throw new InvalidArgumentException("display name must have less then 256 characters"); + } int rc = Win32.ChangeServiceConfig(handle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=1148632&r1=1148631&r2=1148632&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Wed Jul 20 07:14:50 2011 @@ -94,7 +94,7 @@ ACR_WIN_EXPORT(jlong, RegistryKeyImpl, o &skey); } DONE_WITH_STR(name); - if (rc) { + if (rc != 0) { skey = NULL; ACR_THROW_SYS_ERROR(rc); } @@ -121,7 +121,7 @@ ACR_WIN_EXPORT(jlong, RegistryKeyImpl, c NULL); } DONE_WITH_STR(name); - if (rc) { + if (rc != 0) { skey = 0; ACR_THROW_SYS_ERROR(rc); }