Esempio n. 1
0
  /**
   * Registers FFI ruby classes/modules
   *
   * @param module the module to register the classes under
   */
  public void init(Ruby runtime, RubyModule ffi) {
    synchronized (ffi) {
      if (ffi.getClass("Type") == null) {
        Type.createTypeClass(runtime, ffi);
      }
      DataConverter.createDataConverterModule(runtime, ffi);

      if (ffi.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS) == null) {
        AbstractMemory.createAbstractMemoryClass(runtime, ffi);
      }
      if (ffi.getClass("Buffer") == null) {
        Buffer.createBufferClass(runtime, ffi);
      }
      if (ffi.getClass("Pointer") == null) {
        Pointer.createPointerClass(runtime, ffi);
      }
      if (ffi.getClass("AutoPointer") == null) {
        AutoPointer.createAutoPointerClass(runtime, ffi);
      }
      if (ffi.getClass("MemoryPointer") == null) {
        MemoryPointer.createMemoryPointerClass(runtime, ffi);
      }
      if (ffi.getClass("Struct") == null) {
        Struct.createStructClass(runtime, ffi);
      }
      if (ffi.getClass(StructLayout.CLASS_NAME) == null) {
        StructLayout.createStructLayoutClass(runtime, ffi);
      }
      if (ffi.getClass("StructByValue") == null) {
        StructByValue.createStructByValueClass(runtime, ffi);
      }
      if (ffi.getClass(AbstractInvoker.CLASS_NAME) == null) {
        AbstractInvoker.createAbstractInvokerClass(runtime, ffi);
      }
      if (ffi.getClass(CallbackInfo.CLASS_NAME) == null) {
        CallbackInfo.createCallbackInfoClass(runtime, ffi);
      }
      if (ffi.getClass("Enum") == null) {
        Enum.createEnumClass(runtime, ffi);
      }
      if (ffi.getClass("Type").getClass("Mapped") == null) {
        MappedType.createConverterTypeClass(runtime, ffi);
      }
      if (ffi.getClass(FileDescriptorIO.CLASS_NAME) == null) {
        FileDescriptorIO.createFileDescriptorIOClass(runtime, ffi);
      }

      ffi.setConstant("TypeDefs", RubyHash.newHash(runtime));

      Platform.createPlatformModule(runtime, ffi);
      IOModule.createIOModule(runtime, ffi);

      StructByReference.createStructByReferenceClass(runtime, ffi);
    }
  }
Esempio n. 2
0
 private static final int bufferFlags(Buffer buffer) {
   int f = buffer.getInOutFlags();
   return ((f & Buffer.IN) != 0 ? ArrayFlags.IN : 0)
       | ((f & Buffer.OUT) != 0 ? ArrayFlags.OUT : 0);
 }