flotype-bridge 0.1.0.beta.2 → 0.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.md +27 -4
- data/doc/Bridge/Bridge.html +624 -0
- data/doc/Bridge.html +72 -903
- data/doc/created.rid +2 -1
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +56 -56
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +5 -3
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +70 -0
- data/examples/chat/chat_client.rb +15 -35
- data/examples/chat/chat_server.rb +21 -21
- data/examples/chat/public/css/style.css +4 -0
- data/examples/chat/public/js/all.js +5 -0
- data/examples/chat/public/js/bridge.min.js +2 -0
- data/examples/chat/public/js/index.js +14 -0
- data/examples/chat/views/index.erb +5 -0
- data/examples/chat/views/layout.erb +23 -0
- data/flotype-bridge.gemspec +1 -1
- data/lib/bridge.rb +253 -106
- data/lib/connection.rb +161 -0
- data/lib/reference.rb +49 -0
- data/lib/serializer.rb +97 -0
- data/lib/tcp.rb +61 -0
- data/lib/util.rb +101 -0
- data/lib/version.rb +3 -0
- data/test/regression/reconnect.rb +48 -0
- data/test/regression/rpc.rb +39 -0
- data/test/regression/test.rb +58 -0
- data/test/unit/bridge_dummy.rb +26 -0
- data/test/unit/connection_dummy.rb +21 -0
- data/test/unit/reference_dummy.rb +11 -0
- data/test/unit/tcp_dummy.rb +12 -0
- data/test/unit/test.rb +20 -0
- data/test/unit/test_reference.rb +30 -0
- data/test/unit/test_serializer.rb +109 -0
- data/test/unit/test_tcp.rb +51 -0
- data/test/unit/test_util.rb +59 -0
- metadata +106 -136
- data/doc/Bridge/Callback.html +0 -495
- data/doc/Bridge/CallbackRef.html +0 -343
- data/doc/Bridge/Conn.html +0 -409
- data/doc/Bridge/Core.html +0 -762
- data/doc/Bridge/LocalRef.html +0 -509
- data/doc/Bridge/Ref.html +0 -647
- data/doc/Bridge/Service.html +0 -135
- data/doc/Bridge/Sys.html +0 -278
- data/doc/Bridge/Util.html +0 -746
- data/doc/_index.html +0 -202
- data/doc/class_list.html +0 -47
- data/doc/classes/Bridge.html +0 -263
- data/doc/classes/Bridge.src/M000001.html +0 -24
- data/doc/classes/Bridge.src/M000002.html +0 -18
- data/doc/classes/Bridge.src/M000003.html +0 -18
- data/doc/classes/Bridge.src/M000004.html +0 -20
- data/doc/classes/Bridge.src/M000005.html +0 -26
- data/doc/classes/Bridge.src/M000006.html +0 -22
- data/doc/classes/Bridge.src/M000007.html +0 -18
- data/doc/classes/Bridge.src/M000008.html +0 -18
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -55
- data/doc/css/style.css +0 -322
- data/doc/file.README.html +0 -71
- data/doc/file_list.html +0 -49
- data/doc/files/lib/bridge_rb.html +0 -108
- data/doc/fr_class_index.html +0 -27
- data/doc/fr_file_index.html +0 -27
- data/doc/fr_method_index.html +0 -34
- data/doc/frames.html +0 -13
- data/doc/js/app.js +0 -205
- data/doc/js/full_list.js +0 -173
- data/doc/method_list.html +0 -510
- data/doc/rdoc-style.css +0 -208
- data/doc/top-level-namespace.html +0 -105
- data/lib/bb/callback.rb +0 -33
- data/lib/bb/conn.rb +0 -31
- data/lib/bb/core.rb +0 -109
- data/lib/bb/localref.rb +0 -37
- data/lib/bb/ref.rb +0 -49
- data/lib/bb/svc.rb +0 -7
- data/lib/bb/sys.rb +0 -17
- data/lib/bb/util.rb +0 -93
- data/lib/bb/version.rb +0 -3
- data/tests/bb_test_helper.rb +0 -3
- data/tests/test_serialize.rb +0 -4
data/doc/rdoc-style.css
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
|
2
|
-
body {
|
3
|
-
font-family: Verdana,Arial,Helvetica,sans-serif;
|
4
|
-
font-size: 90%;
|
5
|
-
margin: 0;
|
6
|
-
margin-left: 40px;
|
7
|
-
padding: 0;
|
8
|
-
background: white;
|
9
|
-
}
|
10
|
-
|
11
|
-
h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
|
12
|
-
h1 { font-size: 150%; }
|
13
|
-
h2,h3,h4 { margin-top: 1em; }
|
14
|
-
|
15
|
-
a { background: #eef; color: #039; text-decoration: none; }
|
16
|
-
a:hover { background: #039; color: #eef; }
|
17
|
-
|
18
|
-
/* Override the base stylesheet's Anchor inside a table cell */
|
19
|
-
td > a {
|
20
|
-
background: transparent;
|
21
|
-
color: #039;
|
22
|
-
text-decoration: none;
|
23
|
-
}
|
24
|
-
|
25
|
-
/* and inside a section title */
|
26
|
-
.section-title > a {
|
27
|
-
background: transparent;
|
28
|
-
color: #eee;
|
29
|
-
text-decoration: none;
|
30
|
-
}
|
31
|
-
|
32
|
-
/* === Structural elements =================================== */
|
33
|
-
|
34
|
-
div#index {
|
35
|
-
margin: 0;
|
36
|
-
margin-left: -40px;
|
37
|
-
padding: 0;
|
38
|
-
font-size: 90%;
|
39
|
-
}
|
40
|
-
|
41
|
-
|
42
|
-
div#index a {
|
43
|
-
margin-left: 0.7em;
|
44
|
-
}
|
45
|
-
|
46
|
-
div#index .section-bar {
|
47
|
-
margin-left: 0px;
|
48
|
-
padding-left: 0.7em;
|
49
|
-
background: #ccc;
|
50
|
-
font-size: small;
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
div#classHeader, div#fileHeader {
|
55
|
-
width: auto;
|
56
|
-
color: white;
|
57
|
-
padding: 0.5em 1.5em 0.5em 1.5em;
|
58
|
-
margin: 0;
|
59
|
-
margin-left: -40px;
|
60
|
-
border-bottom: 3px solid #006;
|
61
|
-
}
|
62
|
-
|
63
|
-
div#classHeader a, div#fileHeader a {
|
64
|
-
background: inherit;
|
65
|
-
color: white;
|
66
|
-
}
|
67
|
-
|
68
|
-
div#classHeader td, div#fileHeader td {
|
69
|
-
background: inherit;
|
70
|
-
color: white;
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
div#fileHeader {
|
75
|
-
background: #057;
|
76
|
-
}
|
77
|
-
|
78
|
-
div#classHeader {
|
79
|
-
background: #048;
|
80
|
-
}
|
81
|
-
|
82
|
-
|
83
|
-
.class-name-in-header {
|
84
|
-
font-size: 180%;
|
85
|
-
font-weight: bold;
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
div#bodyContent {
|
90
|
-
padding: 0 1.5em 0 1.5em;
|
91
|
-
}
|
92
|
-
|
93
|
-
div#description {
|
94
|
-
padding: 0.5em 1.5em;
|
95
|
-
background: #efefef;
|
96
|
-
border: 1px dotted #999;
|
97
|
-
}
|
98
|
-
|
99
|
-
div#description h1,h2,h3,h4,h5,h6 {
|
100
|
-
color: #125;;
|
101
|
-
background: transparent;
|
102
|
-
}
|
103
|
-
|
104
|
-
div#validator-badges {
|
105
|
-
text-align: center;
|
106
|
-
}
|
107
|
-
div#validator-badges img { border: 0; }
|
108
|
-
|
109
|
-
div#copyright {
|
110
|
-
color: #333;
|
111
|
-
background: #efefef;
|
112
|
-
font: 0.75em sans-serif;
|
113
|
-
margin-top: 5em;
|
114
|
-
margin-bottom: 0;
|
115
|
-
padding: 0.5em 2em;
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
/* === Classes =================================== */
|
120
|
-
|
121
|
-
table.header-table {
|
122
|
-
color: white;
|
123
|
-
font-size: small;
|
124
|
-
}
|
125
|
-
|
126
|
-
.type-note {
|
127
|
-
font-size: small;
|
128
|
-
color: #DEDEDE;
|
129
|
-
}
|
130
|
-
|
131
|
-
.xxsection-bar {
|
132
|
-
background: #eee;
|
133
|
-
color: #333;
|
134
|
-
padding: 3px;
|
135
|
-
}
|
136
|
-
|
137
|
-
.section-bar {
|
138
|
-
color: #333;
|
139
|
-
border-bottom: 1px solid #999;
|
140
|
-
margin-left: -20px;
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
.section-title {
|
145
|
-
background: #79a;
|
146
|
-
color: #eee;
|
147
|
-
padding: 3px;
|
148
|
-
margin-top: 2em;
|
149
|
-
margin-left: -30px;
|
150
|
-
border: 1px solid #999;
|
151
|
-
}
|
152
|
-
|
153
|
-
.top-aligned-row { vertical-align: top }
|
154
|
-
.bottom-aligned-row { vertical-align: bottom }
|
155
|
-
|
156
|
-
/* --- Context section classes ----------------------- */
|
157
|
-
|
158
|
-
.context-row { }
|
159
|
-
.context-item-name { font-family: monospace; font-weight: bold; color: black; }
|
160
|
-
.context-item-value { font-size: small; color: #448; }
|
161
|
-
.context-item-desc { color: #333; padding-left: 2em; }
|
162
|
-
|
163
|
-
/* --- Method classes -------------------------- */
|
164
|
-
.method-detail {
|
165
|
-
background: #efefef;
|
166
|
-
padding: 0;
|
167
|
-
margin-top: 0.5em;
|
168
|
-
margin-bottom: 1em;
|
169
|
-
border: 1px dotted #ccc;
|
170
|
-
}
|
171
|
-
.method-heading {
|
172
|
-
color: black;
|
173
|
-
background: #ccc;
|
174
|
-
border-bottom: 1px solid #666;
|
175
|
-
padding: 0.2em 0.5em 0 0.5em;
|
176
|
-
}
|
177
|
-
.method-signature { color: black; background: inherit; }
|
178
|
-
.method-name { font-weight: bold; }
|
179
|
-
.method-args { font-style: italic; }
|
180
|
-
.method-description { padding: 0 0.5em 0 0.5em; }
|
181
|
-
|
182
|
-
/* --- Source code sections -------------------- */
|
183
|
-
|
184
|
-
a.source-toggle { font-size: 90%; }
|
185
|
-
div.method-source-code {
|
186
|
-
background: #262626;
|
187
|
-
color: #ffdead;
|
188
|
-
margin: 1em;
|
189
|
-
padding: 0.5em;
|
190
|
-
border: 1px dashed #999;
|
191
|
-
overflow: hidden;
|
192
|
-
}
|
193
|
-
|
194
|
-
div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
195
|
-
|
196
|
-
/* --- Ruby keyword styles --------------------- */
|
197
|
-
|
198
|
-
.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
|
199
|
-
|
200
|
-
.ruby-constant { color: #7fffd4; background: transparent; }
|
201
|
-
.ruby-keyword { color: #00ffff; background: transparent; }
|
202
|
-
.ruby-ivar { color: #eedd82; background: transparent; }
|
203
|
-
.ruby-operator { color: #00ffee; background: transparent; }
|
204
|
-
.ruby-identifier { color: #ffdead; background: transparent; }
|
205
|
-
.ruby-node { color: #ffa07a; background: transparent; }
|
206
|
-
.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
|
207
|
-
.ruby-regexp { color: #ffa07a; background: transparent; }
|
208
|
-
.ruby-value { color: #7fffd4; background: transparent; }
|
@@ -1,105 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
-
<title>
|
7
|
-
Top Level Namespace
|
8
|
-
|
9
|
-
— Documentation by YARD 0.7.5
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
relpath = '';
|
19
|
-
if (relpath != '') relpath += '/';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
|
-
|
24
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
25
|
-
|
26
|
-
|
27
|
-
</head>
|
28
|
-
<body>
|
29
|
-
<script type="text/javascript" charset="utf-8">
|
30
|
-
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
-
</script>
|
32
|
-
|
33
|
-
<div id="header">
|
34
|
-
<div id="menu">
|
35
|
-
|
36
|
-
<a href="_index.html">Index</a> »
|
37
|
-
|
38
|
-
|
39
|
-
<span class="title">Top Level Namespace</span>
|
40
|
-
|
41
|
-
|
42
|
-
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
-
</div>
|
44
|
-
|
45
|
-
<div id="search">
|
46
|
-
|
47
|
-
<a id="class_list_link" href="#">Class List</a>
|
48
|
-
|
49
|
-
<a id="method_list_link" href="#">Method List</a>
|
50
|
-
|
51
|
-
<a id="file_list_link" href="#">File List</a>
|
52
|
-
|
53
|
-
</div>
|
54
|
-
<div class="clear"></div>
|
55
|
-
</div>
|
56
|
-
|
57
|
-
<iframe id="search_frame"></iframe>
|
58
|
-
|
59
|
-
<div id="content"><h1>Top Level Namespace
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
</h1>
|
64
|
-
|
65
|
-
<dl class="box">
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
</dl>
|
75
|
-
<div class="clear"></div>
|
76
|
-
|
77
|
-
<h2>Defined Under Namespace</h2>
|
78
|
-
<p class="children">
|
79
|
-
|
80
|
-
|
81
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Bridge.html" title="Bridge (module)">Bridge</a></span>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
</p>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
</div>
|
97
|
-
|
98
|
-
<div id="footer">
|
99
|
-
Generated on Sun Mar 4 11:14:11 2012 by
|
100
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
101
|
-
0.7.5 (ruby-1.8.7).
|
102
|
-
</div>
|
103
|
-
|
104
|
-
</body>
|
105
|
-
</html>
|
data/lib/bb/callback.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
# Wrapper for callbacks passed in as arguments.
|
3
|
-
class Callback
|
4
|
-
def initialize fun
|
5
|
-
@fun = fun
|
6
|
-
end
|
7
|
-
|
8
|
-
def callback *args
|
9
|
-
@fun.call *args
|
10
|
-
end
|
11
|
-
|
12
|
-
def call *args
|
13
|
-
@fun.call(*call)
|
14
|
-
end
|
15
|
-
|
16
|
-
def method atom
|
17
|
-
if atom.to_s == 'callback'
|
18
|
-
@fun
|
19
|
-
else
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def methods bool
|
25
|
-
[:callback]
|
26
|
-
end
|
27
|
-
|
28
|
-
def respond_to? atom
|
29
|
-
atom = atom.to_s
|
30
|
-
atom == 'call' || atom == 'to_json'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/bb/conn.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
module Conn
|
3
|
-
def self.send arg
|
4
|
-
Util::log 'sending: ' + arg
|
5
|
-
@@conn.send_data arg
|
6
|
-
end
|
7
|
-
|
8
|
-
# Methods expected by EventMachine.
|
9
|
-
def initialize
|
10
|
-
Util::log 'Connection initialized.'
|
11
|
-
@@conn = self
|
12
|
-
end
|
13
|
-
|
14
|
-
def post_init
|
15
|
-
Util::log 'Starting handshake.'
|
16
|
-
Core::command(:CONNECT,
|
17
|
-
{ :session => Core::session,
|
18
|
-
:api_key => Bridge::options['api_key'] })
|
19
|
-
end
|
20
|
-
|
21
|
-
def receive_data data
|
22
|
-
Util::log 'Got data.'
|
23
|
-
Core::process(data)
|
24
|
-
end
|
25
|
-
|
26
|
-
def unbind
|
27
|
-
Util::log 'Disconnected.'
|
28
|
-
Core::disconnect
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/bb/core.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
# The internals of the Bridge client. Use of this module is strongly
|
3
|
-
# unadvised, as the internal structure may vary greatly from that of
|
4
|
-
# other language implementations.
|
5
|
-
module Core
|
6
|
-
@@services, @@queue, @@sess = {'["system"]' => Bridge::Sys}, [], [nil, nil]
|
7
|
-
@@connected, @@len, @@buffer = false, 0, ''
|
8
|
-
|
9
|
-
def self.session
|
10
|
-
@@sess
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.client_id
|
14
|
-
@@sess[0]
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.connected
|
18
|
-
@@connected
|
19
|
-
end
|
20
|
-
|
21
|
-
# The queue is used primarily for Bridge::ready() callbacks.
|
22
|
-
def self.enqueue fun
|
23
|
-
if @@connected
|
24
|
-
fun.call
|
25
|
-
else
|
26
|
-
@@queue = @@queue + [fun]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.store svc, obj = nil, named = true
|
31
|
-
@@services[[named ? svc : "channel:#{svc}"].to_json] = obj
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.lookup ref
|
35
|
-
Util::log 'Looking up ref ' + ref.to_json
|
36
|
-
ref = JSON::parse ref.to_json
|
37
|
-
svc = @@services[ref[2 .. -1].to_json] || @@services[[ref[2]].to_json]
|
38
|
-
if svc != nil
|
39
|
-
if ref[3] != nil
|
40
|
-
svc.method(ref[3])
|
41
|
-
else
|
42
|
-
svc
|
43
|
-
end
|
44
|
-
else
|
45
|
-
Ref.lookup ref
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.process data
|
50
|
-
if @@len == 0
|
51
|
-
@@len = data.unpack('N')[0]
|
52
|
-
return process data[4 .. -1]
|
53
|
-
end
|
54
|
-
Util::log ':::: ' + data
|
55
|
-
(@@buffer << data)
|
56
|
-
if @@buffer.length < @@len
|
57
|
-
return
|
58
|
-
end
|
59
|
-
data = @@buffer
|
60
|
-
@@buffer, @@len = @@buffer[@@len .. -1], 0
|
61
|
-
# If this is the first message, set our SessionId and Secret.
|
62
|
-
m = /^(\w+)\|(\w+)$/.match data
|
63
|
-
if m
|
64
|
-
@@connected = true
|
65
|
-
@@sess = [m[1], m[2]]
|
66
|
-
Util::log "Received secret and session ID: #{@@sess.to_json}"
|
67
|
-
@@queue.each {|fun|
|
68
|
-
fun.call
|
69
|
-
}
|
70
|
-
@@queue = []
|
71
|
-
return
|
72
|
-
end
|
73
|
-
# Else, it is a normal message.
|
74
|
-
unser = Util::unserialize data
|
75
|
-
dest = unser['destination']
|
76
|
-
if dest.respond_to? :call
|
77
|
-
dest.call *unser['args']
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.command cmd, data
|
82
|
-
if cmd == :CONNECT
|
83
|
-
Conn::send(Util::serialize({:command => cmd, :data => data}))
|
84
|
-
else
|
85
|
-
Core::enqueue lambda {
|
86
|
-
Conn::send(Util::serialize({:command => cmd, :data => data}))
|
87
|
-
}
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.reconnect timeout
|
92
|
-
opts = Bridge::options
|
93
|
-
if opts[:reconnect]
|
94
|
-
Util::log "Attempting to reconnect; waiting at most #{timeout.to_s}s."
|
95
|
-
EventMachine::connect(opts[:host], opts[:port], Conn)
|
96
|
-
EventMachine::Timer.new(timeout) do
|
97
|
-
if not @@connected
|
98
|
-
reconnect timeout * 2
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.disconnect
|
105
|
-
@@connected = false
|
106
|
-
reconnect 0.1
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/lib/bb/localref.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
# Wrapper for callbacks passed in as arguments.
|
3
|
-
class LocalRef < Ref
|
4
|
-
def initialize path, mod
|
5
|
-
@mod = mod
|
6
|
-
path = ['client', lambda {Core::client_id}] + path
|
7
|
-
super(path)
|
8
|
-
end
|
9
|
-
|
10
|
-
def method_missing atom, *args, &blk
|
11
|
-
(@mod.method atom).call *args
|
12
|
-
end
|
13
|
-
|
14
|
-
def method atom
|
15
|
-
@mod.method(atom)
|
16
|
-
end
|
17
|
-
|
18
|
-
def operations bool
|
19
|
-
@mod.methods(bool)
|
20
|
-
end
|
21
|
-
|
22
|
-
def call *args
|
23
|
-
@mod.call *args
|
24
|
-
end
|
25
|
-
|
26
|
-
def respond_to? atom
|
27
|
-
@mod.respond_to? atom
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_json *a
|
31
|
-
if @path[1].respond_to? :call
|
32
|
-
@path[1] = @path[1].call
|
33
|
-
end
|
34
|
-
{:ref => @path, :operations => @mod.methods(false)}.to_json *a
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/bb/ref.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
# Instances of this class represent references to remote services.
|
3
|
-
class Ref
|
4
|
-
@@refs = {}
|
5
|
-
|
6
|
-
def self.lookup ref
|
7
|
-
key = ref[2 .. -1].to_json
|
8
|
-
if @@refs[key] == nil
|
9
|
-
@@refs[key] = Ref.new(ref)
|
10
|
-
end
|
11
|
-
@@refs[key]
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize path
|
15
|
-
@path = path
|
16
|
-
@@refs[path[2 .. -1].to_json] = self
|
17
|
-
end
|
18
|
-
|
19
|
-
def path
|
20
|
-
@path
|
21
|
-
end
|
22
|
-
|
23
|
-
def method_missing atom, *args, &blk
|
24
|
-
Core::lookup(@path + [atom]).call *args
|
25
|
-
end
|
26
|
-
|
27
|
-
def method atom
|
28
|
-
Core::lookup(@path + [atom])
|
29
|
-
end
|
30
|
-
|
31
|
-
def call *args
|
32
|
-
Core::command :SEND, {
|
33
|
-
:destination => {:ref => @path},
|
34
|
-
:args => Util::inflate(args)
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def respond_to? atom
|
39
|
-
true
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_json *a
|
43
|
-
if @path[1].respond_to? :call
|
44
|
-
@path[1] = @path[1].call
|
45
|
-
end
|
46
|
-
{:ref => @path}.to_json *a
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/bb/svc.rb
DELETED
data/lib/bb/sys.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Bridge
|
2
|
-
# These are internal system functions, which should only be called by the
|
3
|
-
# Erlang gateway.
|
4
|
-
module Sys
|
5
|
-
def self.hook_channel_handler name, handler, fun
|
6
|
-
fun.call(Core::store(name, handler, 'channel'))
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.remoteError msg
|
10
|
-
Util::err(msg)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get_service name, fun
|
14
|
-
fun.call(Core::lookup(name).methods(false))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/bb/util.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Bridge
|
4
|
-
module Util
|
5
|
-
# Traverses an object, replacing funs with refs.
|
6
|
-
def self.inflate obj
|
7
|
-
if obj.is_a?(Array)
|
8
|
-
obj.map do |v|
|
9
|
-
Util::bloat v
|
10
|
-
end
|
11
|
-
else
|
12
|
-
o = {}
|
13
|
-
obj.each do |k, v|
|
14
|
-
o[k] = Util::bloat v
|
15
|
-
end
|
16
|
-
o
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.bloat v
|
21
|
-
if v.is_a?(Module) || v.is_a?(Bridge::Service)
|
22
|
-
local_ref(v)
|
23
|
-
elsif v.respond_to?(:call) && !v.is_a?(Ref)
|
24
|
-
cb(v)
|
25
|
-
elsif v.is_a?(Hash) || v.is_a?(Array)
|
26
|
-
inflate v
|
27
|
-
else
|
28
|
-
v
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.deflate obj
|
33
|
-
if obj.is_a?(Array)
|
34
|
-
obj.map do |v|
|
35
|
-
deflate v
|
36
|
-
end
|
37
|
-
elsif obj.is_a? Hash
|
38
|
-
if obj.has_key? 'ref'
|
39
|
-
Core::lookup obj['ref']
|
40
|
-
else
|
41
|
-
o = {}
|
42
|
-
obj.each do |k, v|
|
43
|
-
o[k] = deflate v
|
44
|
-
end
|
45
|
-
o
|
46
|
-
end
|
47
|
-
else
|
48
|
-
obj
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.serialize obj
|
53
|
-
obj = inflate(obj)
|
54
|
-
str = JSON::generate obj
|
55
|
-
[str.length].pack("N") + str
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.unserialize str
|
59
|
-
obj = deflate(JSON::parse str)
|
60
|
-
deflate obj
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.err msg
|
64
|
-
$stderr.puts msg
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.log msg, level = 3
|
68
|
-
opts = Bridge::options
|
69
|
-
if level <= opts['log_level']
|
70
|
-
puts msg
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.cb fun
|
75
|
-
Core::store(fun.object_id.to_s(36),
|
76
|
-
LocalRef.new([fun.hash.to_s(36)], Callback.new(fun)))
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.has_keys? obj, *keys
|
80
|
-
keys.each do |k|
|
81
|
-
if !obj.has_key?(k) && !obj.has_key?(k.to_sym)
|
82
|
-
return false
|
83
|
-
end
|
84
|
-
end
|
85
|
-
true
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.local_ref v
|
89
|
-
key = v.object_id.to_s(36)
|
90
|
-
Core::store key, Bridge::LocalRef.new([key], v)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
data/lib/bb/version.rb
DELETED
data/tests/bb_test_helper.rb
DELETED
data/tests/test_serialize.rb
DELETED