com.sun.jna.ptr.IntByReference Java Examples

The following examples show how to use com.sun.jna.ptr.IntByReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byId(int id) {
	if ((Platform.isMac() || Platform.isLinux()) && !isSudo()) {
		throw new RuntimeException("You need to run as root/sudo for unix/osx based environments.");
	}
	
	if (Platform.isWindows()) {
		return new Win32Process(id, Kernel32.OpenProcess(0x438, true, id));
	} else if (Platform.isLinux()) {
		return new UnixProcess(id);
	} else if (Platform.isMac()) {
		IntByReference out = new IntByReference();
		if (mac.task_for_pid(mac.mach_task_self(), id, out) != 0) {
			throw new IllegalStateException("Failed to find mach task port for process, ensure you are running as sudo.");
		}
		return new MacProcess(id, out.getValue());
	}
	throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
}
 
Example #2
Source File: NotesACL.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
/**
 * Check if "Enforce consistent ACL" is set
 * 
 * @return true if set
 */
public boolean isUniformAccess() {
	checkHandle();
	
	IntByReference retFlags = new IntByReference();
	
	short result;
	if (PlatformUtils.is64Bit()) {
		result = NotesNativeAPI64.get().ACLGetFlags(m_hACL64, retFlags);
	}
	else {
		result = NotesNativeAPI64.get().ACLGetFlags(m_hACL64, retFlags);
	}
	NotesErrorUtils.checkResult(result);
	
	return (retFlags.getValue() & NotesConstants.ACL_UNIFORM_ACCESS) == NotesConstants.ACL_UNIFORM_ACCESS;
}
 
