Examples of Memory


Examples of com.sun.jna.Memory

            // Memory must be aligned correctly (on a 32-byte boundary) for the libvlc
            // API functions (extra bytes are allocated to allow for enough memory if
            // the alignment needs to be changed)
            nativeBuffers = new Memory[bufferFormat.getPlaneCount()];
            for(int i = 0; i < bufferFormat.getPlaneCount(); i ++ ) {
                nativeBuffers[i] = new Memory(pitchValues[i] * lineValues[i] + 32).align(32);
            }
            Logger.trace("format finished");
            return pitchValues.length;
        }
View Full Code Here

Examples of com.sun.jna.Memory

    check(!INVALID_HANDLE_VALUE.equals(hComm), "CreateFile " + COM);
    String send = "Hello World";
    int tlen = send.getBytes().length;

    int[] txn = { 0 };
    Memory txm = new Memory(tlen + 1);
    txm.clear();
    txm.write(0, send.getBytes(), 0, tlen);

    int[] rxn = { 0 };
    Memory rxm = new Memory(tlen);

    OVERLAPPED osReader = new OVERLAPPED();
    osReader.writeField("hEvent", CreateEventA(null, true, false, null));
    check(osReader.hEvent != null, "CreateEvent/osReader");

    OVERLAPPED osWriter = new OVERLAPPED();
    osWriter.writeField("hEvent", CreateEventA(null, true, false, null));
    check(osWriter.hEvent != null, "CreateEvent/osWriter");

    boolean first = true;

    // First time through here send some stuff
    first = false;
    check(ResetEvent(osWriter.hEvent), "ResetEvent/osWriter.hEvent");
    boolean write = WriteFile(hComm, txm, tlen, txn, osWriter);
    if (!write) {
      check(GetLastError() == ERROR_IO_PENDING, "WriteFile");
      System.out.println("Write pending");
    }
    while (!write) {
      System.out.println("WaitForSingleObject/write");
      int dwRes = WaitForSingleObject(osWriter.hEvent, 1000);
      switch (dwRes) {
        case WAIT_OBJECT_0:
          if (!GetOverlappedResult(hComm, osWriter, txn, true))
            check(GetLastError() == ERROR_IO_INCOMPLETE, "GetOverlappedResult/osWriter");
          else
            write = true;
          break;
        case WAIT_TIMEOUT:
          System.out.println("write TIMEOT");
          break;
        default:
          check(false, "WaitForSingleObject/write");
          break;
      }
    }
    System.out.println("Transmit: '" + txm.getString(0) + "' , len=" + txn[0]);

    // First set up the read so that we actually get some overlap
    check(ResetEvent(osReader.hEvent), "ResetEvent/osReader.hEvent ");
    boolean read = ReadFile(hComm, rxm, tlen, rxn, osReader);
    if (!read) {
      check(GetLastError() == ERROR_IO_PENDING, "ReadFile");
      System.out.println("Read pending");
    }

    while (!read) {
      if (first) {
      }

      System.out.println("WaitForSingleObject/read");
      check(ResetEvent(osReader.hEvent), "ResetEvent/osReader.hEvent");
      int dwRes = WaitForSingleObject(osReader.hEvent, 1000);
      switch (dwRes) {
        case WAIT_OBJECT_0:
          if (!GetOverlappedResult(hComm, osReader, rxn, false))
            check(GetLastError() == ERROR_IO_INCOMPLETE, "GetOverlappedResult/osReader");
          else
            read = true;
          break;

        case WAIT_TIMEOUT:
          System.out.println("WAIT_TIMEOUT");
          break;

        default:
          check(false, "WaitForSingleObject/osReader.hEvent");
          break;
      }
    }

    System.out.println("Received: '" + rxm.getString(0) + "' , len=" + rxn[0]);
    check(CloseHandle(osWriter.hEvent), "CloseHandle/osWriter.hEvent");
    check(CloseHandle(osReader.hEvent), "CloseHandle/osReader.hEvent");
    check(CloseHandle(hComm), "CloseHandle/hComm");
    System.out.println("All done");
  }
View Full Code Here

