r2883 - in branches/2.0.0-evol-499-storage: . src/main/java/org/chorem/jtimer/ui/system src/main/java/org/chorem/jtimer/ui/system/macos src/main/java/org/chorem/jtimer/ui/system/unix src/main/java/org/chorem/jtimer/ui/system/win32
Author: echatellier Date: 2012-07-12 14:51:48 +0200 (Thu, 12 Jul 2012) New Revision: 2883 Url: http://chorem.org/repositories/revision/jtimer/2883 Log: Merge branche 1.4.x-evol-657-bridj Added: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java Modified: branches/2.0.0-evol-499-storage/ branches/2.0.0-evol-499-storage/pom.xml branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/package-info.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java Property changes on: branches/2.0.0-evol-499-storage ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.4.0-ttalgo:2840-2847 + /branches/1.4.0-ttalgo:2840-2847 /branches/1.4.x-evol-657-bridj:2876-2882 Modified: branches/2.0.0-evol-499-storage/pom.xml =================================================================== --- branches/2.0.0-evol-499-storage/pom.xml 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/pom.xml 2012-07-12 12:51:48 UTC (rev 2883) @@ -90,8 +90,6 @@ <!--Multilanguage maven-site --> <locales>fr,en</locales> - - <xmrpcVersion>3.1.3</xmrpcVersion> <!-- files to deploy to redmine --> <redmine.releaseFiles> @@ -201,7 +199,7 @@ <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> - <version>2.4.8</version> + <version>2.5.1</version> <scope>compile</scope> <exclusions> <exclusion> @@ -237,18 +235,18 @@ <scope>compile</scope> </dependency> <dependency> - <groupId>net.java.dev.jna</groupId> - <artifactId>jna</artifactId> - <version>3.4.0</version> + <groupId>com.nativelibs4java</groupId> + <artifactId>bridj</artifactId> + <version>0.6.1</version> <scope>compile</scope> + <exclusions> + <exclusion> + <groupId>com.google.android.tools</groupId> + <artifactId>dx</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> - <groupId>net.java.dev.jna</groupId> - <artifactId>platform</artifactId> - <version>3.4.0</version> - <scope>compile</scope> - </dependency> - <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <scope>runtime</scope> @@ -258,9 +256,14 @@ <artifactId>freemarker</artifactId> <version>2.3.19</version> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.3.163</version> + <scope>runtime</scope> + </dependency> <!-- commons-xxx lib --> - <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> @@ -277,14 +280,8 @@ <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <scope>runtime</scope> - </dependency> <!-- tests dependencies --> - <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -27,12 +27,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.bridj.Platform; import org.chorem.jtimer.ui.system.macos.MacOSSystemInfo; import org.chorem.jtimer.ui.system.unix.UnixSystemInfo; import org.chorem.jtimer.ui.system.win32.Win32SystemInfo; -import com.sun.jna.Platform; - /** * Build system info determined from system. * @@ -81,7 +80,7 @@ instance = new Win32SystemInfo(); } else if (Platform.isLinux()) { instance = new UnixSystemInfo(); - } else if (Platform.isMac()) { + } else if (Platform.isMacOSX()) { instance = new MacOSSystemInfo(); } else { // system unknown Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,11 +25,11 @@ package org.chorem.jtimer.ui.system.macos; -import com.sun.jna.Library; -import com.sun.jna.Native; +import org.bridj.BridJ; +import org.bridj.ann.Library; /** - * Quartz 2D API. + * Mac OS X Bridj library. * * @author chatellier * @version $Revision$ @@ -38,21 +38,22 @@ * Last update : $Date$ * By : $Author: chatellier $ */ -public interface ApplicationServices extends Library { - - ApplicationServices INSTANCE = (ApplicationServices) Native.loadLibrary( - "ApplicationServices", ApplicationServices.class); - - /** Constants that specify an input event. */ - int kCGAnyInputEventType = -1; - /** Specifies that an event source should use a private event state table. */ - int kCGEventSourceStatePrivate = -1; - /** Specifies that an event source should use the event state table that reflects the combined state of all event sources posting to the current user login session. */ - int kCGEventSourceStateCombinedSessionState = 0; - /** Specifies that an event source should use the event state table that reflects the combined state of all hardware event sources posting from the HID system. */ - int kCGEventSourceStateHIDSystemState = 1; - - /** +@Library("ApplicationServices") +public class ApplicationServices { + static { + BridJ.register(); + } + + /** Constants that specify an input event. */ + public static final int kCGAnyInputEventType = ~0; + /** Specifies that an event source should use a private event state table. */ + public static final int kCGEventSourceStatePrivate = -1; + /** Specifies that an event source should use the event state table that reflects the combined state of all event sources posting to the current user login session. */ + public static final int kCGEventSourceStateCombinedSessionState = 0; + /** Specifies that an event source should use the event state table that reflects the combined state of all hardware event sources posting from the HID system. */ + public static final int kCGEventSourceStateHIDSystemState = 1; + + /** * Returns the elapsed time since the last event for a Quartz event source. * * @param sourceStateId The source state to access @@ -61,6 +62,5 @@ * * @see <a href="http://developer.apple.com/mac/library/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventSourceSecondsSinceLastEventType">Quartz API</a> */ - public double CGEventSourceSecondsSinceLastEventType(int sourceStateId, - int eventType); -} \ No newline at end of file + public static native double CGEventSourceSecondsSinceLastEventType(int source, int eventType); +} Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -46,7 +46,7 @@ */ @Override public long getIdleTime() { - double idleTimeSeconds = ApplicationServices.INSTANCE + double idleTimeSeconds = ApplicationServices .CGEventSourceSecondsSinceLastEventType( ApplicationServices.kCGEventSourceStateCombinedSessionState, ApplicationServices.kCGAnyInputEventType); Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/package-info.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/package-info.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/package-info.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -23,6 +23,6 @@ * #L% */ /** - * System interface using JNA to get system information. + * System interface using Bridj to get system information. */ package org.chorem.jtimer.ui.system; Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -27,11 +27,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.bridj.Pointer; import org.chorem.jtimer.ui.system.SystemInfo; -import com.sun.jna.platform.unix.X11; -import com.sun.jna.ptr.IntByReference; - /** * Linux system info. * @@ -80,58 +78,31 @@ long idleTime = 0; // get X11 display - X11.Display display = X11.INSTANCE.XOpenDisplay(null); + X11.Display display = X11.XOpenDisplay(null); if (display == null) { log.error("Can't open X11 display"); } else { // Display is opened + Pointer<Xss.XScreenSaverInfo> screenSaverInfo = Xss.XScreenSaverAllocInfo(); - // check if screensaver extension is enabled - IntByReference eventBase = new IntByReference(); - IntByReference errorBase = new IntByReference(); - - if (!Xss.INSTANCE.XScreenSaverQueryExtension(display, eventBase, - errorBase)) { - if (log.isErrorEnabled()) { - log.error("Can't find xscreensaver extension, " - + "idle time can't be detected"); - } + if (screenSaverInfo == null) { + log.error("Could not alloc screen saver info"); } else { - // screensaver is enabled - - Xss.XScreenSaverInfo screenSaverInfo = Xss.INSTANCE - .XScreenSaverAllocInfo(); - - if (screenSaverInfo == null) { - log.error("Could not alloc screen saver info"); + // get root window + X11.Window rootWindow = X11.XDefaultRootWindow(display); + int flag = Xss.XScreenSaverQueryInfo(display, rootWindow, screenSaverInfo); + if (flag == 0) { + log.error("Can't get user idle time"); } else { - // get root window - X11.Window rootWindow = X11.INSTANCE - .XDefaultRootWindow(display); - - if (rootWindow == null) { - log.error("Could not query root window"); - } else { - - // FIX : without this, cause random NPE - screenSaverInfo.window = rootWindow; - - Xss.INSTANCE.XScreenSaverQueryInfo(display, rootWindow, - screenSaverInfo); - if (screenSaverInfo.idle == null) { - log.error("screenSaverInfo.idle is null"); - } else { - idleTime = screenSaverInfo.idle.longValue(); - } - } - - // free resources - X11.INSTANCE.XFree(screenSaverInfo.getPointer()); + idleTime = screenSaverInfo.get().idle(); } + + // free resources + X11.XFree(screenSaverInfo); } // free resources - X11.INSTANCE.XCloseDisplay(display); + X11.XCloseDisplay(display); } return idleTime; Copied: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java (from rev 2882, branches/1.4.x-evol-657-bridj/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java) =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java (rev 0) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -0,0 +1,60 @@ +package org.chorem.jtimer.ui.system.unix; + +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.TypedPointer; +import org.bridj.ann.Library; + +/** + * Unix X11 Bridj library. + * + * @author chatellier + * @version $Revision: 2778 $ + * + * Last update : $Date: 2011-09-05 10:12:54 +0200 (lun. 05 sept. 2011) $ + * By : $Author: echatellier $ + */ +@Library("X11") +public class X11 { + static { + BridJ.register(); + } + + public static class Drawable extends TypedPointer { + public Drawable(long peer) { + super(peer); + } + + public Drawable(Pointer<?> ptr) { + super(ptr); + } + } + + public static class Window extends Drawable { + public Window(long peer) { + super(peer); + } + + public Window(Pointer<?> ptr) { + super(ptr); + } + } + + public static class Display extends TypedPointer { + public Display(long peer) { + super(peer); + } + + public Display(Pointer<?> ptr) { + super(ptr); + } + } + + public static native Display XOpenDisplay(Pointer<Byte> name); + + public static native Window XDefaultRootWindow(Display display); + + public static native int XFree(Pointer data); + + public static native int XCloseDisplay(Display display); +} Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2010 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,70 +25,132 @@ package org.chorem.jtimer.ui.system.unix; -import com.sun.jna.Library; -import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import com.sun.jna.Structure; -import com.sun.jna.platform.unix.X11; -import com.sun.jna.ptr.IntByReference; +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.StructObject; +import org.bridj.ann.Field; +import org.bridj.ann.Library; +import org.bridj.ann.Ptr; /** - * libXss JNA interface. + * Unix Xss Bridj library. * - * Incomplete definition. - * * @author chatellier * @version $Revision$ * * Last update : $Date$ * By : $Author$ */ -public interface Xss extends Library { +@Library("Xss") +public class Xss { + static { + BridJ.register(); + } - /** Xss Instance */ - Xss INSTANCE = (Xss) Native.loadLibrary("Xss", Xss.class); + public static class XScreenSaverInfo extends StructObject { + public XScreenSaverInfo() { + super(); + } - /** - * XScreenSaverInfo struct - */ - public static class XScreenSaverInfo extends Structure { - public X11.Window window; /* screen saver window - may not exist */ - public int state; /* ScreenSaverOff, ScreenSaverOn, ScreenSaverDisabled */ - public int kind; /* ScreenSaverBlanked, ...Internal, ...External */ - public NativeLong til_or_since; /* time til or since screen saver */ - public NativeLong idle; /* total time since last user input */ - public NativeLong eventMask; /* currently selected events for this client */ + public XScreenSaverInfo(Pointer pointer) { + super(pointer); + } + + /** + * screen saver window<br> + * C type : Window + */ + @Ptr + @Field(0) + public long window() { + return this.io.getSizeTField(this, 0); + } + + /** + * screen saver window<br> + * C type : Window + */ + @Ptr + @Field(0) + public XScreenSaverInfo window(long window) { + this.io.setSizeTField(this, 0, window); + return this; + } + + // ScreenSaver{Off,On,Disabled} + @Field(1) + public int state() { + return this.io.getIntField(this, 1); + } + + // ScreenSaver{Off,On,Disabled} + @Field(1) + public XScreenSaverInfo state(int state) { + this.io.setIntField(this, 1, state); + return this; + } + + // ScreenSaver{Blanked,Internal,External} + @Field(2) + public int kind() { + return this.io.getIntField(this, 2); + } + + // ScreenSaver{Blanked,Internal,External} + @Field(2) + public XScreenSaverInfo kind(int kind) { + this.io.setIntField(this, 2, kind); + return this; + } + + // milliseconds + @org.bridj.ann.CLong + @Field(3) + public long til_or_since() { + return this.io.getCLongField(this, 3); + } + + // milliseconds + @org.bridj.ann.CLong + @Field(3) + public XScreenSaverInfo til_or_since(long til_or_since) { + this.io.setCLongField(this, 3, til_or_since); + return this; + } + + // milliseconds + @org.bridj.ann.CLong + @Field(4) + public long idle() { + return this.io.getCLongField(this, 4); + } + + // milliseconds + @org.bridj.ann.CLong + @Field(4) + public XScreenSaverInfo idle(long idle) { + this.io.setCLongField(this, 4, idle); + return this; + } + + // events + @org.bridj.ann.CLong + @Field(5) + public long event_mask() { + return this.io.getCLongField(this, 5); + } + + // events + @org.bridj.ann.CLong + @Field(5) + public XScreenSaverInfo event_mask(long event_mask) { + this.io.setCLongField(this, 5, event_mask); + return this; + } } - /** - * Information sur l'activation de l'ecran de veille de X11. - * - * @param display display - * @param event_base event_base - * @param error_base error_base - * - * @return true if XScreenSaver extension is loaded - * - * @see IntByReference - */ - public boolean XScreenSaverQueryExtension(X11.Display display, - IntByReference event_base, IntByReference error_base); + public static native Pointer<XScreenSaverInfo> XScreenSaverAllocInfo(); - /** - * XScreenSaverAllocInfo. - * - * @return XScreenSaverInfo instance - */ - public XScreenSaverInfo XScreenSaverAllocInfo(); - - /** - * XScreenSaverQueryInfo. - * - * @param display - * @param drawable - * @param infos - * @return status flag - */ - public int XScreenSaverQueryInfo(X11.Display display, - X11.Drawable drawable, XScreenSaverInfo infos); + public static native int XScreenSaverQueryInfo(X11.Display dpy, + X11.Drawable drawable, Pointer<XScreenSaverInfo> saver_info); } Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as Copied: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java (from rev 2882, branches/1.4.x-evol-657-bridj/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java) =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java (rev 0) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -0,0 +1,58 @@ +/* + * #%L + * jTimer + * + * $Id: UnixSystemInfo.java 2828 2012-03-16 11:00:21Z echatellier $ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.ui.system.win32; + +import org.bridj.*; +import org.bridj.ann.*; + +/** + * Win Kernel32 Bridj library. + * + * @author chatellier + * @version $Revision: 2778 $ + * + * Last update : $Date: 2011-09-05 10:12:54 +0200 (lun. 05 sept. 2011) $ + * By : $Author: echatellier $ + */ +@Convention(Convention.Style.StdCall) +@Library("kernel32") +public class Kernel32 { + static { + BridJ.register(); + } + + /** + * Retrieves the number of milliseconds that have elapsed since the system + * was started. + * + * @see <a + * href="http://msdn2.microsoft.com/en-us/library/ms724408.aspx">MSDN + * GetTickCount function</a> + * @return number of milliseconds that have elapsed since the system was + * started. + */ + public static native int GetTickCount(); +} Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,43 +25,56 @@ package org.chorem.jtimer.ui.system.win32; -import com.sun.jna.Native; -import com.sun.jna.Structure; -import com.sun.jna.win32.StdCallLibrary; +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.StructObject; +import org.bridj.ann.Convention; +import org.bridj.ann.Field; +import org.bridj.ann.Library; /** - * Win User32 JNA Interface. + * Win User32 Bridj library. * - * TODO it not the same code as jna's User32 class. - * * @author chatellier * @version $Revision$ - * - * @see <a href="http://msdn.microsoft.com/en-us/library/ms646272">Windows API</a> * * Last update : $Date$ * By : $Author$ */ -public interface User32 extends StdCallLibrary { +@Convention(Convention.Style.StdCall) +@Library("user32") +public class User32 { + static { + BridJ.register(); + } - /** Instance. */ - User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); - /** * Contains the time of the last input. + * + * @see <a + * href="http://msdn.microsoft.com/en-us/library/ms646272">MSDN + * LASTINPUTINFO structure</a> */ - class LASTINPUTINFO extends Structure { - public int cbSize = 8; + public static class LASTINPUTINFO extends StructObject { + @Field(0) + public int cbSize() { + return this.io.getIntField(this, 0); + } // / Tick count of when the last input event was received. - public int dwTime; + @Field(1) + public int dwTime() { + return this.io.getIntField(this, 1); + } } /** * Retrieves the time of the last input event. * - * @param result time of the last input event, in milliseconds - * @return boolean flag + * @see <a + * href="http://msdn.microsoft.com/en-us/library/ms646272">MSDN + * GetLastInputInfo function</a> + * @return time of the last input event, in milliseconds */ - boolean GetLastInputInfo(LASTINPUTINFO result); + public static native boolean GetLastInputInfo(Pointer<LASTINPUTINFO> result); } Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -25,14 +25,13 @@ package org.chorem.jtimer.ui.system.win32; +import org.bridj.Pointer; import org.chorem.jtimer.ui.system.SystemInfo; -import com.sun.jna.platform.win32.Kernel32; - /** * Win32 System info. * - * From http://ochafik.free.fr/blog/?p=98 + * From https://github.com/ochafik/nativelibs4java. * * @author chatellier * @version $Revision$ @@ -61,8 +60,9 @@ * @return idle time in milliseconds */ public int getIdleTimeMillisWin32() { - User32.INSTANCE.GetLastInputInfo(lastInputInfo); - return Kernel32.INSTANCE.GetTickCount() - lastInputInfo.dwTime; + User32.LASTINPUTINFO lastInputInfo = new User32.LASTINPUTINFO(); + User32.GetLastInputInfo(Pointer.pointerTo(lastInputInfo)); + return Kernel32.GetTickCount() - lastInputInfo.dwTime(); } /* Modified: branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java =================================================================== --- branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java 2012-06-30 12:14:40 UTC (rev 2882) +++ branches/2.0.0-evol-499-storage/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java 2012-07-12 12:51:48 UTC (rev 2883) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as
participants (1)
-
echatellier@users.chorem.org