winpack-3.8.3

16:53:57.265 INFO  jd.cli.Main - Decompiling winpack-3.8.3.jar
package com.jniwrapper.win32;

import com.jniwrapper.win32.system.Kernel32;

public class FunctionName
{
  static final char SUFFIX_ANSI = 'A';
  static final char SUFFIX_UNICODE = 'W';
  private String _name;
  private boolean _hasANSISuffix = true;
  private static boolean _useUnicode = Kernel32.getInstance().isUnicode();
  
  public static void useUnicodeNames(boolean value)
  {
    _useUnicode = value;
  }
  
  public static boolean usesUnicodeNames()
  {
    return _useUnicode;
  }
  
  public FunctionName(String name)
  {
    _name = name;
  }
  
  public FunctionName(String name, boolean hasANSISuffix)
  {
    _name = name;
    _hasANSISuffix = hasANSISuffix;
  }
  
  public boolean hasANSISuffix()
  {
    return _hasANSISuffix;
  }
  
  public String getName()
  {
    return _name;
  }
  
  public String getEncodingSpecificName(boolean unicode)
  {
    StringBuffer result = new StringBuffer(getName());
    if (unicode) {
      result.append('W');
    } else if (_hasANSISuffix) {
      result.append('A');
    }
    return result.toString();
  }
  
