public static void createPKeyDSA(Ruby runtime, RubyModule mPKey) { RubyClass cDSA = mPKey.defineClassUnder("DSA", mPKey.getClass("PKey"), PKEYDSA_ALLOCATOR); RubyClass pkeyError = mPKey.getClass("PKeyError"); mPKey.defineClassUnder("DSAError", pkeyError, pkeyError.getAllocator()); cDSA.defineAnnotatedMethods(PKeyDSA.class); }
public static RubyClass createConverterTypeClass(Ruby runtime, RubyModule ffiModule) { RubyClass convClass = ffiModule .getClass("Type") .defineClassUnder( "Mapped", ffiModule.getClass("Type"), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); convClass.defineAnnotatedMethods(MappedType.class); convClass.defineAnnotatedConstants(MappedType.class); return convClass; }
public static RubyClass createPointerClass(Ruby runtime, RubyModule module) { RubyClass pointerClass = module.defineClassUnder( "Pointer", module.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS), RubyInstanceConfig.REIFY_RUBY_CLASSES ? new ReifyingAllocator(Pointer.class) : PointerAllocator.INSTANCE); pointerClass.defineAnnotatedMethods(Pointer.class); pointerClass.defineAnnotatedConstants(Pointer.class); pointerClass.setReifiedClass(Pointer.class); pointerClass.kindOf = new RubyModule.KindOf() { @Override public boolean isKindOf(IRubyObject obj, RubyModule type) { return obj instanceof Pointer && super.isKindOf(obj, type); } }; module.defineClassUnder( "NullPointerError", runtime.getRuntimeError(), runtime.getRuntimeError().getAllocator()); // Add Pointer::NULL as a constant Pointer nullPointer = new Pointer(runtime, pointerClass, new NullMemoryIO(runtime)); pointerClass.setConstant("NULL", nullPointer); runtime .getNilClass() .addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer)); return pointerClass; }
public static void createConfig(Ruby runtime, RubyModule mOSSL) { RubyClass cConfig = mOSSL.defineClassUnder("Config", runtime.getObject(), runtime.getObject().getAllocator()); cConfig.defineAnnotatedMethods(Config.class); RubyClass openSSLError = mOSSL.getClass("OpenSSLError"); mOSSL.defineClassUnder("ConfigError", openSSLError, openSSLError.getAllocator()); // TODO: we should define this constant with proper path. (see above) // cConfig.setConstant("DEFAULT_CONFIG_FILE", runtime.newString(DEFAULT_CONFIG_FILE)); }
/** * @param runtime * @param driver * @return */ public static RubyClass createResultClass(final Ruby runtime, DriverDefinition driver) { RubyModule doModule = runtime.getModule(DATA_OBJECTS_MODULE_NAME); RubyClass superClass = doModule.getClass(RUBY_CLASS_NAME); RubyModule driverModule = (RubyModule) doModule.getConstant(driver.getModuleName()); RubyClass resultClass = driverModule.defineClassUnder(RUBY_CLASS_NAME, superClass, RESULT_ALLOCATOR); resultClass.defineAnnotatedMethods(Result.class); return resultClass; }
public static RubyClass createBufferClass(Ruby runtime, RubyModule module) { RubyClass result = module.defineClassUnder( "Buffer", module.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); result.defineAnnotatedMethods(Buffer.class); result.defineAnnotatedConstants(Buffer.class); return result; }
/** * @param runtime * @param factory * @return */ public static RubyClass createCommandClass(final Ruby runtime, DriverDefinition factory) { RubyModule doModule = runtime.getModule(DATA_OBJECTS_MODULE_NAME); RubyClass superClass = doModule.getClass(RUBY_CLASS_NAME); RubyModule driverModule = (RubyModule) doModule.getConstant(factory.getModuleName()); RubyClass commandClass = runtime.defineClassUnder("Command", superClass, COMMAND_ALLOCATOR, driverModule); commandClass.setInstanceVariable("@__factory", JavaEmbedUtils.javaToRuby(runtime, factory)); commandClass.defineAnnotatedMethods(Command.class); setDriverDefinition(commandClass, runtime, factory); return commandClass; }
public static void createPKey(Ruby runtime, RubyModule ossl) { RubyModule _PKey = ossl.defineModuleUnder("PKey"); _PKey.defineAnnotatedMethods(PKeyModule.class); // PKey is abstract RubyClass _PKeyPkey = _PKey.defineClassUnder( "PKey", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); RubyClass _OpenSSLError = ossl.getClass("OpenSSLError"); _PKey.defineClassUnder("PKeyError", _OpenSSLError, _OpenSSLError.getAllocator()); _PKeyPkey.defineAnnotatedMethods(PKey.class); PKeyRSA.createPKeyRSA(runtime, _PKey); PKeyDSA.createPKeyDSA(runtime, _PKey); PKeyDH.createPKeyDH(runtime, _PKey, _PKeyPkey); }
/** * Output a log message * * @param logMessage * @param executionTime */ private void debug(String logMessage, Long executionTime) { Ruby runtime = getRuntime(); Connection connection_instance = (Connection) api.getInstanceVariable(this, "@connection"); RubyModule doModule = runtime.getModule(DATA_OBJECTS_MODULE_NAME); RubyClass loggerClass = doModule.getClass("Logger"); RubyClass messageClass = loggerClass.getClass("Message"); IRubyObject loggerMsg = messageClass.newInstance( runtime.getCurrentContext(), runtime.newString(logMessage), // query runtime.newString(""), // start runtime.newFixnum(executionTime), // duration Block.NULL_BLOCK); api.callMethod(connection_instance, "log", loggerMsg); }
public static RubyClass createCommandClass( final Ruby runtime, final String moduleName, final String errorName, final DriverDefinition driverDefinition) { RubyModule doModule = runtime.getModule(DATA_OBJECTS_MODULE_NAME); RubyClass superClass = doModule.getClass(RUBY_CLASS_NAME); RubyModule driverModule = (RubyModule) doModule.getConstant(moduleName); RubyClass commandClass = runtime.defineClassUnder("Command", superClass, COMMAND_ALLOCATOR, driverModule); Command.api = JavaEmbedUtils.newObjectAdapter(); Command.driver = driverDefinition; Command.moduleName = moduleName; Command.errorName = errorName; commandClass.defineAnnotatedMethods(Command.class); return commandClass; }
/** * instantiateClass * * @param runtime * @param module * @param name * @param args * @return */ public static IRubyObject instantiateClass( Ruby runtime, String module, String name, IRubyObject... args) { ThreadContext threadContext = runtime.getCurrentContext(); IRubyObject result = null; // try to load the module RubyModule rubyModule = runtime.getModule(module); if (rubyModule != null) { // now try to load the class RubyClass rubyClass = rubyModule.getClass(name); // instantiate it, if it exists if (rubyClass != null) { result = rubyClass.newInstance(threadContext, args, Block.NULL_BLOCK); } } return result; }
/** * 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); } }