arbi 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arbi.rb +45 -7
- metadata +3 -8
data/lib/arbi.rb
CHANGED
@@ -13,7 +13,7 @@ module Arbi
|
|
13
13
|
require 'getopt/long'
|
14
14
|
include Getopt
|
15
15
|
|
16
|
-
VERSION = "1.0.
|
16
|
+
VERSION = "1.0.5"
|
17
17
|
|
18
18
|
@cmd = []
|
19
19
|
|
@@ -30,6 +30,26 @@ module Arbi
|
|
30
30
|
exit 0
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.connect address = '127.0.0.1', port = '6969'
|
34
|
+
@@connection = TCPSocket.new address, port
|
35
|
+
@@connection.print "SERIAL\r\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.connected?
|
39
|
+
return true if @@connection
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.connection
|
44
|
+
@@connection
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.get what
|
48
|
+
raise "Arbi isn't connected to the server" unless self.connected?
|
49
|
+
@@connection.print what + "\r\n"
|
50
|
+
eval @@connection.gets.strip
|
51
|
+
end
|
52
|
+
|
33
53
|
class Server
|
34
54
|
require 'socket'
|
35
55
|
|
@@ -73,6 +93,10 @@ module Arbi
|
|
73
93
|
@servert.kill
|
74
94
|
end
|
75
95
|
|
96
|
+
def finalize
|
97
|
+
close
|
98
|
+
end
|
99
|
+
|
76
100
|
private
|
77
101
|
|
78
102
|
def parse_args
|
@@ -80,8 +104,8 @@ module Arbi
|
|
80
104
|
opts = Arbi::Long.getopts(
|
81
105
|
["--bind-address", "-a", Arbi::REQUIRED],
|
82
106
|
["--port", "-p", Arbi::REQUIRED],
|
83
|
-
["--help"
|
84
|
-
["--version"
|
107
|
+
["--help"],
|
108
|
+
["--version"]
|
85
109
|
)
|
86
110
|
rescue Getopt::Long::Error => e
|
87
111
|
puts "Arguments error: #{e}"
|
@@ -96,12 +120,13 @@ module Arbi
|
|
96
120
|
|
97
121
|
def new_client session
|
98
122
|
@threads.push Thread.start(session){ |session|
|
123
|
+
ser = false
|
99
124
|
while message = session.gets
|
100
125
|
toggle = true
|
101
126
|
message = message.strip
|
102
127
|
break if message =~ /^QUIT$/i
|
103
128
|
|
104
|
-
if message =~ /^HELP$/i
|
129
|
+
if message =~ /^HELP$/i and !ser
|
105
130
|
session.print "help:\r\n"
|
106
131
|
Arbi::cmd.each { |pair|
|
107
132
|
session.print "#{pair[0]}\r\n"
|
@@ -113,18 +138,27 @@ module Arbi
|
|
113
138
|
toggle = !toggle
|
114
139
|
end
|
115
140
|
|
116
|
-
if message =~ /^VERSION$/i
|
141
|
+
if message =~ /^VERSION$/i and !ser
|
117
142
|
session.print "version:\r\nArbi (Client|Server) v#{VERSION}\r\nEND\r\n"
|
118
143
|
toggle = !toggle
|
119
144
|
end
|
120
145
|
|
146
|
+
if message =~ /^SERIAL$/i
|
147
|
+
ser = !ser
|
148
|
+
toggle = !toggle
|
149
|
+
end
|
150
|
+
|
121
151
|
Arbi::cmd.each { |pair|
|
122
152
|
if message =~ pair[0]
|
123
|
-
|
153
|
+
if ser
|
154
|
+
session.print pair[1].get_infos.inspect + "\r\n"
|
155
|
+
else
|
156
|
+
session.print (pair[1].class == Class ? pair[1].protocolize(pair[1].get_infos) : pair[1].class.protocolize(pair[1].get_infos))
|
157
|
+
end
|
124
158
|
toggle = !toggle
|
125
159
|
end
|
126
160
|
}
|
127
|
-
session.print "error:\r\nCommand doesn't exist\r\nEND\r\n" if toggle
|
161
|
+
session.print (ser ? "{'error' => 'command desn\\'t exist'}" : "error:\r\nCommand doesn't exist\r\nEND\r\n") if toggle
|
128
162
|
end
|
129
163
|
@sessions -= [session]
|
130
164
|
session.close
|
@@ -172,6 +206,10 @@ module Arbi
|
|
172
206
|
@sock.close
|
173
207
|
end
|
174
208
|
|
209
|
+
def finalize
|
210
|
+
close
|
211
|
+
end
|
212
|
+
|
175
213
|
def show_help
|
176
214
|
puts "Arbi client:"
|
177
215
|
puts "\tUSAGE: #{$0} [switches]"
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
8
|
+
- 5
|
9
|
+
version: 1.0.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- shura
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-08-13 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
41
|
segments:
|
45
42
|
- 0
|
46
43
|
version: "0"
|
@@ -80,7 +77,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
77
|
requirements:
|
81
78
|
- - ">="
|
82
79
|
- !ruby/object:Gem::Version
|
83
|
-
hash: 3
|
84
80
|
segments:
|
85
81
|
- 0
|
86
82
|
version: "0"
|
@@ -89,7 +85,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
85
|
requirements:
|
90
86
|
- - ">="
|
91
87
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 3
|
93
88
|
segments:
|
94
89
|
- 0
|
95
90
|
version: "0"
|