win32-ipc 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES ADDED
@@ -0,0 +1,44 @@
1
+ == 0.5.0 - 30-Apr-2007
2
+ * Now pure Ruby.
3
+ * Ipc.new no longer accepts a block.
4
+ * Changed IpcError to Ipc::Error.
5
+ * Removed the 'doc' directory. The documentation is now inlined via rdoc.
6
+ * Added a gemspec.
7
+ * Added a Rakefile, including tasks for installation and testing.
8
+
9
+ == 0.4.1 - 23-Jan-2005
10
+ * Minor internal modifications for handling block arguments.
11
+
12
+ == 0.4.0 - 16-Dec-2004
13
+ * Changed the timeout from milliseconds to seconds. This wasn't documented,
14
+ and I'm guessing most people didn't know that they were passing milliseconds
15
+ instead of seconds. But, I've bumped the version number, just in case.
16
+
17
+ == 0.3.1 - 11-Dec-2004
18
+ * Fixed a bug in Ipc#wait where a segfault would occur if a block was not
19
+ provided.
20
+ * Moved the 'examples' directory to the toplevel directory.
21
+
22
+ == 0.3.0 - 31-Oct-2004
23
+ * The constructor now takes an optional block. Instance objects will call
24
+ that block if they are signaled.
25
+ * Added the 'block' method (read-only). Allows you to access the block
26
+ provided to the constructor.
27
+ * Modified the 'wait' instance method to take an optional block. This block
28
+ will be called if the object is signaled. Overrides the block to the
29
+ constructor for that instance object (only).
30
+ * Added the 'signaled?' instance method to indicate if the object is in the
31
+ signaled state or not.
32
+ * Modified all methods to raise an IpcError if an error occurs (instead of
33
+ simply returning nil).
34
+ * Added internal comments in order to make the code rdoc friendly, including
35
+ changes to the README file.
36
+
37
+ == 0.2.0 - 15-Jul-2004
38
+ * Updated to use the newer allocation framework. This means that as of
39
+ version 0.2.0, this package requires Ruby 1.8.0 or later.
40
+ * Moved the test.rb script to docs/examples.
41
+ * Minor code cleanup
42
+
43
+ == 0.1.0 - 30-Apr-2004
44
+ * Initial release
@@ -0,0 +1,7 @@
1
+ * CHANGES
2
+ * install.rb
3
+ * MANIFEST
4
+ * README
5
+ * win32-ipc.gemspec
6
+ * lib/win32/ipc.rb
7
+ * test/tc_ipc.rb
data/README ADDED
@@ -0,0 +1,34 @@
1
+ = Description
2
+ An abstract base class for Windows synchronization objects.
3
+
4
+ = Installation
5
+ rake test (optional)
6
+ rake install
7
+
8
+ = Synopsis
9
+ There is no synopsis. Don't use this module directly. It is used as the basis
10
+ for other packages, such as win32-mutex, etc.
11
+
12
+ = Notes
13
+ Based originally on the Win32::Ipc module by Gurusamy Sarathy.
14
+
15
+ This package is a prerequisite for several other IPC related Windows packages.
16
+
17
+ = Known Bugs
18
+ None that I know of. Please log any other bug reports on the RubyForge
19
+ project page at http://www.rubyforge.net/projects/win32utils
20
+
21
+ = License
22
+ Ruby's
23
+
24
+ = Copyright
25
+ (C) 2003-2007 Daniel J. Berger, All Rights Reserved
26
+
27
+ = Warranty
28
+ This package is provided "as is" and without any express or
29
+ implied warranties, including, without limitation, the implied
30
+ warranties of merchantability and fitness for a particular purpose.
31
+
32
+ = Authors
33
+ * Park Heesob
34
+ * Daniel J. Berger
@@ -0,0 +1,14 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Install the win32-ipc package (non-gem)'
5
+ task :install do
6
+ ruby 'install.rb'
7
+ end
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << 'test'
11
+ t.verbose = true
12
+ t.warning = true
13
+ t.test_files = FileList['test/tc_ipc.rb']
14
+ end
@@ -0,0 +1,11 @@
1
+ # For those who don't like gems...
2
+ require 'rbconfig'
3
+ require 'fileutils'
4
+ include Config
5
+
6
+ sitelibdir = CONFIG['sitelibdir']
7
+ installdir = sitelibdir + '/win32'
8
+ file = 'lib\win32\ipc.rb'
9
+
10
+ Dir.mkdir(installdir) unless File.exists?(installdir)
11
+ FileUtils.cp(file, installdir, :verbose => true)
@@ -0,0 +1,150 @@
1
+ require 'windows/error'
2
+ require 'windows/synchronize'
3
+ require 'windows/handle'
4
+
5
+ module Win32
6
+
7
+ # This is a an abstract base class for IPC related classes, such as
8
+ # Events and Semaphores.
9
+ #
10
+ class Ipc
11
+ include Windows::Error
12
+ include Windows::Synchronize
13
+ include Windows::Handle
14
+
15
+ class Error < StandardError; end
16
+
17
+ VERSION = '0.5.0'
18
+
19
+ SIGNALED = 1
20
+ ABANDONED = -1
21
+ TIMEOUT = 0
22
+
23
+ # The HANDLE object (an unsigned long value). Mostly provided for
24
+ # subclasses to use internally when needed.
25
+ #
26
+ attr_reader :handle
27
+
28
+ # Creates and returns a new IPC object. Since the IPC class is meant
29
+ # as an abstract base class, you should never call this method directly.
30
+ #
31
+ def initialize(handle)
32
+ @handle = handle
33
+ @signaled = false
34
+ end
35
+
36
+ # Closes the handle object provided in the constructor.
37
+ #
38
+ def close
39
+ CloseHandle(@handle)
40
+ end
41
+
42
+ # Returns whether or not the IPC object is in a signaled state.
43
+ #
44
+ def signaled?
45
+ @signaled
46
+ end
47
+
48
+ # call-seq:
49
+ # Ipc#wait(timeout)
50
+ # Ipc#wait(timeout){ block called when signaled }
51
+ #
52
+ # Waits for the calling object to be signaled. The +timeout+ value is
53
+ # the maximum time to wait, in seconds. A timeout of 0 returns
54
+ # immediately.
55
+ #
56
+ # Returns SIGNALED (1), ABANDONED (-1) or TIMEOUT (0). Raises an
57
+ # IPC::Error if the wait fails for some reason.
58
+ #
59
+ def wait(timeout = INFINITE)
60
+ timeout *= 1000 if timeout && timeout != INFINITE
61
+
62
+ wait = WaitForSingleObject(@handle, timeout)
63
+
64
+ case wait
65
+ when WAIT_FAILED
66
+ raise Error, get_last_error
67
+ when WAIT_OBJECT_0
68
+ @signaled = true
69
+ yield if block_given?
70
+ return SIGNALED
71
+ when WAIT_ABANDONED
72
+ return ABANDONED
73
+ when WAIT_TIMEOUT
74
+ return TIMEOUT
75
+ else
76
+ raise Error, get_last_error
77
+ end
78
+ end
79
+
80
+ # :call-seq:
81
+ # IPC#wait_any([ipc_objects], timeout = INFINITE)
82
+ #
83
+ # Waits for at least one of the +ipc_objects+ to be signaled. The
84
+ # +timeout+ value is maximum time to wait in seconds. A timeout of 0
85
+ # returns immediately.
86
+ #
87
+ # Returns the index+1 of the object that was signaled. If multiple
88
+ # objects are signaled, the one with the lowest index is returned.
89
+ # Returns 0 if no objects are signaled.
90
+ #
91
+ def wait_any(ipc_objects, timeout=INFINITE)
92
+ timeout *= 1000 if timeout && timeout != INFINITE
93
+ wait_for_multiple(ipc_objects, 0, timeout)
94
+ end
95
+
96
+ # :call-seq:
97
+ # IPC#wait_all([ipc_objects], timeout = INFINITE)
98
+ #
99
+ # Identical to IPC#wait_any, except that it waits for all +ipc_objects+
100
+ # to be signaled instead of just one.
101
+ #
102
+ # Returns the index of the last object signaled. If at least one of the
103
+ # objects is an abandoned mutex, the return value is negative.
104
+ #
105
+ def wait_all(ipc_objects, timeout=INFINITE)
106
+ timeout *= 1000 if timeout && timeout != INFINITE
107
+ wait_for_multiple(ipc_objects, 1, timeout)
108
+ end
109
+
110
+ private
111
+
112
+ # Waits until one or all (depending on the value of +wait_all+) of the
113
+ # +ipc_objects+ are in the signaled state or the +timeout+ interval
114
+ # elapses.
115
+ #
116
+ def wait_for_multiple(ipc_objects, wait_all=0, timeout=INFINITE)
117
+ unless ipc_objects.is_a?(Array)
118
+ msg = 'invalid argument - must be an array of Ipc objects'
119
+ raise TypeError, msg
120
+ end
121
+
122
+ length = ipc_objects.length
123
+
124
+ if length == 0
125
+ raise Error, 'no objects to wait for'
126
+ end
127
+
128
+ wait = WaitForMultipleObjects(length, ipc_objects, wait_all, timeout)
129
+
130
+ if wait == WAIT_FAILED
131
+ raise Error, get_last_error
132
+ end
133
+
134
+ # signaled
135
+ if (wait > WAIT_OBJECT_0) && (wait < WAIT_OBJECT_0 + length)
136
+ return wait - WAIT_OBJECT_0 + 1
137
+ end
138
+
139
+ # abandoned mutex - return negative value
140
+ if (wait >= WAIT_ABANDONED_0) && (wait < WAIT_ABANDONED_0 + length)
141
+ return -wait - WAIT_ABANDONED_0 + 1
142
+ end
143
+
144
+ # timed out
145
+ return 0 if wait == WAIT_TIMEOUT
146
+
147
+ nil
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,74 @@
1
+ ##########################################################################
2
+ # tc_ipc.rb
3
+ #
4
+ # Test case for the Win32::Ipc class. Note that this class is rather
5
+ # difficult to test directly since it is meant to be subclassed, not
6
+ # used directly.
7
+ #
8
+ # You should run this test via the 'rake test' task.
9
+ ##########################################################################
10
+ require 'win32/ipc'
11
+ require 'test/unit'
12
+ include Win32
13
+
14
+ class TC_Win32_Ipc < Test::Unit::TestCase
15
+ def setup
16
+ @ipc = Ipc.new(1)
17
+ end
18
+
19
+ def test_version
20
+ assert_equal('0.5.0', Ipc::VERSION)
21
+ end
22
+
23
+ def test_handle
24
+ assert_respond_to(@ipc, :handle)
25
+ assert_equal(1, @ipc.handle)
26
+ end
27
+
28
+ def test_signaled
29
+ assert_respond_to(@ipc, :signaled?)
30
+ assert_equal(false, @ipc.signaled?)
31
+ end
32
+
33
+ def test_wait
34
+ assert_respond_to(@ipc, :wait)
35
+ end
36
+
37
+ def test_wait_expected_errors
38
+ assert_raises(Ipc::Error){ @ipc.wait }
39
+ assert_raises(ArgumentError){ @ipc.wait(1,2) }
40
+ end
41
+
42
+ def test_wait_any
43
+ assert_respond_to(@ipc, :wait_any)
44
+ end
45
+
46
+ def test_wait_any_expected_errors
47
+ assert_raises(Ipc::Error){ @ipc.wait_any([]) }
48
+ assert_raises(TypeError){ @ipc.wait_any(1,2) }
49
+ end
50
+
51
+ def test_wait_all
52
+ assert_respond_to(@ipc, :wait_all)
53
+ end
54
+
55
+ def test_wait_all_expected_errors
56
+ assert_raises(Ipc::Error){ @ipc.wait_all([]) }
57
+ assert_raises(TypeError){ @ipc.wait_all(1,2) }
58
+ end
59
+
60
+ def test_close
61
+ assert_respond_to(@ipc, :close)
62
+ assert_nothing_raised{ @ipc.close }
63
+ end
64
+
65
+ def test_constants
66
+ assert_not_nil(Ipc::SIGNALED)
67
+ assert_not_nil(Ipc::ABANDONED)
68
+ assert_not_nil(Ipc::TIMEOUT)
69
+ end
70
+
71
+ def teardown
72
+ @ipc = nil
73
+ end
74
+ end
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+
3
+ spec = Gem::Specification.new do |gem|
4
+ gem.name = "win32-ipc"
5
+ gem.version = "0.5.0"
6
+ gem.author = "Daniel J. Berger"
7
+ gem.email = "djberg96@gmail.com"
8
+ gem.homepage = "http://www.rubyforge.org/projects/win32utils"
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.summary = "An abstract base class for Windows synchronization objects."
11
+ gem.description = "An abstract base class for Windows synchronization objects."
12
+ gem.test_file = "test/tc_ipc.rb"
13
+ gem.has_rdoc = true
14
+ gem.files = Dir["lib/win32/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
15
+ gem.files.reject! { |fn| fn.include? "CVS" }
16
+ gem.require_path = "lib"
17
+ gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
18
+ gem.add_dependency("windows-pr", ">= 0.6.0")
19
+ end
20
+
21
+ if $0 == __FILE__
22
+ Gem.manage_gems
23
+ Gem::Builder.new(spec).build
24
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0.8
3
+ specification_version: 1
4
+ name: win32-ipc
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.0
7
+ date: 2007-04-30 00:00:00 -06:00
8
+ summary: An abstract base class for Windows synchronization objects.
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/win32utils
13
+ rubyforge_project:
14
+ description: An abstract base class for Windows synchronization objects.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Daniel J. Berger
31
+ files:
32
+ - lib/win32/ipc.rb
33
+ - test/CVS
34
+ - test/tc_ipc.rb
35
+ - CHANGES
36
+ - CVS
37
+ - install.rb
38
+ - lib
39
+ - MANIFEST
40
+ - Rakefile
41
+ - README
42
+ - test
43
+ - win32-ipc.gemspec
44
+ test_files:
45
+ - test/tc_ipc.rb
46
+ rdoc_options: []
47
+
48
+ extra_rdoc_files:
49
+ - README
50
+ - CHANGES
51
+ - MANIFEST
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ requirements: []
57
+
58
+ dependencies:
59
+ - !ruby/object:Gem::Dependency
60
+ name: windows-pr
61
+ version_requirement:
62
+ version_requirements: !ruby/object:Gem::Version::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.6.0
67
+ version: