Skip to content

Commit

Permalink
Merge pull request #574 from lgoldstein/static-structure-fields
Browse files Browse the repository at this point in the history
Using static final un-modifiable List of field names for structure(s)
  • Loading branch information
twall committed Jan 10, 2016
2 parents e6d4cd2 + 898e686 commit ba18b38
Show file tree
Hide file tree
Showing 102 changed files with 3,024 additions and 2,652 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Features
* [#563](https://github.com/java-native-access/jna/pull/563): Added `com.sun.jna.platform.win32.Wininet` with the following 4 methods: `FindFirstUrlCacheEntry`, `DeleteUrlCacheEntry`, `FindCloseUrlCache`, `FindNextUrlCacheEntry`, and the `INTERNET_CACHE_ENTRY_INFO` structure, and a helper in `com.sun.jna.platform.win32.WininetUtil` for parsing WinInet's cache - [@mlfreeman2](https://github.com/mlfreeman2).
* [#567](https://github.com/java-native-access/jna/pull/567): Added `PrintWindow`, `IsWindowEnabled`, `IsWindow`, `FindWindowEx`, `GetAncestor`, `GetCursorPos`, `SetCursorPos`, `SetWinEventHook`, `UnhookWinEvent`, `CopyIcon`, and `GetClassLong` to `com.sun.jna.platform.win32.User32` and supporting constants to `com.sun.jna.platform.win32.WinUser` - [@mlfreeman2](https://github.com/mlfreeman2).
* [#573](https://github.com/java-native-access/jna/pull/573): Added `EnumProcessModules`, `GetModuleInformation`, and `GetProcessImageFileName` to `com.sun.jna.platform.win32.Psapi` and added `ExtractIconEx` to `com.sun.jna.platform.win32.Shell32` - [@mlfreeman2](https://github.com/mlfreeman2).
* [#574](https://github.com/java-native-access/jna/pull/574): Using static final un-modifiable List of field names for structure(s) [@lgoldstein](https://github.com/lgoldstein)

Bug Fixes
---------
Expand Down
20 changes: 14 additions & 6 deletions contrib/ntservice/src/jnacontrib/jna/Advapi32.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public int callback(int dwControl, int dwEventType,
* SERVICE_STATUS,LPSERVICE_STATUS;
*/
public static class SERVICE_STATUS extends Structure {
public static final List<String> FIELDS = createFieldsOrder(
"dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint");

public int dwServiceType;
public int dwCurrentState;
public int dwControlsAccepted;
Expand All @@ -159,8 +162,9 @@ public static class SERVICE_STATUS extends Structure {
public int dwCheckPoint;
public int dwWaitHint;

protected List getFieldOrder() {
return Arrays.asList(new String[] { "dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint" });
@Override
protected List<String> getFieldOrder() {
return FIELDS;
}
}

Expand All @@ -170,11 +174,13 @@ protected List getFieldOrder() {
* LPSERVICE_TABLE_ENTRY;
*/
public static class SERVICE_TABLE_ENTRY extends Structure {
public static final List<String> FIELDS = createFieldsOrder("lpServiceName", "lpServiceProc");
public String lpServiceName;
public SERVICE_MAIN_FUNCTION lpServiceProc;

protected List getFieldOrder() {
return Arrays.asList(new String[] { "lpServiceName", "lpServiceProc" });
@Override
protected List<String> getFieldOrder() {
return FIELDS;
}
}

Expand All @@ -186,10 +192,12 @@ public static abstract class ChangeServiceConfig2Info extends Structure {
* SERVICE_DESCRIPTION,LPSERVICE_DESCRIPTION;
*/
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
public static final List<String> FIELDS = createFieldsOrder("lpDescription");
public String lpDescription;

protected List getFieldOrder() {
return Arrays.asList(new String[] { "lpDescription" });
@Override
protected List<String> getFieldOrder() {
return FIELDS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* Methods that are useful to decompose a raster into a set of rectangles.
* An occupied pixel has two possible meanings, depending on the raster :
* An occupied pixel has two possible meanings, depending on the raster :
* <ul>
* <li>if the raster has an alpha layer, occupied means with alpha not null</li>
* <li>if the raster doesn't have any alpha layer, occupied means not completely black</li>
Expand All @@ -45,6 +45,7 @@ public class RasterRangesUtils {
};

private static final Comparator<Object> COMPARATOR = new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
return ((Rectangle)o1).x - ((Rectangle)o2).x;
}
Expand Down Expand Up @@ -117,7 +118,7 @@ public static boolean outputOccupiedRanges(Raster raster, RangesOutput out) {
*/
public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int w, int h, RangesOutput out) {
Set<Rectangle> rects = new HashSet<Rectangle>();
Set<Rectangle> prevLine = Collections.EMPTY_SET;
Set<Rectangle> prevLine = Collections.<Rectangle>emptySet();
int scanlineBytes = binaryBits.length / h;
for (int row = 0; row < h; row++) {
Set<Rectangle> curLine = new TreeSet<Rectangle>(COMPARATOR);
Expand Down Expand Up @@ -190,7 +191,7 @@ public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int
*/
public static boolean outputOccupiedRanges(int[] pixels, int w, int h, int occupationMask, RangesOutput out) {
Set<Rectangle> rects = new HashSet<Rectangle>();
Set<Rectangle> prevLine = Collections.EMPTY_SET;
Set<Rectangle> prevLine = Collections.<Rectangle>emptySet();
for (int row = 0; row < h; row++) {
Set<Rectangle> curLine = new TreeSet<Rectangle>(COMPARATOR);
int idxOffset = row * w;
Expand Down
11 changes: 8 additions & 3 deletions contrib/platform/src/com/sun/jna/platform/mac/Carbon.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.sun.jna.platform.mac;

import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
Expand Down Expand Up @@ -72,22 +71,28 @@ public interface Carbon extends Library {
int UnregisterEventHotKey(Pointer inHotKey);

public class EventTypeSpec extends Structure {
public static final List<String> FIELDS = createFieldsOrder("eventClass", "eventKind");

public int eventClass;
public int eventKind;

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("eventClass", "eventKind");
return FIELDS;
}
}

public static class EventHotKeyID extends Structure {
public static final List<String> FIELDS = createFieldsOrder("signature", "id");

public int signature;
public int id;

public static class ByValue extends EventHotKeyID implements Structure.ByValue { }

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("signature", "id");
return FIELDS;
}
}

Expand Down
19 changes: 12 additions & 7 deletions contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Expand All @@ -15,19 +15,18 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.platform.FileUtils;

public class MacFileUtils extends FileUtils {

@Override
public boolean hasTrash() { return true; }

public interface FileManager extends Library {
Expand All @@ -44,19 +43,25 @@ public interface FileManager extends Library {
int kFSPathMakeRefDoNotFollowLeafSymlink = 0x01;

class FSRef extends Structure {
public static final List<String> FIELDS = createFieldsOrder("hidden");
public byte[] hidden = new byte[80];
protected List getFieldOrder() { return Arrays.asList(new String[] { "hidden" }); }

@Override
protected List<String> getFieldOrder() {
return FIELDS;
}
}

// Deprecated; use trashItemAtURL instead:
// https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/trashItemAtURL:resultingItemURL:error:
// https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/trashItemAtURL:resultingItemURL:error:
int FSRefMakePath(FSRef fsref, byte[] path, int maxPathSize);
int FSPathMakeRef(String source, int options, ByteByReference isDirectory);
int FSPathMakeRefWithOptions(String source, int options, FSRef fsref, ByteByReference isDirectory);
int FSPathMoveObjectToTrashSync(String source, PointerByReference target, int options);
int FSMoveObjectToTrashSync(FSRef source, FSRef target, int options);
}

@Override
public void moveToTrash(File[] files) throws IOException {
File home = new File(System.getProperty("user.home"));
File trash = new File(home, ".Trash");
Expand All @@ -67,7 +72,7 @@ public void moveToTrash(File[] files) throws IOException {
for (int i=0;i < files.length;i++) {
File src = files[i];
FileManager.FSRef fsref = new FileManager.FSRef();
int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(),
int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(),
FileManager.kFSPathMakeRefDoNotFollowLeafSymlink,
fsref, null);
if (status != 0) {
Expand Down
47 changes: 26 additions & 21 deletions contrib/platform/src/com/sun/jna/platform/mac/SystemB.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.sun.jna.platform.mac;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
Expand Down Expand Up @@ -59,25 +58,33 @@ public interface SystemB extends Library {
int INT_SIZE = Native.getNativeSize(int.class);

public static class HostCpuLoadInfo extends Structure {
public static final List<String> FIELDS = createFieldsOrder("cpu_ticks");
public int cpu_ticks[] = new int[CPU_STATE_MAX];

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("cpu_ticks");
return FIELDS;
}
}

public static class HostLoadInfo extends Structure {
public static final List<String> FIELDS = createFieldsOrder("avenrun", "mach_factor");
public int[] avenrun = new int[3]; // scaled by LOAD_SCALE
public int[] mach_factor = new int[3]; // scaled by LOAD_SCALE

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("avenrun", "mach_factor");
return FIELDS;
}
}

public static class VMStatistics extends Structure {
public static final List<String> FIELDS = createFieldsOrder("free_count", "active_count",
"inactive_count", "wire_count", "zero_fill_count",
"reactivations", "pageins", "pageouts", "faults",
"cow_faults", "lookups", "hits", "purgeable_count",
"purges", "speculative_count");

public int free_count; // # of pages free
public int active_count; // # of pages active
public int inactive_count; // # of pages inactive
Expand All @@ -97,15 +104,25 @@ public static class VMStatistics extends Structure {

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("free_count", "active_count",
"inactive_count", "wire_count", "zero_fill_count",
"reactivations", "pageins", "pageouts", "faults",
"cow_faults", "lookups", "hits", "purgeable_count",
"purges", "speculative_count");
return FIELDS;
}
}

public static class VMStatistics64 extends Structure {
public static final List<String> FIELDS = createFieldsOrder("free_count", "active_count",
"inactive_count", "wire_count",
"zero_fill_count", "reactivations",
"pageins", "pageouts",
"faults", "cow_faults",
"lookups", "hits",
"purges",
"purgeable_count", "speculative_count",
"decompressions", "compressions",
"swapins", "swapouts",
"compressor_page_count", "throttled_count",
"external_page_count", "internal_page_count",
"total_uncompressed_pages_in_compressor");

public int free_count; // # of pages free
public int active_count; // # of pages active
public int inactive_count; // # of pages inactive
Expand Down Expand Up @@ -139,19 +156,7 @@ public static class VMStatistics64 extends Structure {

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("free_count", "active_count",
"inactive_count", "wire_count",
"zero_fill_count", "reactivations",
"pageins", "pageouts",
"faults", "cow_faults",
"lookups", "hits",
"purges",
"purgeable_count", "speculative_count",
"decompressions", "compressions",
"swapins", "swapouts",
"compressor_page_count", "throttled_count",
"external_page_count", "internal_page_count",
"total_uncompressed_pages_in_compressor");
return FIELDS;
}
}

Expand Down
5 changes: 3 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/unix/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package com.sun.jna.platform.unix;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Structure;
Expand Down Expand Up @@ -83,6 +82,8 @@ public interface Resource {
int RLIMIT_NLIMITS = 16;

public static class Rlimit extends Structure {
public static final List<String> FIELDS = createFieldsOrder("rlim_cur", "rlim_max");

/** The current (soft) limit. */
public long rlim_cur;

Expand All @@ -91,7 +92,7 @@ public static class Rlimit extends Structure {

@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "rlim_cur", "rlim_max" });
return FIELDS;
}
}

Expand Down
Loading

0 comments on commit ba18b38

Please sign in to comment.