Class: Sybase::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/sybase/context.rb

Defined Under Namespace

Classes: Callbacks

Instance Method Summary collapse

Constructor Details

#initialize(version = DEFAULT_CTLIB_VERSION) ⇒ Context

Returns a new instance of Context.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sybase/context.rb', line 3

def initialize(version = DEFAULT_CTLIB_VERSION)
  @version = Integer(version)

  FFI::MemoryPointer.new(:pointer) do |ptr|
    Lib.check Lib.cs_ctx_alloc(@version, ptr), "cs_ctx_alloc failed"
    @ptr = FFI::AutoPointer.new(ptr.read_pointer, Lib.method(:cs_ctx_drop))
  end

  Lib.check Lib.ct_init(@ptr, @version), "ct_init failed"

  if block_given?
    begin
      yield self
    ensure
      exit
    end
  end
end

Instance Method Details

#callbacksObject



29
30
31
# File 'lib/sybase/context.rb', line 29

def callbacks
  @callbacks ||= Callbacks.new self
end

#exitObject



37
38
39
# File 'lib/sybase/context.rb', line 37

def exit
  Lib.check Lib.ct_exit(@ptr, CS_UNUSED), "ct_exit failed"
end

#sync=(bool) ⇒ Object



22
23
24
25
26
27
# File 'lib/sybase/context.rb', line 22

def sync=(bool)
  FFI::MemoryPointer.new(:int) do |ptr|
    ptr.write_int(bool ? CS_SYNC_IO : CS_ASYNC_IO) # CS_DEFER_IO ?
    Lib.check Lib.ct_config(@ptr, CS_SET, CS_NETIO, ptr, CS_UNUSED, nil)
  end
end

#to_ptrObject



33
34
35
# File 'lib/sybase/context.rb', line 33

def to_ptr
  @ptr
end