Exemple #1
0
  public static CObject parse(CLibrary parent, boolean protocol, Stream s) {
    String name = s.consumeID();
    CObject obj = protocol ? parent.getInterface(name) : parent.getObject(name);
    Reporter.setObject(obj);

    // Remove categories
    if (s.peekChar() == '(') s.consumeBalanced('(', ')');

    // Find superclass
    if (s.peekChar() == ':') {
      s.consumeChars(1);
      obj.setSuperclass(s.consumeID());
    }

    // Find interfaces
    if (s.peekChar() == '<') {
      String interfs = s.consumeBalanced('<', '>');
      interfs = interfs.substring(1, interfs.length() - 1).trim();
      StringTokenizer tk = new StringTokenizer(interfs, ",");
      while (tk.hasMoreTokens()) obj.addInterface(tk.nextToken().trim());
    }
    if (s.peekChar() == '{') s.consumeBalanced('{', '}');
    if (s.peekChar() == ';') s.consumeChars(1);

    return obj;
  }
 public static void sched_setaffinity(final BitSet affinity) {
   final CLibrary lib = CLibrary.INSTANCE;
   final cpu_set_t cpuset = new cpu_set_t();
   final int size =
       version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE;
   final long[] bits = affinity.toLongArray();
   for (int i = 0; i < bits.length; i++) {
     if (Platform.is64Bit()) {
       cpuset.__bits[i].setValue(bits[i]);
     } else {
       cpuset.__bits[i * 2].setValue(bits[i] & 0xFFFFFFFFL);
       cpuset.__bits[i * 2 + 1].setValue((bits[i] >>> 32) & 0xFFFFFFFFL);
     }
   }
   try {
     if (lib.sched_setaffinity(0, size, cpuset) != 0) {
       throw new IllegalStateException(
           "sched_setaffinity(0, "
               + size
               + ", 0x"
               + Utilities.toHexString(affinity)
               + ") failed; errno="
               + Native.getLastError());
     }
   } catch (LastErrorException e) {
     throw new IllegalStateException(
         "sched_setaffinity(0, "
             + size
             + ", 0x"
             + Utilities.toHexString(affinity)
             + ") failed; errno="
             + e.getErrorCode(),
         e);
   }
 }
 public static int syscall(int number, Object... args) {
   final CLibrary lib = CLibrary.INSTANCE;
   try {
     final int ret = lib.syscall(number, args);
     if (ret < 0) {
       throw new IllegalStateException("sched_getcpu() failed; errno=" + Native.getLastError());
     }
     return ret;
   } catch (LastErrorException e) {
     throw new IllegalStateException("sched_getcpu() failed; errno=" + e.getErrorCode(), e);
   }
 }
 public static int getpid() {
   final CLibrary lib = CLibrary.INSTANCE;
   try {
     final int ret = lib.getpid();
     if (ret < 0) {
       throw new IllegalStateException("getpid() failed; errno=" + Native.getLastError());
     }
     return ret;
   } catch (LastErrorException e) {
     throw new IllegalStateException("getpid() failed; errno=" + e.getErrorCode(), e);
   }
 }
Exemple #5
0
 CObject(CLibrary library, String name, boolean isProtocol) {
   super(name);
   this.library = library;
   this.isProtocol = isProtocol;
   genericsCount = Advisor.genericsSupport(name);
   this.cClassName = library.getPackagename().replace(".", "_") + "_" + name;
 }
  public static @NotNull cpu_set_t sched_getaffinity() {
    final CLibrary lib = CLibrary.INSTANCE;
    final cpu_set_t cpuset = new cpu_set_t();
    final int size =
        version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE;

    try {
      if (lib.sched_getaffinity(0, size, cpuset) != 0) {
        throw new IllegalStateException(
            "sched_getaffinity(0, " + size + ", cpuset) failed; errno=" + Native.getLastError());
      }
    } catch (LastErrorException e) {
      throw new IllegalStateException(
          "sched_getaffinity(0, (" + size + ") , cpuset) failed; errno=" + e.getErrorCode(), e);
    }
    return cpuset;
  }
