Package com.sun.jna

Examples of com.sun.jna.Memory


    try
    {
      IntByReference lpdwType = new IntByReference();
      IntByReference lpcchName = new IntByReference(0);
      Memory lpszName = new Memory(256);

      int dwIndex = 0;

      int returnValue = 0;
      do
      {
        lpdwType.setValue(0);
        lpcchName.setValue(0);
        lpszName.clear();
        lpcchName.setValue(256);

        returnValue = Clusapi.INSTANCE.ClusterEnum(hEnum, dwIndex, lpdwType, lpszName, lpcchName);

        if (returnValue == Clusapi.ERROR_SUCCESS)
        {
          String group = lpszName.getString(0, true);
          ClusterGroupInfo info = getGroupNodeInfo(hCluster, group);
          if (info != null)
            result.add(info);
        }
View Full Code Here


          {
            IntByReference lpdwNotifyKey = new IntByReference();
            IntByReference lpdwFilterType = new IntByReference();
            IntByReference lpcchName = new IntByReference();
            IntByReference dwNotifyKey = new IntByReference();
            Memory lpszName = new Memory(256);
            Pointer minusOne = Pointer.createConstant(-1);
            int dwMilliseconds = 300 * 1000;
            final int dwFilter = Clusapi.CLUSTER_CHANGE_GROUP_STATE | Clusapi.CLUSTER_CHANGE_HANDLE_CLOSE
                | Clusapi.CLUSTER_CHANGE_GROUP_DELETED | Clusapi.CLUSTER_CHANGE_CLUSTER_STATE
                | Clusapi.CLUSTER_CHANGE_CLUSTER_RECONNECT | Clusapi.CLUSTER_CHANGE_GROUP_ADDED;

            while (!_stopped)
            {
              Pointer hCluster = null;
              Pointer hChange = null;

              long started = System.currentTimeMillis();

              try
              {
                lpdwNotifyKey.setValue(0);
                lpdwFilterType.setValue(0);
                lpcchName.setValue(0);
                dwNotifyKey.setValue(0);
                lpszName.clear();
                lpcchName.setValue(256);

                hCluster = Clusapi.INSTANCE.OpenCluster(null);
                if (hCluster == null)
                  _log.severe("ClusApi.OpenCluster returned err code " + MyKernel32.INSTANCE.GetLastError());
                else
                {
                  hChange = Clusapi.INSTANCE.CreateClusterNotifyPort(minusOne, hCluster, dwFilter, dwNotifyKey);
                  if (hChange == null)
                    _log.severe("ClusApi.CreateClusterNotifyPort returned err code " + MyKernel32.INSTANCE.GetLastError());
                }

                if (hCluster == null || hChange == null)
                  Thread.sleep(5000);
                else
                {
                  int result = Clusapi.INSTANCE.GetClusterNotify(hChange, lpdwNotifyKey, lpdwFilterType, lpszName, lpcchName,
                      dwMilliseconds);

                  if (result == Clusapi.ERROR_SUCCESS)
                    doListeners(null, lpdwFilterType.getValue(), lpszName.getString(0, true));
                  else if (result != Clusapi.WAIT_TIMEOUT) // 258
                                        // =
                                        // Wait
                                        // Time
                                        // Out
View Full Code Here

  protected String getWorkingDirInternal()
  {

    String f = "/proc/" + getPid() + "/cwd";
    short BUFSIZE = 512;
    Memory result = new Memory(BUFSIZE);
    result.clear();
    short size = CLibrary.INSTANCE.readlink(f, result, (short) (BUFSIZE - 1));
    if (size <= 0)
    {
      System.out.println("error reading process working dir -> please edit wrapper.working.dir in configuration file");
      return f;
    }
    result.setByte((long) size, (byte) 0);
    return result.getString(0);

    /*
     * String result = null; File f = new File("/proc/" + getPid() +
     * "/cwd"); try { result = f.getCanonicalPath(); } catch (IOException e)
     * { e.printStackTrace(); } return result;
View Full Code Here

        // get size required
        if (!advapi32.QueryServiceConfig(service, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig(service, buffer, cbBufSize, pcbBytesNeeded))
          {
            QUERY_SERVICE_CONFIG lpServiceConfig = new QUERY_SERVICE_CONFIG();
            lpServiceConfig.init(buffer);
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DISABLED)
              state |= Service.STATE_DISABLED;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_BOOT_START | lpServiceConfig.dwStartType == Advapi32.SERVICE_SYSTEM_START
                | lpServiceConfig.dwStartType == Advapi32.SERVICE_AUTO_START)
              state |= Service.STATE_AUTOMATIC;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DEMAND_START)
              state |= Service.STATE_MANUAL;
            if ((lpServiceConfig.dwServiceType & Advapi32.SERVICE_INTERACTIVE_PROCESS) != 0)
              state |= Service.STATE_INTERACTIVE;
            result.setAccount(lpServiceConfig.lpServiceStartName);
            result.setCommand(lpServiceConfig.lpBinaryPathName);
            result.setDependencies(lpServiceConfig.getDependencies());
            result.setDisplayName(lpServiceConfig.lpDisplayName);

          }
          else
          {
            state |= Service.STATE_UNKNOWN;
            System.out.println("Error in QueryServiceConfig: " + Native.getLastError());
          }
        }
        else
        {
          state |= Service.STATE_UNKNOWN;
          System.out.println("Error in QueryServiceConfig: " + Native.getLastError());
        }
        if (!advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_STATUS_PROCESS lpBuffer = new SERVICE_STATUS_PROCESS();
            lpBuffer.init(buffer);
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_RUNNING)
              state |= Service.STATE_RUNNING;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_PAUSED)
              state |= Service.STATE_PAUSED;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_START_PENDING)
              state |= Service.STATE_STARTING;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_STOP_PENDING)
              state |= Service.STATE_STOPPING;
            result.setPid(lpBuffer.dwProcessId);
          }
          else
          {
            state |= Service.STATE_UNKNOWN;
            System.out.println("Error in QueryServiceStatusEx: " + Native.getLastError());
          }
        }
        if (!advapi32.QueryServiceConfig2(service, (byte) advapi32.SERVICE_CONFIG_DESCRIPTION, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig2(service, (byte) advapi32.SERVICE_CONFIG_DESCRIPTION, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_DESCRIPTION lpBuffer = new SERVICE_DESCRIPTION();
            lpBuffer.init(buffer);
            result.setDescription(lpBuffer.lpDescription);
View Full Code Here

        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          if (cbBufSize > 8192)
            cbBufSize = 8192;
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig(service, buffer, cbBufSize, pcbBytesNeeded))
          {
            QUERY_SERVICE_CONFIG lpServiceConfig = new QUERY_SERVICE_CONFIG();
            lpServiceConfig.init(buffer);
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DISABLED)
              result |= Service.STATE_DISABLED;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_BOOT_START | lpServiceConfig.dwStartType == Advapi32.SERVICE_SYSTEM_START
                | lpServiceConfig.dwStartType == Advapi32.SERVICE_AUTO_START)
              result |= Service.STATE_AUTOMATIC;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DEMAND_START)
              result |= Service.STATE_MANUAL;
            if ((lpServiceConfig.dwServiceType & Advapi32.SERVICE_INTERACTIVE_PROCESS) != 0)
              result |= Service.STATE_INTERACTIVE;

          }
          else
          {
            result |= Service.STATE_UNKNOWN;
            int error = Native.getLastError();
            System.out.println("Error getting buffer size in QueryServiceConfig: " + error + " " + Kernel32Util.formatMessageFromLastErrorCode(error));
          }
        }
        else
        {
          result |= Service.STATE_UNKNOWN;
          int error = Native.getLastError();
          System.out.println("Error in QueryServiceConfig: " + error + " " + Kernel32Util.formatMessageFromLastErrorCode(error));
        }
        if (!advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_STATUS_PROCESS lpBuffer = new SERVICE_STATUS_PROCESS();
            lpBuffer.init(buffer);
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_RUNNING)
View Full Code Here

    Pointer sc = openServiceControlManager(machine, WINSVC.SC_MANAGER_ENUMERATE_SERVICE);

    // Check if OpenSCManager returns NULL. Otherwise proceed
    if (sc != null && !sc.equals(null))
    {
      Memory service_data = null;
      int service_data_size = 0;
      int infoLevel = WINSVC.SC_ENUM_PROCESS_INFO;
      boolean retVal;
      IntByReference bytesNeeded = new IntByReference(0);
      IntByReference srvCount = new IntByReference(0);
      IntByReference resumeHandle = new IntByReference(0);
      int srvType = WINSVC.SERVICE_WIN32;
      int srvState = WINSVC.SERVICE_STATE_ALL;

      // Call EnumServicesStatus with null data and data_size == 0, so we
      // get the required memory size
      retVal = Advapi32.INSTANCE.EnumServicesStatusExW(sc, infoLevel, srvType, srvState, service_data, service_data_size, bytesNeeded,
          srvCount, resumeHandle, null);

      int err = Native.getLastError();
      // EnumServicesStatus should need more memory space
      if ((!retVal) || err == WINERROR.ERROR_MORE_DATA)
      {
        int bytesCount = bytesNeeded.getValue();
        service_data = new Memory(bytesCount);
        service_data.clear();
        service_data_size = bytesCount;
        // System.out.println(resumeHandle.getValue());
        resumeHandle.setValue(0);
        retVal = Advapi32.INSTANCE.EnumServicesStatusExW(sc, infoLevel, srvType, srvState, service_data, service_data_size, bytesNeeded,
            srvCount, resumeHandle, null);
View Full Code Here

         *
         * @param size The size in bytes of memory to allocate.
         *
         */
        private PointerIO(long size) {
            this(new Memory(size), size);
        }
View Full Code Here

            // 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

    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

                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

TOP

Related Classes of com.sun.jna.Memory

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.