Example #3
Source File: JnaService.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public byte[] getServiceInfo(ServiceParameterBuffer serviceParameterBuffer,
        ServiceRequestBuffer serviceRequestBuffer, int maxBufferLength) throws SQLException {
    try {
        final byte[] serviceParameterBufferBytes = serviceParameterBuffer == null ? null
                : serviceParameterBuffer.toBytesWithType();
        final byte[] serviceRequestBufferBytes =
                serviceRequestBuffer == null ? null : serviceRequestBuffer.toBytes();
        final ByteBuffer responseBuffer = ByteBuffer.allocateDirect(maxBufferLength);
        synchronized (getSynchronizationObject()) {
            clientLibrary.isc_service_query(statusVector, handle, new IntByReference(0),
                    (short) (serviceParameterBufferBytes != null ? serviceParameterBufferBytes.length
                            : 0), serviceParameterBufferBytes,
                    (short) (serviceRequestBufferBytes != null ? serviceRequestBufferBytes.length
                            : 0), serviceRequestBufferBytes,
                    (short) maxBufferLength, responseBuffer);
            processStatusVector();
        }
        byte[] responseArray = new byte[maxBufferLength];
        responseBuffer.get(responseArray);
        return responseArray;
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
 
Example #4
Source File: INotesNativeAPI64.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
public short CalReadRange(
long hDB,
NotesTimeDateStruct.ByValue tdStart,
NotesTimeDateStruct.ByValue  tdEnd,
int dwViewSkipCount,
int dwMaxReturnCount,
int dwReturnMask,
int dwReturnMaskExt,
Pointer pFilterInfo,
LongByReference hRetCalData,
ShortByReference retCalBufferLength,
LongByReference hRetUIDData,
IntByReference retNumEntriesProcessed,
ShortByReference retSignalFlags,
int dwFlags,
Pointer pCtx);
 
Example #5
Source File: JnaDatabase.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public JnaTransaction startTransaction(final TransactionParameterBuffer tpb) throws SQLException {
    try {
        checkConnected();
        final IntByReference transactionHandle = new IntByReference(0);
        final byte[] tpbArray = tpb.toBytesWithType();
        synchronized (getSynchronizationObject()) {
            clientLibrary.isc_start_transaction(statusVector, transactionHandle, (short) 1, handle,
                    (short) tpbArray.length, tpbArray);
            processStatusVector();

            final JnaTransaction transaction = new JnaTransaction(this, transactionHandle, TransactionState.ACTIVE);
            transactionAdded(transaction);
            return transaction;
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
 
Example #6
Source File: Nc4Iosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String nc_inq_var_name(int grpid, int varno) throws IOException {
  byte[] name = new byte[Nc4prototypes.NC_MAX_NAME + 1];
  IntByReference xtypep = new IntByReference();
  IntByReference ndimsp = new IntByReference();
  IntByReference nattsp = new IntByReference();

  int ret = nc4.nc_inq_var(grpid, varno, name, xtypep, ndimsp, null, nattsp);
  if (ret != 0)
    throw new IOException("nc_inq_var faild: code=" + ret);
  return makeString(name);
}
 
Example #7
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short NSFComputeEvaluate(
int  hCompute,
int hNote,
IntByReference rethResult,
ShortByReference retResultLength,
IntByReference retNoteMatchesFormula,
IntByReference retNoteShouldBeDeleted,
IntByReference retNoteModified);
 
Example #8
Source File: PipeOutputStream.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void write(int b) throws IOException {
    byte[] data = new byte[]{(byte) b};
    IntByReference ibr = new IntByReference();
    boolean result = Kernel32.INSTANCE.WriteFile(pipe, data, data.length, ibr, null);
    if (!result) {
        throw new IOException("Cannot write to the pipe. Error " + Kernel32.INSTANCE.GetLastError());
    }
    if (ibr.getValue() != data.length) {
        throw new IOException("Cannot write to the pipe. Error " + Kernel32.INSTANCE.GetLastError());
    }
}
 
Example #9
Source File: Nc4DSP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Nc4DSP open(String filepath) throws DapException {
  if (filepath.startsWith("file:"))
    try {
      XURI xuri = new XURI(filepath);
      filepath = xuri.getPath();
    } catch (URISyntaxException use) {
      throw new DapException("Malformed filepath: " + filepath).setCode(DapCodes.SC_NOT_FOUND);
    }
  int ret, mode;
  IntByReference ncidp = new IntByReference();
  this.filepath = filepath;
  try {
    mode = NC_NOWRITE;
    Nc4Cursor.errcheck(nc4, ret = nc4.nc_open(this.filepath, mode, ncidp));
    this.ncid = ncidp.getValue();
    // Figure out what kind of file
    IntByReference formatp = new IntByReference();
    Nc4Cursor.errcheck(nc4, ret = nc4.nc_inq_format(ncid, formatp));
    this.format = formatp.getValue();
    if (DEBUG)
      System.out.printf("TestNetcdf: open: %s; ncid=%d; format=%d%n", this.filepath, ncid, this.format);
    // Compile the DMR
    Nc4DMRCompiler dmrcompiler = new Nc4DMRCompiler(this, ncid, dmrfactory);
    setDMR(dmrcompiler.compile());
    if (DEBUG || DUMPDMR) {
      System.err.println("+++++++++++++++++++++");
      System.err.println(printDMR(getDMR()));
      System.err.println("+++++++++++++++++++++");
    }
    return this;
  } catch (Exception t) {
    t.printStackTrace();
  }
  return null;
}
 
Example #10
Source File: WdmDll.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Removes the WDM file at the given fortran unit number
 * from the open WDM buffer and adjust buffer accordingly.
 * For this to work a valid WDM message file must be open.
 *
 * @param wdmFileNumber
 */
public void removeWdmFileFromBuffer(int wdmFileNumber) {
    IntByReference returnCode = new IntByReference(-1);
    nativeDLL.wdflcl_(new IntByReference(wdmFileNumber), returnCode);
    if (returnCode.getValue() != 0) {
        throw new RuntimeException("WdmDll: Invalid result from call to subroutine dll.wdflcl_ , returnCode = " + returnCode.getValue());
    }
}
 
Example #11
Source File: Win32ProcessTools.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public static boolean adjustPrivileges() {

        WinNT.TOKEN_PRIVILEGES tp = new WinNT.TOKEN_PRIVILEGES(1);
        WinNT.TOKEN_PRIVILEGES oldtp = new WinNT.TOKEN_PRIVILEGES(1);
        WinNT.LUID luid = new WinNT.LUID();
        WinNT.HANDLEByReference hTokenRef = new WinNT.HANDLEByReference();
        if (!Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), WinNT.TOKEN_ADJUST_PRIVILEGES | WinNT.TOKEN_QUERY, hTokenRef)) {
            return false;
        }
        WinNT.HANDLE hToken = hTokenRef.getValue();
        if (!Advapi32.INSTANCE.LookupPrivilegeValue(null, WinNT.SE_DEBUG_NAME, luid)) {
            Kernel32.INSTANCE.CloseHandle(hToken);
            return false;
        }

        tp.PrivilegeCount = new WinDef.DWORD(1);
        tp.Privileges = new WinNT.LUID_AND_ATTRIBUTES[1];
        tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new WinDef.DWORD(WinNT.SE_PRIVILEGE_ENABLED));

        IntByReference retSize = new IntByReference(0);
        if (!Advapi32.INSTANCE.AdjustTokenPrivileges(hToken, false, tp, tp.size(), oldtp, retSize)) {
            Kernel32.INSTANCE.CloseHandle(hToken);
            return false;
        }
        Kernel32.INSTANCE.CloseHandle(hToken);
        privAdjusted = true;
        return true;
    }
 
Example #12
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short NSFMimePartCreateStream(
int hNote,
Memory pchItemName,
short wItemNameLen,
short wPartType,
int dwFlags,
IntByReference phCtx);
 
Example #13
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short CalGetNewInvitations(
int hDB,
NotesTimeDateStruct ptdStart,
Memory pszUID,
NotesTimeDateStruct ptdSince,
NotesTimeDateStruct ptdretUntil,
ShortByReference pwNumInvites,
IntByReference phRetNOTEIDs,
IntByReference phRetUNIDs,
Pointer pReserved,
int dwFlags,
Pointer pCtx);
 
Example #14
Source File: TestSensorsLinux.java    From jSensors with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	CSensors INSTANCE = Native.loadLibrary("sensors", CSensors.class);

	System.err.println("Return method: " + INSTANCE.sensors_init(null));

	CChip result;
	int numSensor = 0;
	while ((result = INSTANCE.sensors_get_detected_chips(null, new IntByReference(numSensor))) != null) {
		// System.out.println("Found " + result);
		numSensor++;
		System.out.println("Adapter " + INSTANCE.sensors_get_adapter_name(result.bus));

		CFeature feature;
		int numFeature = 0;
		while ((feature = INSTANCE.sensors_get_features(result, new IntByReference(numFeature))) != null) {
			// System.out.println("Found " + feature);
			numFeature++;

			String label = INSTANCE.sensors_get_label(result, feature);

			CSubFeature subFeature;
			int numSubFeature = 0;
			while ((subFeature = INSTANCE.sensors_get_all_subfeatures(result, feature,
					new IntByReference(numSubFeature))) != null) {
				double value = 0.0;
				DoubleByReference pValue = new DoubleByReference(value);

				int returnValue = INSTANCE.sensors_get_value(result, subFeature.number, pValue);
				System.out.println(label + " feature " + subFeature.name + ": " + pValue.getValue());
				System.out.println(label + "returnValue: " + returnValue);
				System.out.println();

				numSubFeature++;
			}
		}
	}

}
 
Example #15
Source File: Nc4DMRCompiler.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
int[] getVardims(int gid, int vid, int ndims) throws DapException {
  int ret;
  int[] dimids = new int[ndims];

  if (ndims > 0) {
    byte[] namep = new byte[NC_MAX_NAME + 1];
    IntByReference ndimsp = new IntByReference();
    errcheck(ret = nc4.nc_inq_var(gid, vid, null, null, ndimsp, dimids, null));
  }
  return dimids;
}
 
Example #16
Source File: NotesNativeAPI64.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public native short NSFComputeEvaluate(
long  hCompute,
long hNote,
LongByReference rethResult,
ShortByReference retResultLength,
IntByReference retNoteMatchesFormula,
IntByReference retNoteShouldBeDeleted,
IntByReference retNoteModified);
 
Example #17
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short NSFDbNoteLock(
int hDB,
int NoteID,
int Flags,
Memory pLockers,
IntByReference rethLockers,
IntByReference retLength);
 
Example #18
Source File: WdmDll.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int[] getNextValidDate(int[] startDate, int timeUnit, int timeStep, int numberOftimeSteps) {
    int[] nextDate = new int[6];
    Arrays.fill(nextDate, 0);
    nativeDLL.timadd_(startDate, new IntByReference(timeUnit), new IntByReference(timeStep),
            new IntByReference(numberOftimeSteps), nextDate);
    return nextDate;
}
 
Example #19
Source File: NotesNativeAPI64.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public native void NSFItemQueryEx(
long  note_handle,
NotesBlockIdStruct.ByValue item_bid,
Memory item_name,
short  return_buf_len,
ShortByReference name_len_ptr,
ShortByReference item_flags_ptr,
ShortByReference value_datatype_ptr,
NotesBlockIdStruct value_bid_ptr,
IntByReference value_len_ptr,
ByteByReference retSeqByte,
ByteByReference retDupItemID);
 
Example #20
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short MIMEGetDecodedEntityData(
int hNote,
Pointer pMimeEntity,
int dwEncodedOffset,
int dwChunkLen,
IntByReference phData,
IntByReference pdwDecodedDataLen,
IntByReference pdwEncodedDataLen);
 
Example #21
Source File: SimpleModelDLL.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public double getDeltaT() {
    DoubleByReference deltaT = new DoubleByReference();
    int retVal = nativeDLL.m_simple_model_mp_get_delta_t_(deltaT);
    if (retVal != 0) {
        nativeDLL.m_simple_model_mp_finish_(new IntByReference(currentModelInstance));
        throw new RuntimeException("Invalid result from dll.GET_DELTA_T call, retVal= " + retVal);
    }
    return deltaT.getValue();
}
 
Example #22
Source File: Nc4wrapper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public synchronized int nc_inq_enum(int ncid, int xtype, byte[] name, IntByReference baseType,
    SizeTByReference base_sizep, SizeTByReference num_membersp) {
  int ret;
  try {
    ce();
    ret = nc4.nc_inq_enum(ncid, xtype, name, baseType, base_sizep, num_membersp);
    if (TRACE) {
      trace(ret, "nc_inq_enum", ncid, xtype, name, baseType, base_sizep, num_membersp);
    }
  } finally {
    cx();
  }
  return ret;
}
 
Example #23
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short NSFItemInfoNext(
int  note_handle,
NotesBlockIdStruct.ByValue NextItem,
Memory item_name,
short name_len,
NotesBlockIdStruct retbhItem,
ShortByReference retDataType,
NotesBlockIdStruct retbhValue,
IntByReference retValueLength);
 
Example #24
Source File: MemoryBuffer.java    From Spark-Reader with GNU General Public License v3.0 5 votes vote down vote up
public char getChar(int pos)
{
    if(!inRange(pos))
    {
        startPoint = pos;
        endPoint = pos + buffSize;
        IntByReference memoryRead = new IntByReference();
        KernelController.getKernel32().ReadProcessMemory(process, startPoint, memory, buffSize, memoryRead);
        //allRead = memoryRead.getValue() == 0;
        //System.out.println("read: " + memoryRead.getValue());
        //System.out.println();
    }
    return (char)memory.getShort(pos - startPoint);
}
 
Example #25
Source File: NotesNativeAPI64.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public native short NSFDbGetMultNoteInfo(
long  hDb,
short  Count,
short  Options,
long  hInBuf,
IntByReference retSize,
LongByReference rethOutBuf);
 
Example #26
Source File: DXLExporter.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public DXLExporter() {
	IntByReference rethDXLExport = new IntByReference();
	short result = NotesNativeAPI.get().DXLCreateExporter(rethDXLExport);
	NotesErrorUtils.checkResult(result);
	m_hExporter = rethDXLExport.getValue();
	if (m_hExporter==0) {
		throw new NotesError(0, "Failed to allocate DXL exporter");
	}
	NotesGC.__memoryAllocated(this);
}
 
Example #27
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected int setPlatformSocketOption(int sockfd, int level, int optName,
    TCPSocketOptions opt, Integer optVal, int optSize)
    throws NativeErrorException {
  try {
    return setsockopt(sockfd, level, optName,
        new IntByReference(optVal.intValue()), optSize);
  } catch (LastErrorException le) {
    throw new NativeErrorException(le.getMessage(), le.getErrorCode(),
        le.getCause());
  }
}
 
Example #28
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short CalReadEntry(
int hDB,
Memory pszUID,
Memory pszRecurID,
IntByReference hRetCalData,
IntByReference pdwReserved,
int dwFlags,
Pointer pCtx);
 
Example #29
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected int setPlatformSocketOption(int sockfd, int level, int optName,
    TCPSocketOptions opt, Integer optVal, int optSize)
    throws NativeErrorException {
  try {
    return setsockopt(sockfd, level, optName,
        new IntByReference(optVal.intValue()), optSize);
  } catch (LastErrorException le) {
    throw new NativeErrorException(le.getMessage(), le.getErrorCode(),
        le.getCause());
  }
}
 
Example #30
Source File: INotesNativeAPI32.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public short CalReadNotice(
int hDB,
int noteID,
IntByReference hRetCalData,
Pointer pReserved,
int dwFlags,
Pointer pCtx);