All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.boot.natives.Pipes Maven / Gradle / Ivy

There is a newer version: 1.16.0
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * @(#) $Id: Pipes.java 2084 2007-11-27 14:53:31Z s3460 $
 */
package at.spardat.xma.boot.natives;

/**
 * @author s3460
 * @since version_number
 * Class with native static Methods wrapping JNI Calls to the WIN32-API (Pipe Functions).
 */
public class Pipes {

    /**
     * any process (for AllowSetForegroundWindow)
     * private static final int ASFW_ANY = -1;
     */

    static {
        System.loadLibrary("natives");
    }

    /**
     * The CreateNamedPipe function creates an instance of a named pipe
     * and returns a handle for subsequent pipe operations.
     * A named pipe server process uses this function either to create the first instance
     * of a specific named pipe and establish its basic attributes or
     * to create a new instance of an existing named pipe.
     * @param lpName
     * @param dwOpenMode
     * @param dwPipeMode
     * @param nMaxInstances Maximum number of instances that can be created for this pipe. range 1 through PIPE_UNLIMITED_INSTANCES (255).
     * @param nOutBufferSize Number of bytes to reserve for the output buffer.
     * @param nInBufferSize Number of bytes to reserve for the input buffer
     * @param nDefaultTimeOut Default time-out value, in milliseconds. NMPWAIT_USE_DEFAULT_WAIT
     * @param lpSecurityAttributes Pointer to a SECURITY_ATTRIBUTES structure.
     * @return INVALID_HANDLE_VALUE if Method fails
     * @since version_number
     * @author s3460
     */
    public static final native int CreateNamedPipe(String lpName,
            int dwOpenMode,
            int dwPipeMode,
            int nMaxInstances,
            int nOutBufferSize,
            int nInBufferSize,
            int nDefaultTimeOut,
            int lpSecurityAttributes);


    /**
     * The ConnectNamedPipe function enables a named pipe server process
     * to wait for a client process to connect to an instance of a named pipe.
     * A client process connects by calling either the
     * CreateFile or CallNamedPipe function.
     * @param hNamedPipe Handle to the server end of a named pipe instance.
     * @param lpOverlapped Pointer to an OVERLAPPED structure.
     * @return true if connection to the pipe was successful, false otherwise
     * @since version_number
     * @author s3460
     */
    public static final native boolean ConnectNamedPipe(
            int hNamedPipe,
            int lpOverlapped);

    /**
     * The GetLastError function retrieves the calling thread's last-error code value.
     * The last-error code is maintained on a per-thread basis.
     * Multiple threads do not overwrite each other's last-error code.
     *
     * @return the last-error code value
     * @since version_number
     * @author s3460
     */
    public static final native int GetLastError();


    /**
     * The CloseHandle function closes an open object handle.
     *
     * @param hObject Handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE
     * @return If the function succeeds, the return value is nonzero.
     * @since version_number
     * @author s3460
     */
    public static final native boolean CloseHandle(int hObject);


    /***
     * The ReadFile function reads data from a file, starting at the position
     * indicated by the file pointer.
     * This function is designed for both synchronous and asynchronous operation.
     * @param hFile
     * @param lpBuffer Pointer to the buffer that receives the data read from the file.
     * @param nNumberOfBytesToRead
     * @param lpNumberOfBytesRead
     * @param lpOverlapped Pointer to an OVERLAPPED structure. This structure is required if hFile was created with FILE_FLAG_OVERLAPPED.
     * @return If the function succeeds, the return value is nonzero.
     * @since version_number
     * @author s3460
     */
    public static final native boolean ReadFile(
            int hFile,
            byte [] lpBuffer,
            int nNumberOfBytesToRead,
            int[] lpNumberOfBytesRead,
            int lpOverlapped);

    /**
     * The WriteFile function writes data to a file at the position specified
     * by the file pointer.
     * This function is designed for both synchronous and asynchronous operation.
     *
     * @param hFile
     * @param lpBuffer Pointer to the buffer containing the data to be written to the file.
     * @param nNumberOfBytesToWrite
     * @param lpNumberOfBytesWritten
     * @param lpOverlapped Pointer to an OVERLAPPED structure. This structure is required if hFile was opened with FILE_FLAG_OVERLAPPED
     * @return true if writing was ok otherwise false.
     * @since version_number
     * @author s3460
     */
    public static final native boolean WriteFile (
            int hFile,
            byte [] lpBuffer,
            int nNumberOfBytesToWrite,
            int[] lpNumberOfBytesWritten,
            int lpOverlapped);

    /**
     * The FlushFileBuffers function flushes the buffers of the specified file
     * and causes all buffered data to be written to the file.
     * @param hFile
     * @return true if ok otherwise false
     * @since version_number
     * @author s3460
     */
    public static final native boolean FlushFileBuffers(int hFile);

    /**
     * The DisconnectNamedPipe function disconnects the server end
     * of a named pipe instance from a client process.
     *
     * @param hNamedPipe
     * @return true if pipe was succesfully closed, false otherwise
     * @since version_number
     * @author s3460
     */
    public static final native boolean DisconnectNamedPipe(int hNamedPipe);




    /**
     * The CreateFile function creates or opens a file, directory, physical disk, volume,
     * console buffer, tape drive, communications resource, mailslot, or named pipe.
     * The function returns a handle that can be used to access the object.
     *
     * @param lpFileName
     * @param dwDesiredAccess
     * @param dwShareMode
     * @param lpSecurityAttributes
     * @param dwCreationDisposition
     * @param dwFlagsAndAttributes
     * @param hTemplateFile
     * @return returns a handle that can be used to access the object
     * @since version_number
     * @author s3460
     */
    public static final native int CreateFile(
            String lpFileName,
            int dwDesiredAccess,
            int dwShareMode,
            int lpSecurityAttributes,
            int dwCreationDisposition,
            int dwFlagsAndAttributes,
            int hTemplateFile
          );



    /**
     * The WaitNamedPipe function waits until either a time-out interval elapses
     * or an instance of the specified named pipe is available for connection
     * (that is, the pipe's server process has a pending ConnectNamedPipe operation
     * on the pipe).
     * If an instance of the pipe is available before the time-out interval elapses,
     * the return value is nonzero.
     * If an instance of the pipe is not available before the time-out interval elapses,
     * the return value is zero. To get extended error information, call GetLastError.
     * Timeout:
     * NMPWAIT_USE_DEFAULT_WAIT 0x00000000
     * NMPWAIT_WAIT_FOREVER 0xffffffff
     * @param lpNamedPipeName
     * @param nTimeOut Number of milliseconds that the function will wait for an instance of the named pipe to be available. You can used one of the following values instead of specifying a number of milliseconds.
     * @return if instance of the pipe is available before the time-out interval the return value is nonzero otherwise zero.
     * @since version_number
     * @author s3460
     */
    public static final native boolean WaitNamedPipe(String lpNamedPipeName, int nTimeOut);

    /**
     * returns Windows Error Message mapped to the errorCode.
     * @param errorCode
     * @return error message
     * @since version_number
     * @author s3460
     */
    public static final native String FormatMessage(int errorCode);

//    /**
//     * The AllowSetForegroundWindow function enables the specified process
//     * to set the foreground window using the SetForegroundWindow function.
//     * The calling process must already be able to set the foreground window.
//     * @param dwProcessId
//     * @return
//     * @since version_number
//     * @author s3460
//     */
//    public static final native boolean AllowSetForegroundWindow(int dwProcessId);
//
//    /**
//     * The AllowSetForegroundWindow function enables any process
//     * to set the foreground window using the SetForegroundWindow function.
//     * The calling process must already be able to set the foreground window.
//     * @return
//     * @since version_number
//     * @author s3460
//     */
//    public static final boolean AllowSetForegroundWindow(){
//        return AllowSetForegroundWindow(ASFW_ANY);
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy