sgslib 0.2.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/sgs/alarm.rb +1 -1
- data/lib/sgs/config.rb +0 -1
- data/lib/sgs/redis_base.rb +0 -1
- data/lib/sgs/rpc.rb +84 -0
- data/lib/sgs/version.rb +1 -1
- data/lib/sgslib.rb +1 -0
- data/sgslib.gemspec +2 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaae860efa0ec12d6920ac0c2e7498e52b4c858ebe689f8591416187077c0381
|
4
|
+
data.tar.gz: ef31a4d32a397c6c557c389ccf78a2206050a62bd69f10885fd9ff36f9de5014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29df64a13c4e2526137fd7c4c049932f629c5a302285c4d866ee66b239fa7ddd79b816a1e1bb7c120388e71f5d9198c3ebc6bf54f688ef2d48403258f73d5ea2
|
7
|
+
data.tar.gz: 90f580001c3cd7377acec7abfd0dcbf66e56601187e42bf10339faa6868bec8ee23e241363828cfe0fb5efa99bfcaebf7bb4d8354269707f0503e89014ac2a15
|
data/lib/sgs/alarm.rb
CHANGED
data/lib/sgs/config.rb
CHANGED
data/lib/sgs/redis_base.rb
CHANGED
data/lib/sgs/rpc.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018, Kalopa Research. All rights reserved. This is free
|
3
|
+
# software; you can redistribute it and/or modify it under the terms of the
|
4
|
+
# GNU General Public License as published by the Free Software Foundation;
|
5
|
+
# either version 2, or (at your option) any later version.
|
6
|
+
#
|
7
|
+
# It is distributed in the hope that it will be useful, but WITHOUT
|
8
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
9
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
10
|
+
# for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU General Public License along
|
13
|
+
# with this product; see the file COPYING. If not, write to the Free
|
14
|
+
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH "AS IS" AND ANY EXPRESS OR
|
17
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
18
|
+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
19
|
+
# IN NO EVENT SHALL KALOPA RESEARCH BE LIABLE FOR ANY DIRECT, INDIRECT,
|
20
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
22
|
+
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
23
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
#
|
27
|
+
|
28
|
+
##
|
29
|
+
# Routines for sending and receiving messages using Redis. Sourced from
|
30
|
+
# Anthoni Scotti, https://128bit.io/2014/08/31/rpc-using-redis/
|
31
|
+
#
|
32
|
+
require 'redis'
|
33
|
+
require 'securerandom'
|
34
|
+
require 'msgpack'
|
35
|
+
|
36
|
+
module SGS
|
37
|
+
class RPCClient
|
38
|
+
def initialize(channel)
|
39
|
+
@channel = channel.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(name, *args)
|
43
|
+
uuid = SecureRandom.uuid
|
44
|
+
request = {
|
45
|
+
'id' => uuid,
|
46
|
+
'jsonrpc' => '2.0',
|
47
|
+
'method' => name,
|
48
|
+
'params' => args
|
49
|
+
}
|
50
|
+
SGS::RedisBase.redis.lpush(@channel, request.to_msgpack)
|
51
|
+
channel, response = SGS::RedisBase.redis.brpop(uuid, timeout=60)
|
52
|
+
MessagePack.unpack(response)['result']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class RPCServer
|
57
|
+
def initialize(channel, klass)
|
58
|
+
@channel = channel.to_s
|
59
|
+
@klass = klass
|
60
|
+
end
|
61
|
+
|
62
|
+
def start
|
63
|
+
puts "Starting RPC server for #{@channel}"
|
64
|
+
loop do
|
65
|
+
channel, request = SGS::RedisBase.redis.brpop(@channel)
|
66
|
+
request = MessagePack.unpack(request)
|
67
|
+
|
68
|
+
puts "Working on request: #{request['id']}"
|
69
|
+
|
70
|
+
args = request['params'].unshift(request['method'])
|
71
|
+
result = @klass.send *args
|
72
|
+
|
73
|
+
reply = {
|
74
|
+
'jsonrpc' => '2.0',
|
75
|
+
'result' => result,
|
76
|
+
'id' => request['id']
|
77
|
+
}
|
78
|
+
|
79
|
+
SGS::RedisBase.redis.rpush(request['id'], MessagePack.pack(reply))
|
80
|
+
SGS::RedisBase.redis.expire(request['id'], 30)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/sgs/version.rb
CHANGED
data/lib/sgslib.rb
CHANGED
data/sgslib.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sgslib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dermot Tynan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: msgpack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: redis
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +109,7 @@ files:
|
|
95
109
|
- lib/sgs/nmea.rb
|
96
110
|
- lib/sgs/otto.rb
|
97
111
|
- lib/sgs/redis_base.rb
|
112
|
+
- lib/sgs/rpc.rb
|
98
113
|
- lib/sgs/timing.rb
|
99
114
|
- lib/sgs/version.rb
|
100
115
|
- lib/sgs/waypoint.rb
|
@@ -121,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
136
|
version: '0'
|
122
137
|
requirements: []
|
123
138
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.7.6
|
125
140
|
signing_key:
|
126
141
|
specification_version: 4
|
127
142
|
summary: Sailboat Guidance System
|