  public String toString()
  {
    return getEncodingSpecificName(_useUnicode);
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.FunctionName
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Int32;
import com.jniwrapper.IntegerParameter;
import com.jniwrapper.util.Logger;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class HResult
  extends Int32
{
  public static final int S_OK = 0;
  public static final int S_FALSE = 1;
  public static final int E_NOTIMPL = -2147467263;
  public static final int E_OUTOFMEMORY = -2147024882;
  public static final int E_INVALIDARG = -2147024809;
  public static final int E_NOINTERFACE = -2147467262;
  public static final int E_POINTER = -2147467261;
  public static final int E_HANDLE = -2147024890;
  public static final int E_ABORT = -2147467260;
  public static final int E_FAIL = -2147467259;
  public static final int E_UNEXPECTED = -2147418113;
  public static final int E_ACCESSDENIED = -2147024891;
  public static final int CLASS_E_NOAGGREGATION = -2147221232;
  public static final int CLASS_E_CLASSNOTAVAILABLE = -2147221231;
  public static final int CLASS_E_NOTLICENSED = -2147221230;
  public static final int CONNECT_E_FIRST = -2147220992;
  public static final int CONNECT_E_NOCONNECTION = -2147220991;
  public static final int CONNECT_E_ADVISELIMIT = -2147220990;
  public static final int CONNECT_E_CANNOTCONNECT = -2147220989;
  public static final int CONNECT_E_OVERRIDDEN = -2147220988;
  public static final int SELFREG_E_TYPELIB = -2147220992;
  public static final int SELFREG_E_CLASS = -2147220991;
  public static final int PERPROP_E_NOPAGEAVAILABLE = -2147220992;
  public static final int INET_E_INVALID_URL = -2146697214;
  public static final int INET_E_NO_SESSION = -2146697213;
  public static final int INET_E_CANNOT_CONNECT = -2146697212;
  public static final int INET_E_RESOURCE_NOT_FOUND = -2146697211;
  public static final int INET_E_OBJECT_NOT_FOUND = -2146697210;
  public static final int INET_E_DATA_NOT_AVAILABLE = -2146697209;
  public static final int INET_E_DOWNLOAD_FAILURE = -2146697208;
  public static final int INET_E_AUTHENTICATION_REQUIRED = -2146697207;
  public static final int INET_E_NO_VALID_MEDIA = -2146697206;
  public static final int INET_E_CONNECTION_TIMEOUT = -2146697205;
  public static final int INET_E_INVALID_REQUEST = -2146697204;
  public static final int INET_E_UNKNOWN_PROTOCOL = -2146697203;
  public static final int INET_E_SECURITY_PROBLEM = -2146697202;
  public static final int INET_E_CANNOT_LOAD_DATA = -2146697201;
  public static final int INET_E_CANNOT_INSTANTIATE_OBJECT = -2146697200;
  public static final int INET_E_USE_DEFAULT_PROTOCOLHANDLER = -2146697199;
  public static final int INET_E_DEFAULT_ACTION = -2146697199;
  public static final int INET_E_USE_DEFAULT_SETTING = -2146697198;
  public static final int INET_E_QUERYOPTION_UNKNOWN = -2146697197;
  public static final int INET_E_REDIRECTING = -2146697196;
  public static final int INET_E_REDIRECT_FAILED = -2146697196;
  public static final int INET_E_REDIRECT_TO_DIR = -2146697195;
  public static final int INET_E_CANNOT_LOCK_REQUEST = -2146697194;
  public static final int INET_E_USE_EXTEND_BINDING = -2146697193;
  public static final int INET_E_ERROR_FIRST = -2146697214;
  public static final int INET_E_ERROR_LAST = -2146697193;
  public static final int INET_E_CODE_DOWNLOAD_DECLINED = -2146696960;
  public static final int INET_E_RESULT_DISPATCHED = -2146696704;
  public static final int INET_E_CANNOT_REPLACE_SFP_FILE = -2146696448;
  public static final int DISP_E_UNKNOWNINTERFACE = -2147352575;
  public static final int DISP_E_MEMBERNOTFOUND = -2147352573;
  public static final int DISP_E_PARAMNOTFOUND = -2147352572;
  public static final int DISP_E_TYPEMISMATCH = -2147352571;
  public static final int DISP_E_UNKNOWNNAME = -2147352570;
  public static final int DISP_E_NONAMEDARGS = -2147352569;
  public static final int DISP_E_BADVARTYPE = -2147352568;
  public static final int DISP_E_EXCEPTION = -2147352567;
  public static final int DISP_E_OVERFLOW = -2147352566;
  public static final int DISP_E_BADINDEX = -2147352565;
  public static final int DISP_E_UNKNOWNLCID = -2147352564;
  public static final int DISP_E_ARRAYISLOCKED = -2147352563;
  public static final int DISP_E_BADPARAMCOUNT = -2147352562;
  public static final int DISP_E_PARAMNOTOPTIONAL = -2147352561;
  public static final int DISP_E_BADCALLEE = -2147352560;
  public static final int DISP_E_NOTACOLLECTION = -2147352559;
  public static final int DISP_E_DIVBYZERO = -2147352558;
  public static final int CO_E_NOTINITIALIZED = -2147221008;
  public static final int CO_E_ALREADYINITIALIZED = -2147221007;
  public static final int CO_E_CANTDETERMINECLASS = -2147221006;
  public static final int CO_E_CLASSSTRING = -2147221005;
  public static final int CO_E_IIDSTRING = -2147221004;
  public static final int CO_E_APPNOTFOUND = -2147221003;
  public static final int CO_E_APPSINGLEUSE = -2147221002;
  public static final int CO_E_ERRORINAPP = -2147221001;
  public static final int CO_E_DLLNOTFOUND = -2147221000;
  public static final int CO_E_ERRORINDLL = -2147220999;
  public static final int CO_E_WRONGOSFORAPP = -2147220998;
  public static final int CO_E_OBJNOTREG = -2147220997;
  public static final int CO_E_OBJISREG = -2147220996;
  public static final int CO_E_OBJNOTCONNECTED = -2147220995;
  public static final int CO_E_APPDIDNTREG = -2147220994;
  public static final int CO_E_RELEASED = -2147220993;
  public static final int RPC_E_DISCONNECTED = -2147417848;
  public static final int RPC_E_SERVERCALL_RETRYLATER = -2147417846;
  public static final int RPC_E_CALL_REJECTED = -2147418111;
  public static final int OLE_E_FIRST = -2147221504;
  public static final int OLE_E_LAST = -2147221249;
  public static final int OLE_S_FIRST = 262144;
  public static final int OLE_S_LAST = 262399;
  public static final int OLE_E_OLEVERB = -2147221504;
  public static final int OLE_E_ADVF = -2147221503;
  public static final int OLE_E_ENUM_NOMORE = -2147221502;
  public static final int OLE_E_ADVISENOTSUPPORTED = -2147221501;
  public static final int OLE_E_NOCONNECTION = -2147221500;
  public static final int OLE_E_NOTRUNNING = -2147221499;
  public static final int OLE_E_NOCACHE = -2147221498;
  public static final int OLE_E_BLANK = -2147221497;
  public static final int OLE_E_CLASSDIFF = -2147221496;
  public static final int OLE_E_CANT_GETMONIKER = -2147221495;
  public static final int OLE_E_CANT_BINDTOSOURCE = -2147221494;
  public static final int OLE_E_STATIC = -2147221493;
  public static final int OLE_E_PROMPTSAVECANCELLED = -2147221492;
  public static final int OLE_E_INVALIDRECT = -2147221491;
  public static final int OLE_E_WRONGCOMPOBJ = -2147221490;
  public static final int OLE_E_INVALIDHWND = -2147221489;
  public static final int OLE_E_NOT_INPLACEACTIVE = -2147221488;
  public static final int OLE_E_CANTCONVERT = -2147221487;
  public static final int OLE_E_NOSTORAGE = -2147221486;
  public static final int REGDB_E_CLASSNOTREG = -2147221164;
  public static final int REGDB_E_IIDNOTREG = -2147221163;
  public static final int OLECMDERR_E_FIRST = -2147221248;
  public static final int OLECMDERR_E_NOTSUPPORTED = -2147221248;
  public static final int OLECMDERR_E_UNKNOWNGROUP = -2147221244;
  private static Map _namesMap = null;
  private static final Logger LOG = Logger.getInstance(HResult.class);
  
  public HResult() {}
  
  public HResult(int value)
  {
    super(value);
  }
  
  public HResult(IntegerParameter value)
  {
    super(value);
  }
  
  public HResult(short severity, short facility, boolean isError)
  {
    super((int)(severity & 0xFFFF | (facility & 0x1FFF) << 16 | (isError ? 1L : 0L) << 31));
  }
  
  public short getSCode()
  {
    return (short)(int)(getValue() & 0xFFFF);
  }
  
  public short getFacility()
  {
    return (short)(int)(getValue() >> 16 & 0x1FFF);
  }
  
  public boolean isError()
  {
    return (getValue() & 0x80000000) != 0L;
  }
  
  public Object clone()
  {
    return new HResult(this);
  }
  
  private static Map getNamesMap()
  {
    if (_namesMap == null) {
      try
      {
        _namesMap = new HashMap();
        Field[] declaredFields = HResult.class.getDeclaredFields();
        for (int i = 0; i < declaredFields.length; i++)
        {
          Field field = declaredFields[i];
          field.setAccessible(true);
          if ((Integer.TYPE.equals(field.getType())) && ((field.getModifiers() & 0x10) != 0)) {
            _namesMap.put(new Integer(field.getInt(null)), field.getName());
          }
        }
      }
      catch (Exception e)
      {
        LOG.error("", e);
        return Collections.EMPTY_MAP;
      }
    }
    return _namesMap;
  }
  
  public static String decodeHResult(int hResult)
  {
    String name = (String)getNamesMap().get(new Integer(hResult));
    String desc = LastError.getMessage(hResult);
    if (name != null)
    {
      if ((desc != null) && (!desc.equals(""))) {
        return name + " (" + desc + ")";
      }
      return name;
    }
    return desc != null ? desc : "";
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.HResult
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Bool;
import com.jniwrapper.Function;
import com.jniwrapper.Pointer.Void;
import com.jniwrapper.UInt32;
import com.jniwrapper.win32.system.Kernel32;

public class Handle
  extends Pointer.Void
{
  private static final String FUNCTION_CloseHandle = "CloseHandle";
  private static final String FUNCTION_WaitForSingleObject = "WaitForSingleObject";
  public static final int INFINITE_TIMEOUT = -1;
  public static final int STATUS_WAIT_0 = 0;
  public static final int STATUS_ABANDONED_WAIT_0 = 128;
  public static final int STATUS_TIMEOUT = 258;
  public static final int INVALID_HANDLE_VALUE = -1;
  
  public Handle() {}
  
  public Handle(long value)
  {
    super(value);
  }
  
  public Object clone()
  {
    return new Handle(getValue());
  }
  
  public boolean equals(Object obj)
  {
    if ((obj == null) || (!(obj instanceof Handle))) {
      return false;
    }
    Handle anotherHandle = (Handle)obj;
    return getValue() == anotherHandle.getValue();
  }
  
  public static long waitFor(Handle handle, long timeout)
  {
    Function function = Kernel32.getInstance().getFunction("WaitForSingleObject");
    UInt32 waitStatus = new UInt32();
    function.invoke(waitStatus, handle, new UInt32(timeout));
    return waitStatus.getValue();
  }
  
  public static long waitFor(Handle handle)
  {
    return waitFor(handle, -1L);
  }
  
  public static boolean closeHandle(Handle handle)
  {
    if ((handle == null) || (handle.isNull())) {
      throw new IllegalArgumentException();
    }
    Function function = Kernel32.getInstance().getFunction("CloseHandle");
    Bool functionResult = new Bool();
    function.invoke(functionResult, handle);
    return functionResult.getValue();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.Handle
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Pointer.Void;

public class IntPtr
  extends Pointer.Void
{
  public IntPtr() {}
  
  public IntPtr(long value)
  {
    super(value);
  }
  
  public Object clone()
  {
    return new IntPtr(getValue());
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.IntPtr
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Function;
import com.jniwrapper.Int32;
import com.jniwrapper.Parameter;
import com.jniwrapper.Pointer;
import com.jniwrapper.Pointer.Void;
import com.jniwrapper.Str;
import com.jniwrapper.UInt32;
import com.jniwrapper.win32.system.Kernel32;

public class LastError
{
  public static final int NO_ERROR = 0;
  public static final int ERROR_SUCCESS = 0;
  private static final String FUNCTION_GET_LAST_ERROR = "GetLastError";
  private static final String FUNCTION_SET_LAST_ERROR = "SetLastError";
  private static final int FORMAT_MESSAGE_IGNORE_INSERTS = 512;
  private static final int FORMAT_MESSAGE_FROM_SYSTEM = 4096;
  private static final int FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192;
  
  /**
   * @deprecated
   */
  public static int getValue()
  {
    Function getLastError = Kernel32.getInstance().getFunction("GetLastError");
    Int32 errorCode = new Int32();
    getLastError.invoke(errorCode);
    return (int)errorCode.getValue();
  }
  
  /**
   * @deprecated
   */
  public static int getValue(boolean clear)
  {
    int result = getValue();
    if (clear) {
      clearLastErrorCode();
    }
    return result;
  }
  
  public static void clearLastErrorCode()
  {
    setValue(0);
  }
  
  public static void setValue(int value)
  {
    Function setLastError = Kernel32.getInstance().getFunction("SetLastError");
    Int32 errorCode = new Int32(value);
    setLastError.invoke(null, errorCode);
  }
  
  /**
   * @deprecated
   */
  public static String getMessage()
  {
    return getMessage(getValue());
  }
  
  /**
   * @deprecated
   */
  public static String getMessage(boolean clearStatus)
  {
    int lastError = getValue(clearStatus);
    return getMessage(lastError);
  }
  
  public static String getMessage(long errorCode)
  {
    FunctionName FUNCTION_FORMAT_MESSAGE = new FunctionName("FormatMessage");
    
    Function formatMessage = Kernel32.getInstance().getFunction(FUNCTION_FORMAT_MESSAGE.toString());
    UInt32 dwFlags = new UInt32(12800L);
    
    Pointer.Void NULL = new Pointer.Void();
    Str buffer = new Str("", 255);
    
    UInt32 result = new UInt32();
    
    UInt32 errCode = new UInt32(errorCode);
    formatMessage.invoke(result, new Parameter[] { dwFlags, NULL, errCode, new UInt32(0L), new Pointer(buffer), new UInt32(buffer.getMaxLength()), NULL });
    
    return buffer.getValue().trim();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.LastError
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

public class LastErrorException
  extends RuntimeException
{
  private long _errorCode;
  
  /**
   * @deprecated
   */
  public LastErrorException()
  {
    _errorCode = LastError.getValue();
  }
  
  public LastErrorException(long errorCode)
  {
    _errorCode = errorCode;
  }
  
  /**
   * @deprecated
   */
  public LastErrorException(String message)
  {
    super(message);
    _errorCode = LastError.getValue();
  }
  
  public LastErrorException(long errorCode, String message)
  {
    super(message);
    _errorCode = errorCode;
  }
  
  /**
   * @deprecated
   */
  public LastErrorException(String message, boolean clearError)
  {
    super(message);
    _errorCode = LastError.getValue();
    if (clearError) {
      LastError.clearLastErrorCode();
    }
  }
  
  public LastErrorException(long errorCode, String message, boolean clearError)
  {
    super(message);
    _errorCode = errorCode;
    if (clearError) {
      LastError.clearLastErrorCode();
    }
  }
  
  /**
   * @deprecated
   */
  public LastErrorException(Throwable cause)
  {
    super(cause.getMessage());
    _errorCode = LastError.getValue();
  }
  
  public LastErrorException(long errorCode, Throwable cause)
  {
    super(cause.getMessage());
    _errorCode = errorCode;
  }
  
  public LastErrorException(String message, Throwable cause)
  {
    super(message, cause);
  }
  
  public long getErrorCode()
  {
    return _errorCode;
  }
  
  public String getErrorMessage()
  {
    return LastError.getMessage(getErrorCode());
  }
  
  public String getMessage()
  {
    String detailsMessage = super.getMessage();
    if ((detailsMessage == null) || (detailsMessage.length() == 0)) {
      return getErrorMessage();
    }
    return detailsMessage + " " + getErrorMessage();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.LastErrorException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import java.util.EventListener;

public abstract interface MessageLoopListener
  extends EventListener
{
  public abstract boolean onMessage(Msg paramMsg);
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

class MessageLoopThread$1
  implements Runnable
{
  private final MessageLoopThread this$0;
  
  MessageLoopThread$1(MessageLoopThread this$0)
  {
    this.this$0 = this$0;
  }
  
  public void run()
  {
    this$0.doStop();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

class MessageLoopThread$2
  implements Runnable
{
  private final MessageLoopThread this$0;
  
  MessageLoopThread$2(MessageLoopThread this$0)
  {
    this.this$0 = this$0;
  }
  
  public void run()
  {
    MessageLoopThread.access$100(this$0);
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Function;
import com.jniwrapper.IntBool;
import com.jniwrapper.Parameter;
import com.jniwrapper.Pointer;
import com.jniwrapper.ShortInt;
import com.jniwrapper.UInt;
import com.jniwrapper.UInt32;
import com.jniwrapper.util.Logger;
import com.jniwrapper.win32.system.EventObject;
import java.util.Iterator;
import java.util.List;

class MessageLoopThread$LoopThread
  extends Thread
{
  private static final int ERROR_NOT_ENOUGH_QUOTA = 1816;
  private EventObject _messageQueueIsReady;
  private long _threadID;
  private boolean _running;
  private final MessageLoopThread this$0;
  
  MessageLoopThread$LoopThread(MessageLoopThread this$0)
  {
    this(this$0, (MessageLoopThread.class$com$jniwrapper$win32$MessageLoopThread == null ? (MessageLoopThread.class$com$jniwrapper$win32$MessageLoopThread = MessageLoopThread.class$("com.jniwrapper.win32.MessageLoopThread")) : MessageLoopThread.class$com$jniwrapper$win32$MessageLoopThread).getName(), true);
  }
  
  MessageLoopThread$LoopThread(MessageLoopThread this$0, String name, boolean daemon)
  {
    this.this$0 = this$0;
    setName(name);
    setPriority(5);
    setDaemon(daemon);
    _messageQueueIsReady = new EventObject("MessageQueueIsReady." + MessageLoopThread.access$208());
  }
  
  /**
   * @deprecated
   */
  public void postThreadMessage(int message, int wParam, int lParam)
  {
    postThreadMessage(message, wParam, lParam);
  }
  
  public void postThreadMessage(int message, long wParam, long lParam)
  {
    _messageQueueIsReady.waitFor();
    IntBool result = new IntBool();
    long errorCode = MessageLoopThread.access$300().invoke(result, new Parameter[] { new UInt32(_threadID), new UInt(message), new IntPtr(wParam), new IntPtr(lParam) });
    if (result.getValue() == 0L) {
      if (errorCode == 1816L) {
        MessageLoopThread._log.debug("Failed to post the message to the thread due to quota limit. ThreadID = " + _threadID);
      } else {
        MessageLoopThread._log.error("Failed to post the message to the thread. ThreadID = " + _threadID + ", errorCode = " + errorCode, new LastErrorException(errorCode));
      }
    }
  }
  
  public long getThreadID()
  {
    return _threadID;
  }
  
  private boolean notifyListeners(Msg msg)
  {
    boolean isProcessed = false;
    Iterator i;
    synchronized (MessageLoopThread.access$400(this$0))
    {
      for (i = MessageLoopThread.access$400(this$0).iterator(); i.hasNext();)
      {
        MessageLoopListener listener = (MessageLoopListener)i.next();
        if (listener.onMessage(msg)) {
          isProcessed = true;
        }
      }
    }
    return isProcessed;
  }
  
  public void stopThread()
  {
    _running = false;
    this$0.pingMessageLoopThread();
  }
  
  void pingThread()
  {
    this$0.postSyncThreadMessage(1024, 0L, 0L);
  }
  
  public void run()
  {
    MessageLoopThread._log.debug("MessageLoopThread.run()");
    
    this$0.onStart();
    
    UInt32 threadID = new UInt32();
    MessageLoopThread.access$500().invoke(threadID);
    _threadID = threadID.getValue();
    MessageLoopThread._log.debug("MessageLoopThread.run(): got threadID = " + _threadID);
    
    Handle wnd = new Handle();
    
    ShortInt result = new ShortInt();
    Msg msg = new Msg();
    Pointer msgPointer = new Pointer(msg);
    UInt32 nullValue = new UInt32();
    
    MessageLoopThread.access$600().invoke(result, new Parameter[] { msgPointer, wnd, new UInt32(1024L), new UInt32(1024L), new UInt32(0L) });
    try
    {
      Thread.sleep(100L);
    }
    catch (InterruptedException e)
    {
      MessageLoopThread._log.error("", e);
    }
    _messageQueueIsReady.notifyEvent();
    
    MessageLoopThread._log.debug("MessageLoopThread.run(), messageQueueIsReady");
    result.setValue(1L);
    _running = true;
    while ((_running) && (result.getValue() != 0L))
    {
      MessageLoopThread.access$702(this$0, false);
      
      MessageLoopThread.access$800().invoke(result, msgPointer, wnd, nullValue, nullValue);
      if (result.getValue() == -1L) {
        break;
      }
      boolean isProcessed = notifyListeners(msg);
      if (!isProcessed)
      {
        MessageLoopThread.access$900().invoke(null, msgPointer);
        try
        {
          MessageLoopThread.access$1000().invoke(null, msgPointer);
        }
        catch (Throwable e)
        {
          String stringMessage = "Unexpected runtime error has occured in the \"" + getName() + "\" thread during message dispatching.";
          
          MessageLoopThread._log.error(stringMessage, e);
        }
      }
      MessageLoopThread.access$702(this$0, true);
      while (!MessageLoopThread.access$1100(this$0).isEmpty())
      {
        MessageLoopThread.ThreadAction action = (MessageLoopThread.ThreadAction)MessageLoopThread.access$1100(this$0).remove(0);
        if ((action instanceof MessageLoopThread.ThreadSynchronizedAction))
        {
          MessageLoopThread.ThreadSynchronizedAction synchronizedAction = (MessageLoopThread.ThreadSynchronizedAction)action;
          synchronized (_lock)
          {
            try
            {
              synchronizedAction.run();
            }
            finally
            {
              ((boolean[])_lock)[0] = 1;
              _lock.notify();
            }
          }
        }
        else
        {
          try
          {
            action.run();
          }
          catch (Exception e)
          {
            MessageLoopThread._log.error("Failed to execute an asynchronous action in the MessageLoopThread.", e);
          }
        }
      }
    }
    _messageQueueIsReady.close();
    
    this$0.onStop();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.LoopThread
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import java.lang.reflect.Method;

class MessageLoopThread$MethodInvocationAction
  extends MessageLoopThread.ThreadSynchronizedAction
{
  private Object _object;
  private Method _method;
  private Object[] _parameters;
  private Object _result;
  
  MessageLoopThread$MethodInvocationAction(Object object, String methodName, Object[] parameters)
  {
    super(null, null);
    
    _object = object;
    _parameters = (parameters == null ? new Object[0] : parameters);
    
    Class[] argumentClasses = parameters == null ? null : new Class[_parameters.length];
    if (argumentClasses != null) {
      for (int i = 0; i < _parameters.length; i++) {
        argumentClasses[i] = _parameters[i].getClass();
      }
    }
    try
    {
      _method = object.getClass().getMethod(methodName, argumentClasses);
    }
    catch (Exception e)
    {
      _exception = e;
      
      _method = findMethod(object, methodName, argumentClasses);
      if (_method != null) {
        _exception = null;
      }
    }
  }
  
  private Method findMethod(Object object, String methodName, Class[] argumentClasses)
  {
    Method[] methods = object.getClass().getMethods();
    for (int i = 0; i < methods.length; i++)
    {
      Method method = methods[i];
      if (method.getName().equals(methodName))
      {
        Class[] parameterTypes = method.getParameterTypes();
        if ((argumentClasses != null) && (parameterTypes.length == argumentClasses.length))
        {
          boolean parametersMatched = true;
          for (int j = 0; j < parameterTypes.length; j++) {
            if (!parameterTypes[j].isAssignableFrom(argumentClasses[j]))
            {
              parametersMatched = false;
              break;
            }
          }
          if (parametersMatched) {
            return method;
          }
        }
      }
    }
    return null;
  }
  
  public void run()
  {
    if (_exception != null) {
      return;
    }
    try
    {
      _method.setAccessible(true);
      _result = _method.invoke(_object, _parameters);
    }
    catch (Exception e)
    {
      _exception = e;
    }
  }
  
  public Object getResult()
  {
    return _result;
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.MethodInvocationAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

class MessageLoopThread$ThreadAction
  implements Runnable
{
  protected Runnable _action;
  
  MessageLoopThread$ThreadAction(Runnable action)
  {
    _action = action;
  }
  
  public void run()
  {
    _action.run();
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.ThreadAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import java.lang.reflect.InvocationTargetException;

class MessageLoopThread$ThreadSynchronizedAction
  extends MessageLoopThread.ThreadAction
{
  protected Exception _exception;
  protected Object _lock;
  
  MessageLoopThread$ThreadSynchronizedAction(Object lock, Runnable action)
  {
    super(action);
    _lock = lock;
  }
  
  public void run()
  {
    try
    {
      _action.run();
    }
    catch (Exception e)
    {
      _exception = e;
    }
  }
  
  public Exception getException()
  {
    return _exception;
  }
  
  public void rethrowExceptionIfSaved()
    throws InvocationTargetException
  {
    Exception exception = getException();
    if (exception != null)
    {
      if ((exception instanceof InvocationTargetException)) {
        throw ((InvocationTargetException)exception);
      }
      throw new InvocationTargetException(exception);
    }
  }
}

/* Location:
 * Qualified Name:     com.jniwrapper.win32.MessageLoopThread.ThreadSynchronizedAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.jniwrapper.win32;

import com.jniwrapper.Function;
import com.jniwrapper.IntBool;
import com.jniwrapper.NativeResourceCollector;
import com.jniwrapper.Parameter;
import com.jniwrapper.Pointer;
import com.jniwrapper.ShortInt;
import com.jniwrapper.UInt;
import com.jniwrapper.UInt32;
import com.jniwrapper.util.Logger;
import com.jniwrapper.win32.system.EventObject;
import com.jniwrapper.win32.system.Kernel32;
import com.jniwrapper.win32.ui.User32;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class MessageLoopThread
{
  protected static final Logger _log = Logger.getInstance(MessageLoopThread.class);
  private static final FunctionName FUNCTION_GetMessage = new FunctionName("GetMessage");
  private static final FunctionName FUNCTION_PeekMessage = new FunctionName("PeekMessage");
  private static final FunctionName FUNCTION_DispatchMessage = new FunctionName("DispatchMessage");
  private static final FunctionName FUNCTION_PostThreadMessage = new FunctionName("PostThreadMessage");
  private static int _threadIndex = 1;
  private boolean _daemon = true;
  
  static
  {
    User32 user32 = User32.getInstance();
    _peekMessageFunction = user32.getFunction(FUNCTION_PeekMessage.toString());
    _getMessageFunction = user32.getFunction(FUNCTION_GetMessage.toString());
    _translateMessage = user32.getFunction("TranslateMessage");
    _dispatchMessage = user32.getFunction(FUNCTION_DispatchMessage.toString());
    _postThreadMessageFunction = user32.getFunction(FUNCTION_PostThreadMessage.toString());
  }
  
  private static Function _getCurrentThreadId = Kernel32.getInstance().getFunction("GetCurrentThreadId");
  private List _actionsQueue = Collections.synchronizedList(new LinkedList());
  private List _messageListeners = new LinkedList();
  private static Map _messageLoops = new HashMap();
  private static final String FUNCTION_TranslateMessage = "TranslateMessage";
  private static final String FUNCTION_GetCurrentThreadId = "GetCurrentThreadId";
  private static final int PM_NOREMOVE = 0;
  private static Function _getMessageFunction;
  private static Function _peekMessageFunction;
  private static Function _translateMessage;
  private static Function _dispatchMessage;
  private static Function _postThreadMessageFunction;
  private String _name;
  private boolean _processing;
  private boolean _isRunning;
  private LoopThread _messageLoopThread;
  private final Runnable _shutDownAction;
  
  public MessageLoopThread()
  {
    this("Main message loop");
  }
  
  public MessageLoopThread(String name)
  {
    this(name, true);
  }
  
  public MessageLoopThread(boolean daemon)
  {
    this("Main message loop", daemon);
  }
  
  public MessageLoopThread(String name, boolean daemon)
  {
    _name = name;
    _daemon = daemon;
    _shutDownAction = new Runnable()
    {
      public void run()
      {
        doStop();
      }
    };
  }
  
  private static void put(Thread thread, MessageLoopThread loop)
  {
    _messageLoops.put(thread, loop);
  }
  
  private static void remove(Thread thread)
  {
    _messageLoops.remove(thread);
  }
  
  protected static Map getMessageLoops()
  {
    return _messageLoops;
  }
  
  public synchronized void doStart()
  {
    if (_messageLoopThread == null)
    {
      _messageLoopThread = new LoopThread(_name, _daemon);
      put(_messageLoopThread, this);
    }
    if (_messageLoopThread.isAlive()) {
      return;
    }
    _messageLoopThread.start();
    for (;;)
    {
      if (!(_isRunning = _messageLoopThread._running)) {
        try
        {
          Thread.sleep(10L);
        }
        catch (InterruptedException e) {}
      }
    }
    NativeResourceCollector.getInstance().addShutdownAction(_shutDownAction);
  }
  
  public synchronized void doStop()
  {
    if ((_messageLoopThread == null) || (!_isRunning)) {
      return;
    }
    _isRunning = false;
    if (isDispatchThread())
    {
      _log.debug("Detected calling of the doStop() method in dispatch thread of '" + getName() + "' message loop");
      new Thread(new Runnable()
      {
        public void run()
        {
          MessageLoopThread.this.terminateThread();
        }
      }).start();
    }
    else
    {
      terminateThread();
    }
  }
  
  public String getName()
  {
    return _name;
  }
  
  private void terminateThread()
  {
    try
    {
      _messageLoopThread.stopThread();
      _messageLoopThread.join();
      remove(_messageLoopThread);
      _messageLoopThread = null;
      
      _actionsQueue.clear();
      NativeResourceCollector.getInstance().removeShutdownAction(_shutDownAction);
    }
    catch (InterruptedException e)
    {
      _log.error("", e);
      _isRunning = _messageLoopThread.isAlive();
    }
    _log.debug("Terminated thread " + getName());
  }
  
  public boolean isStarted()
  {
    return _isRunning;
  }
  
  public synchronized boolean isDispatchThread()
  {
    return Thread.currentThread() == _messageLoopThread;
  }
  
  public void doInvokeAndWait(Runnable action)
    throws InterruptedException, InvocationTargetException
  {
    checkRunning();
    if (isDispatchThread())
    {
      try
      {
        action.run();
      }
      catch (Exception e)
      {
        throw new InvocationTargetException(e);
      }
    }
    else
    {
      boolean[] lock = new boolean[1];
      ThreadSynchronizedAction synchronizedAction;
      if ((action instanceof MethodInvocationAction))
      {
        ThreadSynchronizedAction synchronizedAction = (ThreadSynchronizedAction)action;
        _lock = lock;
      }
      else
      {
        synchronizedAction = new ThreadSynchronizedAction(lock, action);
      }
      synchronized (lock)
      {
        _actionsQueue.add(synchronizedAction);
        pingMessageLoopThread();
        int cycleCount = 0;
        while (lock[0] == 0)
        {
          cycleCount++;
          lock.wait(0L, 1);
          if (cycleCount % 100 == 0) {
            pingMessageLoopThread();
          }
        }
      }
      synchronizedAction.rethrowExceptionIfSaved();
    }
  }
  
  protected synchronized void pingMessageLoopThread()
  {
    if (_messageLoopThread != null) {
      _messageLoopThread.pingThread();
    }
  }
  
  public void doInvokeLater(Runnable action)
  {
    checkRunning();
    ThreadAction threadAction = new ThreadAction(action);
    _actionsQueue.add(threadAction);
    if (!_processing) {
      pingMessageLoopThread();
    }
  }
  
  private void checkRunning()
  {
    if (!_isRunning) {
      throw new IllegalStateException(_name + " thread is already stopped.");
    }
  }
  
  public Object doInvokeMethod(Object object, String methodName)
    throws InterruptedException, InvocationTargetException
  {
    return doInvokeMethod(object, methodName, null);
  }
  
  public Object doInvokeMethod(Object object, String methodName, Object[] parameters)
    throws InterruptedException, InvocationTargetException
  {
    MethodInvocationAction action = new MethodInvocationAction(object, methodName, parameters);
    doInvokeAndWait(action);
    
    action.rethrowExceptionIfSaved();
    
    return action.getResult();
  }
  
  public void doAddMessageListener(MessageLoopListener listener)
  {
    synchronized (_messageListeners)
    {
      if (!_messageListeners.contains(listener)) {
        _messageListeners.add(listener);
      }
    }
  }
  
  public void doRemoveMessageListener(MessageLoopListener listener)
  {
    synchronized (_messageListeners)
    {
      _messageListeners.remove(listener);
    }
  }
  
  /**
   * @deprecated
   */
  protected synchronized void postSyncThreadMessage(int message, int wParam, int lParam)
  {
    postSyncThreadMessage(message, wParam, lParam);
  }
  
  protected synchronized void postSyncThreadMessage(int message, long wParam, long lParam)
  {
    if (_messageLoopThread != null) {
      _messageLoopThread.postThreadMessage(message, wParam, lParam);
    }
  }
  
  protected void onStart() {}
  
  protected void onStop() {}
  
  private class LoopThread
    extends Thread
  {
    private static final int ERROR_NOT_ENOUGH_QUOTA = 1816;
    private EventObject _messageQueueIsReady;
    private long _threadID;
    private boolean _running;
    
    LoopThread()
    {
      this(MessageLoopThread.class.getName(), true);
    }
    
    LoopThread(String name, boolean daemon)
    {
      setName(name);
      setPriority(5);
      setDaemon(daemon);
      _messageQueueIsReady = new EventObject("MessageQueueIsReady." + MessageLoopThread.access$208());
    }
    
    /**
     * @deprecated
     */
    public void postThreadMessage(int message, int wParam, int lParam)
    {
      postThreadMessage(message, wParam, lParam);
    }
    
    public void postThreadMessage(int message, long wParam, long lParam)
    {
      _messageQueueIsReady.waitFor();
      IntBool result = new IntBool();
      long errorCode = MessageLoopThread._postThreadMessageFunction.invoke(result, new Parameter[] { new UInt32(_threadID), new UInt(message), new IntPtr(wParam), new IntPtr(lParam) });
      if (result.getValue() == 0L) {
        if (errorCode == 1816L) {
          MessageLoopThread._log.debug("Failed to post the message to the thread due to quota limit. ThreadID = " + _threadID);
        } else {
          MessageLoopThread._log.error("Failed to post the message to the thread. ThreadID = " + _threadID + ", errorCode = " + errorCode, new LastErrorException(errorCode));
        }
      }
    }
    
    public long getThreadID()
    {
      return _threadID;
    }
    
    private boolean notifyListeners(Msg msg)
    {
      boolean isProcessed = false;
      Iterator i;
      synchronized (_messageListeners)
      {
        for (i = _messageListeners.iterator(); i.hasNext();)
        {
          MessageLoopListener listener = (MessageLoopListener)i.next();
          if (listener.onMessage(msg)) {
            isProcessed = true;
          }
        }
      }
      return isProcessed;
    }
    
    public void stopThread()
    {
      _running = false;
      pingMessageLoopThread();
    }
    
    void pingThread()
    {
      postSyncThreadMessage(1024, 0L, 0L);
    }
    
    public void run()
    {
      MessageLoopThread._log.debug("MessageLoopThread.run()");
      
      onStart();
      
      UInt32 threadID = new UInt32();
      MessageLoopThread._getCurrentThreadId.invoke(threadID);
      _threadID = threadID.getValue();
      MessageLoopThread._log.debug("MessageLoopThread.run(): got threadID = " + _threadID);
      
      Handle wnd = new Handle();
      
      ShortInt result = new ShortInt();
      Msg msg = new Msg();
      Pointer msgPointer = new Pointer(msg);
      UInt32 nullValue = new UInt32();
      
      MessageLoopThread._peekMessageFunction.invoke(result, new Parameter[] { msgPointer, wnd, new UInt32(1024L), new UInt32(1024L), new UInt32(0L) });
      try
      {
        Thread.sleep(100L);
      }
      catch (InterruptedException e)
      {
        MessageLoopThread._log.error("", e);
      }
      _messageQueueIsReady.notifyEvent();
      
      MessageLoopThread._log.debug("MessageLoopThread.run(), messageQueueIsReady");
      result.setValue(1L);
      _running = true;
      while ((_running) && (result.getValue() != 0L))
      {
        _processing = false;
        
        MessageLoopThread._getMessageFunction.invoke(result, msgPointer, wnd, nullValue, nullValue);
        if (result.getValue() == -1L) {
          break;
        }
        boolean isProcessed = notifyListeners(msg);
        if (!isProcessed)
        {
          MessageLoopThread._translateMessage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd