Class: Dde::App

Inherits:
Object
  • Object
show all
Includes:
Win::Dde
Defined in:
lib/dde/app.rb

Overview

Class encapsulates DDE application. Dde::App serves as a base for more specific types,

such as Dde::Server or Dde

Client.

Direct Known Subclasses

Client, Monitor, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_flags = nil, &dde_callback) ⇒ App

Creates new DDE application (and starts DDE instance if dde_callback block is attached)



28
29
30
31
32
33
# File 'lib/dde/app.rb', line 28

def initialize( init_flags=nil, &dde_callback )
  @init_flags = init_flags

  start_dde init_flags, &dde_callback if dde_callback

end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



25
26
27
# File 'lib/dde/app.rb', line 25

def id
  @id
end

#init_flagsObject (readonly)

Returns the value of attribute init_flags.



25
26
27
# File 'lib/dde/app.rb', line 25

def init_flags
  @init_flags
end

Instance Method Details

#dde_active?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/dde/app.rb', line 87

def dde_active?
  !!@id
end

#error(message = nil) ⇒ Object

Raises Runtime error with message based on given message (DdeGetLastError message if no message given)



76
77
78
79
80
81
82
83
84
85
# File 'lib/dde/app.rb', line 76

def error( message = nil )
  raise case message
    when Integer
      Dde::Errors[message]
    when nil
      Dde::Errors[dde_get_last_error(@id)]
    else
      message
  end
end

#start_dde(init_flags = nil, &dde_callback) ⇒ Object

(Re)Initialize application with DDEML library, providing attached dde callback either preserved @init_flags or init_flags argument are used



46
47
48
49
50
51
52
53
# File 'lib/dde/app.rb', line 46

def start_dde( init_flags=nil, &dde_callback )
  @init_flags = init_flags || @init_flags || APPCLASS_STANDARD

  try "Starting DDE" do
    @id, status = dde_initialize @id, @init_flags, &dde_callback
    error(status) unless @id && status == DMLERR_NO_ERROR
  end
end

#stop_ddeObject

(Re)Initialize application with DDEML library, providing attached dde callback



56
57
58
59
60
61
62
# File 'lib/dde/app.rb', line 56

def stop_dde
  try "Stopping DDE" do
    error "DDE not started" unless dde_active?
    error unless dde_uninitialize(@id)   # Uninitialize app with DDEML library
    @id = nil                                 # Clear instance id if uninitialization successful
  end
end

#try(action, error_type = Dde::Errors::InitError) ⇒ Object

Expects a block, yields to it inside a rescue block, raises given error_type with extended fail message. Returns self in case of success (to enable method chaining).



66
67
68
69
70
71
72
73
# File 'lib/dde/app.rb', line 66

def try( action, error_type=Dde::Errors::InitError )
  begin
    yield
  rescue => e
    raise error_type, action + " failed with: #{e}"
  end
  self
end