Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.ByteByReference


    protected void tearDown() {
        lib = null;
    }

    public void testByteByReference() {
        ByteByReference bref = new ByteByReference();
        lib.incrementInt8ByReference(bref);
        assertEquals("Byte argument not modified", 1, bref.getValue());
    }
View Full Code Here


       
        if ( coerceArgs && args.length > 0 ){
            originalArgs = Arrays.copyOf(args, args.length);
           
            for ( int i=0; i<args.length; i++ ){
                ByteByReference out = new ByteByReference();
               
                long out2 = (long)msg(methodSignature, "getArgumentTypeAtIndex:", i+2);
                String argumentTypeSignature = new Pointer(out2).getString(0);
                args[i] = TypeMapper.getInstance().jToC(args[i], argumentTypeSignature, TypeMapper.getInstance());
               
View Full Code Here

                } else if ( String.class.isInstance(val)){
                    val = new Byte(Byte.parseByte((String)val)).byteValue();
                } else {
                    throw new RuntimeException("Attempt to pass ineligible value to byte: "+val);
                }
                return new ByteByReference((Byte)val);
            case 'v':
                return null;
            case '^':
            default:
                ////System.out.println("Outputting pointer by reference for value "+val+" and signature "+signature);
View Full Code Here

      ExecutorService executorService = Executors.newCachedThreadPool();

      try {
        int rc;
        pollfd[] pollfdset = { new pollfd() };
        ByteByReference value = new ByteByReference();
        NativeLong zero = new NativeLong(0);

        /* Last time (in milliseconds) when the interrupt was generated */
        long lastInterruptTime = 0;

        fd = LibC.INSTANCE.open(pin.valuePath.toString(), LibC.O_RDONLY | LibC.O_NONBLOCK);

        pollfdset[0].fd = fd;
        pollfdset[0].events = LibC.POLLPRI;

        /* Prior calling poll() the file needs to be read or poll() will return immediately without real interrupt received */
        try {
          LibC.INSTANCE.read(pollfdset[0].fd, value.getPointer(), 1);
        } catch (LastErrorException e) {}

        while(!interrupted()) {

          /* Wait for GPIO interrupt or timeout to occur. Timeouts provides possibility to check thread interrupt status */
          rc = LibC.INSTANCE.poll(pollfdset, 1, POLL_TIMEOUT);

          switch(rc) {

          /* Timeout, poll() again */
          case 0:
            continue;

          /* There is one file descriptor ready */
          case 1:
            /* Is interrupt received? */
            if ((pollfdset[0].revents & LibC.POLLPRI) > 0) {

              /* Calculate times for software debounce */
              long interruptTime = System.currentTimeMillis();
              long timeDifference = interruptTime - lastInterruptTime;

              /* Go to file start and read first byte */
              LibC.INSTANCE.lseek(fd, zero, LibC.SEEK_SET);
              rc = LibC.INSTANCE.read(pollfdset[0].fd, value.getPointer(), 1);

              /* There is exactly one byte read */
              if (rc == 1) {

                /* Execute event handlers each in its own thread */
                try {
                  if (pinLock.readLock().tryLock(PINLOCK_TIMEOUT, PINLOCK_TIMEOUT_UNITS)) {
                    try {

                      /* Software debounce */
                      if ((timeDifference > pin.debounceInterval) || (timeDifference < 0)) {

                        for (GPIOPinEventHandler eventHandler : pin.eventHandlers) {
                          EventHandlerExecutor eventHandlerExecutor = new EventHandlerExecutor(pin, eventHandler,
                              Character.getNumericValue(value.getValue()));
                          executorService.execute(eventHandlerExecutor);
                        }

                        lastInterruptTime = interruptTime;
                      }
View Full Code Here

                    winLoc.y = win.getY();
                    POINT srcLoc = new POINT();
                    BLENDFUNCTION blend = new BLENDFUNCTION();
                    HWND hWnd = getHWnd(win);
                    // extract current constant alpha setting, if possible
                    ByteByReference bref = new ByteByReference();
                    IntByReference iref = new IntByReference();
                    byte level = getAlpha(win);
                    try {
                        // GetLayeredwindowAttributes supported WinXP and later
                        if (user.GetLayeredWindowAttributes(hWnd, null, bref, iref)
                            && (iref.getValue() & User32.LWA_ALPHA) != 0) {
                            level = bref.getValue();
                        }
                    }
                    catch(UnsatisfiedLinkError e) {
                    }
                    blend.SourceConstantAlpha = level;
View Full Code Here

    public void testNativeMappedWrite() {
      class TestStructure extends Structure {
            public ByteByReference ref;
      }
      TestStructure s = new TestStructure();
        ByteByReference ref = s.ref = new ByteByReference();
        s.write();
        assertEquals("Value not properly written", ref.getPointer(), s.getPointer().getPointer(0));

      s.ref = null;
      s.write();
        assertNull("Non-null value was written: " + s.getPointer().getPointer(0), s.getPointer().getPointer(0));
    }
View Full Code Here

      }
      TestStructure s = new TestStructure();
        s.read();
        assertNull("Should read null for initial field value", s.ref);

        ByteByReference ref = new ByteByReference();
        s.getPointer().setPointer(0, ref.getPointer());
        s.read();
        assertEquals("Field incorrectly read", ref, s.ref);

        s.getPointer().setPointer(0, null);
        s.read();
View Full Code Here

    public void testNativeMappedWrite() {
      class TestStructure extends Structure {
            public ByteByReference ref;
      }
      TestStructure s = new TestStructure();
        ByteByReference ref = s.ref = new ByteByReference();
        s.write();
        assertEquals("Value not properly written", ref.getPointer(), s.getPointer().getPointer(0));

      s.ref = null;
      s.write();
        assertNull("Non-null value was written: " + s.getPointer().getPointer(0), s.getPointer().getPointer(0));
    }
View Full Code Here

      }
      TestStructure s = new TestStructure();
        s.read();
        assertNull("Should read null for initial field value", s.ref);

        ByteByReference ref = new ByteByReference();
        s.getPointer().setPointer(0, ref.getPointer());
        s.read();
        assertEquals("Field incorrectly read", ref, s.ref);

        s.getPointer().setPointer(0, null);
        s.read();
View Full Code Here

                    winLoc.y = win.getY();
                    POINT srcLoc = new POINT();
                    BLENDFUNCTION blend = new BLENDFUNCTION();
                    HWND hWnd = getHWnd(win);
                    // extract current constant alpha setting, if possible
                    ByteByReference bref = new ByteByReference();
                    IntByReference iref = new IntByReference();
                    byte level = getAlpha(win);
                    try {
                        // GetLayeredwindowAttributes supported WinXP and later
                        if (user.GetLayeredWindowAttributes(hWnd, null, bref, iref)
                            && (iref.getValue() & User32.LWA_ALPHA) != 0) {
                            level = bref.getValue();
                        }
                    }
                    catch(UnsatisfiedLinkError e) {
                    }
                    blend.SourceConstantAlpha = level;
View Full Code Here

TOP

Related Classes of com.sun.jna.ptr.ByteByReference

Copyright © 2018 www.massapicom. 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.