Examples of com.sun.jna.Memory

                kinfo_proc_ppid_offset = kinfo_proc_ppid_offset_32;
            }
            try {
                IntByReference _ = new IntByReference(sizeOfInt);
                IntByReference size = new IntByReference(sizeOfInt);
                Memory m;
                int nRetry = 0;
                while(true) {
                    // find out how much memory we need to do this
                    if(LIBC.sysctl(MIB_PROC_ALL,3, NULL, size, NULL, _)!=0)
                        throw new IOException("Failed to obtain memory requirement: "+LIBC.strerror(Native.getLastError()));

                    // now try the real call
                    m = new Memory(size.getValue());
                    if(LIBC.sysctl(MIB_PROC_ALL,3, m, size, NULL, _)!=0) {
                        if(Native.getLastError()==ENOMEM && nRetry++<16)
                            continue; // retry
                        throw new IOException("Failed to call kern.proc.all: "+LIBC.strerror(Native.getLastError()));
                    }
                    break;
                }

                int count = size.getValue()/sizeOf_kinfo_proc;
                LOGGER.fine("Found "+count+" processes");

                for( int base=0; base<size.getValue(); base+=sizeOf_kinfo_proc) {
                    int pid = m.getInt(base+ kinfo_proc_pid_offset);
                    int ppid = m.getInt(base+ kinfo_proc_ppid_offset);
//                    int effective_uid = m.getInt(base+304);
//                    byte[] comm = new byte[16];
//                    m.read(base+163,comm,0,16);

                    super.processes.put(pid,new DarwinProcess(pid,ppid));
View Full Code Here

Examples of com.sun.jna.Memory

        if(Functions.isWindows())     return null;

        String filename = link.getAbsolutePath();
        try {
            for (int sz=512; sz < 65536; sz*=2) {
                Memory m = new Memory(sz);
                int r = LIBC.readlink(filename,m,new NativeLong(sz));
                if (r<0) {
                    int err = Native.getLastError();
                    if (err==22/*EINVAL --- but is this really portable?*/)
                        return null; // this means it's not a symlink
                    throw new IOException("Failed to readlink "+link+" error="+ err+" "+ LIBC.strerror(err));
                }
                if (r==sz)
                    continue;   // buffer too small

                byte[] buf = new byte[r];
                m.read(0,buf,0,r);
                return new String(buf);
            }
            // something is wrong. It can't be this long!
            throw new IOException("Symlink too long: "+link);
        } catch (LinkageError e) {
View Full Code Here

Examples of com.sun.jna.Memory

* <p>NOTE: this class would ideally be replaced by a generic.
*/
public abstract class ByReference extends PointerType {
   
    protected ByReference(int dataSize) {
        setPointer(new Memory(dataSize));
    }
View Full Code Here

Examples of com.sun.jna.Memory

    String accountName = "Administrator";
    assertFalse(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, null, pSid, null, pDomain, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pSid.getValue() > 0);
    Memory sidMemory = new Memory(pSid.getValue());
    PSID pSidMemory = new PSID(sidMemory);
    char[] referencedDomainName = new char[pDomain.getValue() + 1];
    assertTrue(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
    assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
View Full Code Here

Examples of com.sun.jna.Memory

      HANDLE h = Advapi32.INSTANCE.RegisterEventSource(null, jnaEventSource);     
      IntByReference before = new IntByReference();
      assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
      assertNotNull(h);
      String s[] = { "JNA", "Event" };
      Memory m = new Memory(4);
      m.setByte(0, (byte) 1);
      m.setByte(1, (byte) 2);
      m.setByte(2, (byte) 3);
      m.setByte(3, (byte) 4);
      assertTrue(Advapi32.INSTANCE.ReportEvent(h, WinNT.EVENTLOG_ERROR_TYPE, 0, 0, null, 2, 4, s, m));
      IntByReference after = new IntByReference();
      assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
      assertTrue(before.getValue() < after.getValue());
      assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
View Full Code Here

Examples of com.sun.jna.Memory

   
    public void testReadEventLog() {
      HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
      IntByReference pnBytesRead = new IntByReference();
      IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
      Memory buffer = new Memory(1);
      assertFalse(Advapi32.INSTANCE.ReadEventLog(h,
          WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_BACKWARDS_READ,
          0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded));
      assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
      assertTrue(pnMinNumberOfBytesNeeded.getValue() > 0);
      assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
    }
View Full Code Here

Examples of com.sun.jna.Memory

   
    public void testReadEventLogEntries() {
      HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
      IntByReference pnBytesRead = new IntByReference();
      IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
      Memory buffer = new Memory(1024 * 64);
      // shorten test, avoid iterating through all events
      int maxReads = 3;      
      int rc = 0;
      while(true) {
            if (maxReads-- <= 0)
                break;     
            if (! Advapi32.INSTANCE.ReadEventLog(h,
                                                 WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_FORWARDS_READ,
                                                 0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded)) {
                rc = Kernel32.INSTANCE.GetLastError();
                if (rc == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
                    buffer = new Memory(pnMinNumberOfBytesNeeded.getValue());
                    rc = 0;
                    continue;
                }         
                break;
            }
View Full Code Here

Examples of com.sun.jna.Memory

        final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
        mapping.genericRead = new DWORD(FILE_GENERIC_READ);
        mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
        mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
        mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
        final Memory securityDescriptorMemoryPointer = new Memory(1);

        final PRIVILEGE_SET privileges = new PRIVILEGE_SET(1);
        privileges.PrivilegeCount = new DWORD(0);
        final DWORDByReference privilegeLength = new DWORDByReference(new DWORD(privileges.size()));
        final DWORDByReference grantedAccess = new DWORDByReference();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.