@Override
  public synchronized int onEvent(
      int evtSubscribeNotifyAction, WinDef.PVOID userContext, WinNT.HANDLE eventHandle) {
    if (logger.isDebugEnabled()) {
      logger.debug("onEvent(" + evtSubscribeNotifyAction + ", " + userContext + ", " + eventHandle);
    }

    if (evtSubscribeNotifyAction == WEvtApi.EvtSubscribeNotifyAction.ERROR) {
      if (eventHandle.getPointer().getInt(0)
          == WEvtApi.EvtSubscribeErrors.ERROR_EVT_QUERY_RESULT_STALE) {
        logger.error(MISSING_EVENT_MESSAGE);
      } else {
        logger.error(RECEIVED_THE_FOLLOWING_WIN32_ERROR + eventHandle.getPointer().getInt(0));
      }
    } else if (evtSubscribeNotifyAction == WEvtApi.EvtSubscribeNotifyAction.DELIVER) {
      wEvtApi.EvtRender(
          null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used, propertyCount);

      // Not enough room in buffer, resize so it's big enough
      if (kernel32.GetLastError() == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        int newMaxSize = used.getInt(0);
        // Check for overflow or too big
        if (newMaxSize < size || newMaxSize > maxBufferSize) {
          logger.error(
              "Dropping event "
                  + eventHandle
                  + " because it couldn't be rendered within "
                  + maxBufferSize
                  + " bytes.");
          // Ignored, see
          // https://msdn.microsoft.com/en-us/library/windows/desktop/aa385577(v=vs.85).aspx
          return 0;
        }
        size = newMaxSize;
        buffer = new Memory(size);
        wEvtApi.EvtRender(
            null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used, propertyCount);
      }

      int lastError = kernel32.GetLastError();
      if (lastError == W32Errors.ERROR_SUCCESS) {
        int usedBytes = used.getInt(0);
        String string = Charsets.UTF_16LE.decode(buffer.getByteBuffer(0, usedBytes)).toString();
        if (string.endsWith("\u0000")) {
          string = string.substring(0, string.length() - 1);
        }
        consumer.accept(string);
      } else {
        logger.error(
            EVT_RENDER_RETURNED_THE_FOLLOWING_ERROR_CODE + errorLookup.getLastError() + ".");
      }
    }
    // Ignored, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa385577(v=vs.85).aspx
    return 0;
  }
Exemplo n.º 2
0
 @Override
 public void display(
     DirectMediaPlayer mediaPlayer, Memory[] nativeBuffers, BufferFormat bufferFormat) {
   Memory nativeBuffer = nativeBuffers[0];
   ByteBuffer byteBuffer = nativeBuffer.getByteBuffer(0, nativeBuffer.size());
   pixelWriter.setPixels(
       0,
       0,
       bufferFormat.getWidth(),
       bufferFormat.getHeight(),
       pixelFormat,
       byteBuffer,
       bufferFormat.getPitches()[0]);
 }
Exemplo n.º 3
0
 public SockFProg(SockFilter filters[]) {
   len = (short) filters.length;
   // serialize struct sock_filter * explicitly, its less confusing than the JNA magic we would
   // need
   Memory filter = new Memory(len * 8);
   ByteBuffer bbuf = filter.getByteBuffer(0, len * 8);
   bbuf.order(ByteOrder.nativeOrder()); // little endian
   for (SockFilter f : filters) {
     bbuf.putShort(f.code);
     bbuf.put(f.jt);
     bbuf.put(f.jf);
     bbuf.putInt(f.k);
   }
   this.filter = filter;
 }
Exemplo n.º 4
0
 @Override
 public void display(Memory memory) {
   if (BUFFER_SIZE <= 0) return;
   videoBuffer = memory.getByteBuffer(0, BUFFER_SIZE);
   newBuffer = true;
 }