Module: Hypertube::Core::Transmitter::TransmitterWrapper

Extended by:
FFI::Library
Defined in:
lib/hypertube-ruby-sdk/core/transmitter/transmitter_wrapper.rb

Constant Summary collapse

LOAD_MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.ensure_loadedObject

Idempotent, thread-safe one-time load of the native library and its attached functions (check-then-load under lock with double-check).



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hypertube-ruby-sdk/core/transmitter/transmitter_wrapper.rb', line 12

def self.ensure_loaded
  return if @loaded

  LOAD_MUTEX.synchronize do
    return if @loaded

    arch = case FFI::Platform::ARCH
           when 'x86_64'
             'X64'
           when 'x86'
             'X86'
           when 'arm'
             'ARM'
           when 'aarch64'
             'ARM64'
           else
             raise "Unsupported architecture: #{FFI::Platform::ARCH}"
           end

    if OS.linux?
      ffi_lib File.expand_path("../../../Binaries/Native/Linux/#{arch}/libHypertubeRubyRuntimeNative.so", __FILE__)
    elsif OS.mac?
      ffi_lib File.expand_path("../../../Binaries/Native/MacOs/#{arch}/libHypertubeRubyRuntimeNative.dylib", __FILE__)
    else
      RubyInstaller::Runtime.add_dll_directory(File.expand_path("../../../Binaries/Native/Windows/#{arch}/", __FILE__))
      ffi_lib File.expand_path("../../../Binaries/Native/Windows/#{arch}/HypertubeRubyRuntimeNative.dll", __FILE__)
    end

    attach_function :SendCommand, [:pointer, :int, :string], :int
    attach_function :ReadResponse, [:pointer, :int], :int
    attach_function :Activate, [:pointer], :int
    attach_function :GetNativeError, [], :string
    attach_function :SetConfigSource, [:pointer], :int
    attach_function :SetWorkingDirectory, [:pointer], :int

    @loaded = true
  end
end