Examples of Memory


Examples of com.sun.jna.Memory

  {
    readIndexMap();
    Integer index = (Integer) _indexes.get(name);
    if (index == null)
      return name;
    Memory buff = new Memory(256);
    IntByReference buffSize = new IntByReference();
    buffSize.setValue(256);
    if (Pdhdll.INSTANCE.PdhLookupPerfNameByIndexA(null, index.intValue(), buff, buffSize) == Pdhdll.ERROR_SUCCESS)
      return buff.getString(0);
    return name;
  }
View Full Code Here

Examples of com.sun.jna.Memory

      Pointer cluster = Clusapi.INSTANCE.OpenCluster(null);
      Pointer hEnum = Clusapi.INSTANCE.ClusterOpenEnum(cluster, Clusapi.CLUSTER_ENUM_GROUP);
      int dwIndex = 0;
      IntByReference lpdwType = new IntByReference();
      IntByReference lpcchName = new IntByReference();
      Memory lpszName = new Memory(256);
      lpszName.clear();
      lpcchName.setValue(256);
      int result = 0;
      do
      {
        result = Clusapi.INSTANCE.ClusterEnum(hEnum, dwIndex, lpdwType, lpszName, lpcchName);
        if (result == Clusapi.ERROR_SUCCESS)
        {
          String group = lpszName.getString(0, true);
          ClusterGroupInfo info = getGroupNodeInfo(cluster, group);
          if (info != null)
            activeNode = info.getLocation();
        }
        dwIndex++;
View Full Code Here

Examples of com.sun.jna.Memory

      if (hGroup == null)
        throw new RuntimeException("Clusapi call to OpenClusterGroup returned err code " + MyKernel32.INSTANCE.GetLastError());

      IntByReference lpcchNodeName = new IntByReference();
      Memory lpszNodeName = new Memory(256);
      lpszNodeName.clear();
      lpcchNodeName.setValue(256);

      int state = Clusapi.INSTANCE.GetClusterGroupState(hGroup, lpszNodeName, lpcchNodeName);
      String location = lpszNodeName.getString(0, true);

      if (state == Clusapi.CLUSTER_GROUP_STATE_UNKNOWN)
        _log.severe("unknown group state for group " + groupName + " err code " + MyKernel32.INSTANCE.GetLastError());

      result = new ClusterGroupInfo(groupName, state, location);
View Full Code Here

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

Examples of com.sun.jna.Memory

          {
            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

Examples of com.sun.jna.Memory

  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

Examples of com.sun.jna.Memory

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

Examples of com.sun.jna.Memory

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

Examples of com.sun.jna.Memory

    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

Examples of com.sun.jna.Memory

         *
         * @param size The size in bytes of memory to allocate.
         *
         */
        private PointerIO(long size) {
            this(new Memory(size), size);
        }
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.