Exemple #7
0
  protected static void write(int level, String message, UnixSyslogConfig config)
      throws SyslogRuntimeException {
    synchronized (libraryInstance) {
      if (currentFacility != config.getFacility()) {
        if (openlogCalled) {
          libraryInstance.closelog();
          openlogCalled = false;
        }

        currentFacility = config.getFacility();
      }

      if (!openlogCalled) {
        String ident = config.getIdent();

        if (ident != null && "".equals(ident.trim())) {
          ident = null;
        }

        Memory identBuffer = ident == null ? null : (Memory) identMap.get(ident);

        if (ident != null && identBuffer == null) {
          identBuffer = new Memory(128);
          identBuffer.setString(0, ident, false);
          identMap.put(ident, identBuffer);
        }

        libraryInstance.openlog(identBuffer, config.getOption(), currentFacility);
        openlogCalled = true;
      }

      int priority = currentFacility | level;

      libraryInstance.syslog(priority, "%s", message);
    }
  }
  public static int sched_getcpu() {
    final CLibrary lib = CLibrary.INSTANCE;
    try {
      final int ret = lib.sched_getcpu();
      if (ret < 0) {
        throw new IllegalStateException("sched_getcpu() failed; errno=" + Native.getLastError());
      }
      return ret;
    } catch (LastErrorException e) {
      throw new IllegalStateException("sched_getcpu() failed; errno=" + e.getErrorCode(), e);
    } catch (UnsatisfiedLinkError ule) {
      try {
        final IntByReference cpu = new IntByReference();
        final IntByReference node = new IntByReference();
        final int ret = lib.syscall(318, cpu, node, null);
        if (ret != 0) {
          throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError());
        }
        return cpu.getValue();
      } catch (LastErrorException lee) {
        if (lee.getErrorCode() == 38 && Platform.is64Bit()) { // unknown call
          final Pointer getcpuAddr = new Pointer((-10L << 20) + 1024L * 2L);
          final Function getcpu = Function.getFunction(getcpuAddr, Function.C_CONVENTION);
          final IntByReference cpu = new IntByReference();
          if (getcpu.invokeInt(new Object[] {cpu, null, null}) < 0) {
            throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError());

          } else {
            return cpu.getValue();
          }
        } else {
          throw new IllegalStateException("getcpu() failed; errno=" + lee.getErrorCode(), lee);
        }
      }
    }
  }
  /*
   * Does the LMA fit according to whether the library is accessed via JNA or
   * JNI.
   */
  private int doLMAFit(
      double xInc,
      double y[],
      int fitStart,
      int fitEnd,
      double instr[],
      int n_instr,
      int noise,
      double sig[],
      double param[],
      int paramFree[],
      int nParam,
      double fitted[],
      double chiSquare[],
      double chiSquareTarget,
      double chiSquareDelta) {
    int returnValue = 0;

    if (s_libraryOnPath) {
      // JNA version

      DoubleByReference chiSquareRef = new DoubleByReference(chiSquare[0]);

      returnValue =
          s_library.LMA_fit(
              xInc,
              y,
              fitStart,
              fitEnd,
              instr,
              n_instr,
              noise,
              sig,
              param,
              paramFree,
              nParam,
              fitted,
              chiSquareRef,
              chiSquareTarget,
              chiSquareDelta);

      chiSquare[0] = chiSquareRef.getValue();
    } else {
      // JNI version

      returnValue =
          LMA_fit(
              xInc,
              y,
              fitStart,
              fitEnd,
              instr,
              n_instr,
              noise,
              sig,
              param,
              paramFree,
              nParam,
              fitted,
              chiSquare,
              chiSquareTarget,
              chiSquareDelta);
    }
    return returnValue;
  }
  /*
   * Does the RLD fit according to whether the library is accessed via JNA or
   * JNI.
   */
  private int doRLDFit(
      double xInc,
      double y[],
      int fitStart,
      int fitEnd,
      double instr[],
      int nInstr,
      int noise,
      double sig[],
      double z[],
      double a[],
      double tau[],
      double fitted[],
      double chiSquare[],
      double chiSquareTarget) {
    int returnValue = 0;
    if (s_libraryOnPath) {
      // JNA version

      DoubleByReference zRef = new DoubleByReference(z[0]);
      DoubleByReference aRef = new DoubleByReference(a[0]);
      DoubleByReference tauRef = new DoubleByReference(tau[0]);
      DoubleByReference chiSquareRef = new DoubleByReference(chiSquare[0]);

      returnValue =
          s_library.RLD_fit(
              xInc,
              y,
              fitStart,
              fitEnd,
              instr,
              nInstr,
              noise,
              sig,
              zRef,
              aRef,
              tauRef,
              fitted,
              chiSquareRef,
              chiSquareTarget);

      z[0] = zRef.getValue();
      a[0] = aRef.getValue();
      tau[0] = tauRef.getValue();
      chiSquare[0] = chiSquareRef.getValue();
    } else {
      // JNI version

      returnValue =
          RLD_fit(
              xInc,
              y,
              fitStart,
              fitEnd,
              instr,
              nInstr,
              noise,
              sig,
              z,
              a,
              tau,
              fitted,
              chiSquare,
              chiSquareTarget);
    }
    return returnValue;
  }
 public void killNode(File nodeDir) throws Exception {
   long pid = getPid(nodeDir);
   CLibrary.kill((int) pid, 9);
 }
Exemple #12
0
 public void flush() throws SyslogRuntimeException {
   synchronized (libraryInstance) {
     libraryInstance.closelog();
     openlogCalled = false;
   }
 }