Class: Dde::Server

Inherits:
App
  • Object
show all
Defined in:
lib/dde/server.rb

Overview

Class encapsulates DDE Server with basic functionality (starting/stopping named service)

Direct Known Subclasses

XlServer

Instance Attribute Summary collapse

Attributes inherited from App

#id, #init_flags

Instance Method Summary collapse

Methods inherited from App

#dde_active?, #error, #initialize, #start_dde, #stop_dde, #try

Constructor Details

This class inherits a constructor from Dde::App

Instance Attribute Details

#serviceObject (readonly)

service(s) that this Server supports



6
7
8
# File 'lib/dde/server.rb', line 6

def service
  @service
end

Instance Method Details

#service_active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dde/server.rb', line 36

def service_active?
  !!@service
end

#start_service(name, init_flags = nil, &dde_callback) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dde/server.rb', line 8

def start_service( name, init_flags=nil, &dde_callback )
  try "Starting service #{name}", Dde::Errors::ServiceError do
    # Trying to start DDE if it was inactive
    error unless dde_active? || start_dde( init_flags, &dde_callback )

    # Create DDE string for name (this creates handle that can be passed to DDEML functions)
    @service = Dde::DdeString.new(@id, name)

    # Register new DDE service, returns true/false success code
    error unless dde_name_service(@id, @service.handle, DNS_REGISTER)
  end
end

#stop_serviceObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dde/server.rb', line 21

def stop_service
  try "Stopping active service", Dde::Errors::ServiceError do
    error "Either DDE or service not initialized" unless dde_active? && service_active?

    # Unregister DDE service, returns true/false success code
    error unless dde_name_service(@id, @service.handle, DNS_UNREGISTER);

    # Free string handle for service name
    error unless dde_free_string_handle(@id, @service.handle)

    # Clear handle if service successfuly stopped
    @service = nil
  end
end