eventmachine-distributed-notification 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -2
- data/Rakefile +13 -11
- data/VERSION +1 -1
- data/examples/client.rb +11 -0
- data/examples/server.rb +7 -0
- data/ext/poster_native/extconf.rb +14 -0
- data/ext/poster_native/poster_native.h +2 -0
- data/ext/poster_native/poster_native.m +55 -0
- data/lib/eventmachine-distributed-notification.rb +17 -0
- data/spec/eventmachine-distributed-notification_spec.rb +17 -1
- metadata +20 -14
data/README.rdoc
CHANGED
@@ -9,8 +9,6 @@ An {EventMachine}[http://wiki.github.com/eventmachine/eventmachine/] extension t
|
|
9
9
|
=== Watch Notification
|
10
10
|
|
11
11
|
class Watcher < EM::DistributedNotificationWatch
|
12
|
-
attr_accessor :value
|
13
|
-
|
14
12
|
def notify(name, user_info)
|
15
13
|
puts 'now playing %s' % [user_info['Artist'], user_info['Name']].join(' - ')
|
16
14
|
end
|
@@ -20,6 +18,12 @@ An {EventMachine}[http://wiki.github.com/eventmachine/eventmachine/] extension t
|
|
20
18
|
EM.watch_distributed_notification('com.apple.iTunes.playerInfo', Watcher)
|
21
19
|
}
|
22
20
|
|
21
|
+
=== Post Notification
|
22
|
+
|
23
|
+
EM.run {
|
24
|
+
EM.post_distributed_notification('com.buycheapviagraonlinenow.xxx', 'data')
|
25
|
+
}
|
26
|
+
|
23
27
|
== Contributing to eventmachine-distributed-notification
|
24
28
|
|
25
29
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/Rakefile
CHANGED
@@ -27,19 +27,21 @@ end
|
|
27
27
|
# rule to build the extension: this says
|
28
28
|
# that the extension should be rebuilt
|
29
29
|
# after any change to the files in ext
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
ext_names = %w/observer_native poster_native/
|
31
|
+
ext_names.each do |ext_name|
|
32
|
+
file "lib/#{ext_name}.bundle" =>
|
33
|
+
Dir.glob("ext/#{ext_name}/*{.rb,.m}") do
|
34
|
+
Dir.chdir("ext/#{ext_name}") do
|
35
|
+
# this does essentially the same thing
|
36
|
+
# as what RubyGems does
|
37
|
+
ruby "extconf.rb"
|
38
|
+
sh "make"
|
39
|
+
end
|
40
|
+
cp "ext/#{ext_name}/#{ext_name}.bundle", "lib/"
|
38
41
|
end
|
39
|
-
cp "ext/#{ext_name}/#{ext_name}.bundle", "lib/"
|
40
|
-
end
|
41
42
|
|
42
|
-
task :spec => "lib/#{ext_name}.bundle"
|
43
|
+
task :spec => "lib/#{ext_name}.bundle"
|
44
|
+
end
|
43
45
|
|
44
46
|
Jeweler::RubygemsDotOrgTasks.new
|
45
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/examples/client.rb
ADDED
data/examples/server.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
# Name your extension
|
4
|
+
extension_name = 'poster_native'
|
5
|
+
|
6
|
+
# Set your target name
|
7
|
+
dir_config(extension_name)
|
8
|
+
|
9
|
+
$LDFLAGS += ' -framework CoreFoundation -framework CoreServices'
|
10
|
+
|
11
|
+
have_header(extension_name)
|
12
|
+
|
13
|
+
# Do the work
|
14
|
+
create_makefile(extension_name)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#import "poster_native.h"
|
2
|
+
|
3
|
+
static VALUE rb_cPosterNative;
|
4
|
+
|
5
|
+
struct PosterObject {
|
6
|
+
};
|
7
|
+
|
8
|
+
void cPosterNative_free(void *ptr) {
|
9
|
+
free(ptr);
|
10
|
+
}
|
11
|
+
|
12
|
+
VALUE createInstance() {
|
13
|
+
struct PosterObject *obj;
|
14
|
+
|
15
|
+
obj = malloc(sizeof(struct PosterObject));
|
16
|
+
|
17
|
+
return Data_Wrap_Struct(rb_cPosterNative, 0, cPosterNative_free, obj);
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE cPosterNative_new(int argc, VALUE *argv, VALUE klass)
|
21
|
+
{
|
22
|
+
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
23
|
+
|
24
|
+
return createInstance();
|
25
|
+
}
|
26
|
+
|
27
|
+
static VALUE cPosterNative_post(int argc, VALUE *argv, VALUE self)
|
28
|
+
{
|
29
|
+
VALUE name, data;
|
30
|
+
NSDictionary *userInfo;
|
31
|
+
|
32
|
+
rb_scan_args(argc, argv, "2", &name, &data);
|
33
|
+
|
34
|
+
userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithUTF8String:StringValuePtr(data)] forKey:@"data"];
|
35
|
+
|
36
|
+
[[NSDistributedNotificationCenter defaultCenter]
|
37
|
+
postNotificationName:[NSString stringWithUTF8String:StringValuePtr(name)]
|
38
|
+
object:nil
|
39
|
+
userInfo:userInfo
|
40
|
+
deliverImmediately:YES];
|
41
|
+
|
42
|
+
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
43
|
+
|
44
|
+
return Qnil;
|
45
|
+
}
|
46
|
+
|
47
|
+
void Init_poster_native(void){
|
48
|
+
VALUE rb_mEventMachine, rb_mDistributedNotification;
|
49
|
+
|
50
|
+
rb_mEventMachine = rb_define_module("EventMachine");
|
51
|
+
rb_mDistributedNotification = rb_define_module_under(rb_mEventMachine, "DistributedNotification");
|
52
|
+
rb_cPosterNative = rb_define_class_under(rb_mDistributedNotification, "PosterNative", rb_cObject);
|
53
|
+
rb_define_singleton_method(rb_cPosterNative, "new", cPosterNative_new, -1);
|
54
|
+
rb_define_method(rb_cPosterNative, "post", cPosterNative_post, -1);
|
55
|
+
}
|
@@ -1,7 +1,20 @@
|
|
1
1
|
require 'eventmachine'
|
2
2
|
require 'observer_native'
|
3
|
+
require 'poster_native'
|
3
4
|
|
4
5
|
module EventMachine
|
6
|
+
module DistributedNotification
|
7
|
+
class Poster
|
8
|
+
def initialize
|
9
|
+
@poster = PosterNative.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(name, data)
|
13
|
+
@poster.post(name, data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
5
18
|
class DistributedNotificationWatch
|
6
19
|
def initialize(name)
|
7
20
|
@observer = DistributedNotification::ObserverNative.new(name, self)
|
@@ -28,4 +41,8 @@ module EventMachine
|
|
28
41
|
c.start
|
29
42
|
c
|
30
43
|
end
|
44
|
+
|
45
|
+
def self.post_distributed_notification(name, data)
|
46
|
+
DistributedNotification::Poster.new.post(name, data)
|
47
|
+
end
|
31
48
|
end
|
@@ -10,7 +10,23 @@ class Watcher < EM::DistributedNotificationWatch
|
|
10
10
|
|
11
11
|
def notify(name, user_info)
|
12
12
|
@value = name
|
13
|
-
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe EventMachine::DistributedNotification::Poster do
|
17
|
+
it 'should post distributed notifications' do
|
18
|
+
watcher = Watcher.new('xxx')
|
19
|
+
|
20
|
+
EM.run {
|
21
|
+
watcher.start
|
22
|
+
|
23
|
+
EM::add_timer(1) {
|
24
|
+
EM::post_distributed_notification('xxx', 'yyy')
|
25
|
+
EM.stop
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
watcher.value.should_not be_nil
|
14
30
|
end
|
15
31
|
end
|
16
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventmachine-distributed-notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70185138676260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70185138676260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70185138674940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.8.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70185138674940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc
|
38
|
-
requirement: &
|
38
|
+
requirement: &70185138673060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.12'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70185138673060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70185138684820 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.1.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70185138684820
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70185138682440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.8.3
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70185138682440
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rb-appscript
|
71
|
-
requirement: &
|
71
|
+
requirement: &70185138681200 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,13 +76,14 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70185138681200
|
80
80
|
description: An EventMachine extension to watch OSX's Distributed Notification, posted
|
81
81
|
by iTunes etc.
|
82
82
|
email: youpy@buycheapviagraonlinenow.com
|
83
83
|
executables: []
|
84
84
|
extensions:
|
85
85
|
- ext/observer_native/extconf.rb
|
86
|
+
- ext/poster_native/extconf.rb
|
86
87
|
extra_rdoc_files:
|
87
88
|
- LICENSE.txt
|
88
89
|
- README.rdoc
|
@@ -95,10 +96,15 @@ files:
|
|
95
96
|
- README.rdoc
|
96
97
|
- Rakefile
|
97
98
|
- VERSION
|
99
|
+
- examples/client.rb
|
100
|
+
- examples/server.rb
|
98
101
|
- ext/observer_native/compat.h
|
99
102
|
- ext/observer_native/extconf.rb
|
100
103
|
- ext/observer_native/observer_native.h
|
101
104
|
- ext/observer_native/observer_native.m
|
105
|
+
- ext/poster_native/extconf.rb
|
106
|
+
- ext/poster_native/poster_native.h
|
107
|
+
- ext/poster_native/poster_native.m
|
102
108
|
- lib/eventmachine-distributed-notification.rb
|
103
109
|
- spec/eventmachine-distributed-notification_spec.rb
|
104
110
|
- spec/spec_helper.rb
|
@@ -117,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
123
|
version: '0'
|
118
124
|
segments:
|
119
125
|
- 0
|
120
|
-
hash:
|
126
|
+
hash: -3278988449120356185
|
121
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
128
|
none: false
|
123
129
|
requirements:
|