Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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(s):
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.

Parameters:
lpName
dwOpenMode
dwPipeMode
nMaxInstances Maximum number of instances that can be created for this pipe. range 1 through PIPE_UNLIMITED_INSTANCES (255).
nOutBufferSize Number of bytes to reserve for the output buffer.
nInBufferSize Number of bytes to reserve for the input buffer
nDefaultTimeOut Default time-out value, in milliseconds. NMPWAIT_USE_DEFAULT_WAIT
lpSecurityAttributes Pointer to a SECURITY_ATTRIBUTES structure.
Returns:
INVALID_HANDLE_VALUE if Method fails
Author(s):
s3460
Since:
version_number
 
     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.

Parameters:
hNamedPipe Handle to the server end of a named pipe instance.
lpOverlapped Pointer to an OVERLAPPED structure.
Returns:
true if connection to the pipe was successful, false otherwise
Author(s):
s3460
Since:
version_number
 
     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.

Returns:
the last-error code value
Author(s):
s3460
Since:
version_number
 
     public static final native int GetLastError();


    
The CloseHandle function closes an open object handle.

Parameters:
hObject Handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE
Returns:
If the function succeeds, the return value is nonzero.
Author(s):
s3460
Since:
version_number
 
     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.

Parameters:
hFile
lpBuffer Pointer to the buffer that receives the data read from the file.
nNumberOfBytesToRead
lpNumberOfBytesRead
lpOverlapped Pointer to an OVERLAPPED structure. This structure is required if hFile was created with FILE_FLAG_OVERLAPPED.
Returns:
If the function succeeds, the return value is nonzero.
Author(s):
s3460
Since:
version_number
    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.

Parameters:
hFile
lpBuffer Pointer to the buffer containing the data to be written to the file.
nNumberOfBytesToWrite
lpNumberOfBytesWritten
lpOverlapped Pointer to an OVERLAPPED structure. This structure is required if hFile was opened with FILE_FLAG_OVERLAPPED
Returns:
true if writing was ok otherwise false.
Author(s):
s3460
Since:
version_number
    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.

Parameters:
hFile
Returns:
true if ok otherwise false
Author(s):
s3460
Since:
version_number
    public static final native boolean FlushFileBuffers(int hFile);

    
The DisconnectNamedPipe function disconnects the server end of a named pipe instance from a client process.

Parameters:
hNamedPipe
Returns:
true if pipe was succesfully closed, false otherwise
Author(s):
s3460
Since:
version_number
    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.

Parameters:
lpFileName
dwDesiredAccess
dwShareMode
lpSecurityAttributes
dwCreationDisposition
dwFlagsAndAttributes
hTemplateFile
Returns:
returns a handle that can be used to access the object
Author(s):
s3460
Since:
version_number
    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

Parameters:
lpNamedPipeName
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.
Returns:
if instance of the pipe is available before the time-out interval the return value is nonzero otherwise zero.
Author(s):
s3460
Since:
version_number
    public static final native boolean WaitNamedPipe(String lpNamedPipeNameint nTimeOut);

    
returns Windows Error Message mapped to the errorCode.

Parameters:
errorCode
Returns:
error message
Author(s):
s3460
Since:
version_number
    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);
//    }
New to GrepCode? Check out our FAQ X