rbnewt 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/extconf.rb +24 -1
- data/include/newt/common.h +7 -0
- data/include/newt/stomp.h +19 -0
- data/src/rbnewt.c +99 -0
- data/src/stomp.c +49 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fc9c96699a8b2aee42b4943b41863e7920a55f2
|
4
|
+
data.tar.gz: dafa4acf3efd038b7795ed6f12f303041a76aaa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c26d04528ac759b858a67f3f595fa94670616d5c871137acb19c457278619f07ff912eb244febf417b6b33ce6b55e340a3ea66b860ca002a66ae890df04cf350
|
7
|
+
data.tar.gz: 164bcf5a890544b1a1daf035ab084e2ec91486257027c0cbfe3f6409c21538786615bf8dc1d6392f3ee71fc7205f9bb3c8085357b310546c5310dc2c88280d71
|
data/extconf.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
1
|
require "mkmf"
|
2
2
|
|
3
|
-
|
3
|
+
$libs = "-lpthread -lstomp"
|
4
|
+
$CFLAGS = "-I./include"
|
5
|
+
|
6
|
+
def is_header?
|
7
|
+
is_ok = true
|
8
|
+
is_ok &= have_header('stomp/stomp.h') ||
|
9
|
+
find_header('stomp/stomp.h', '/opt/local/include', '/usr/local/include', '/usr/include')
|
10
|
+
is_ok &= have_header('pthread.h') ||
|
11
|
+
find_header('pthread.h', '/opt/local/include', '/usr/local/include', '/usr/include')
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_library?
|
15
|
+
is_ok = true
|
16
|
+
is_ok &= have_library('stomp', 'stomp_session_new') ||
|
17
|
+
find_library('stomp', 'stomp_session_new', '/opt/local/lib', '/usr/local/lib', '/usr/lib')
|
18
|
+
is_ok &= have_library('pthread', 'pthread_create') ||
|
19
|
+
find_library('pthread', 'pthread_create', '/opt/local/lib', '/usr/local/lib', '/usr/lib')
|
20
|
+
end
|
21
|
+
|
22
|
+
if is_header? and is_library?
|
23
|
+
create_makefile('rbnewt', 'src')
|
24
|
+
else
|
25
|
+
raise "Dependent libraries have not been installed yet."
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifndef __NEWT_STOMP_H__
|
2
|
+
#define __NEWT_STOMP_H__
|
3
|
+
|
4
|
+
#include <newt/common.h>
|
5
|
+
#include <stomp/stomp.h>
|
6
|
+
|
7
|
+
#define NEWT_STOMP_KEY_SERVER "server"
|
8
|
+
#define NEWT_STOMP_KEY_USERID "userid"
|
9
|
+
#define NEWT_STOMP_KEY_PASSWD "passwd"
|
10
|
+
#define NEWT_STOMP_KEY_PORT "port"
|
11
|
+
|
12
|
+
#define NEWT_STOMP_DEFAULT_SERVER "localhost"
|
13
|
+
#define NEWT_STOMP_DEFAULT_USERID "guest"
|
14
|
+
#define NEWT_STOMP_DEFAULT_PASSWD "guest"
|
15
|
+
#define NEWT_STOMP_DEFAULT_PORT "61613"
|
16
|
+
|
17
|
+
int cnewt_stomp_initialize(stomp_session_t *, char *, char *, char *, char *);
|
18
|
+
|
19
|
+
#endif
|
data/src/rbnewt.c
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <assert.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <pthread.h>
|
5
|
+
#include <stomp/stomp.h>
|
6
|
+
#include <newt/stomp.h>
|
7
|
+
|
8
|
+
static char *get_str_from_hash(VALUE hash, char *key) {
|
9
|
+
assert(TYPE(hash) == T_HASH);
|
10
|
+
|
11
|
+
VALUE v = rb_hash_aref(hash, ID2SYM(rb_intern(key)));
|
12
|
+
if(v != Qnil && TYPE(v) == T_STRING) {
|
13
|
+
return StringValueCStr(v);
|
14
|
+
}
|
15
|
+
|
16
|
+
return NULL;
|
17
|
+
}
|
18
|
+
|
19
|
+
static int get_int_from_hash(VALUE hash, char *key) {
|
20
|
+
assert(TYPE(hash) == T_HASH);
|
21
|
+
|
22
|
+
VALUE v = rb_hash_aref(hash, ID2SYM(rb_intern(key)));
|
23
|
+
if(v != Qnil && TYPE(v) == T_FIXNUM) {
|
24
|
+
return NUM2INT(v);
|
25
|
+
}
|
26
|
+
|
27
|
+
return -1;
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE newt_stomp_close(VALUE self) {
|
31
|
+
stomp_session_t *session;
|
32
|
+
|
33
|
+
Data_Get_Struct(self, stomp_session_t, session);
|
34
|
+
|
35
|
+
if(cnewt_stomp_close(session) == RET_SUCCESS) {
|
36
|
+
return self;
|
37
|
+
}
|
38
|
+
|
39
|
+
return Qnil;
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE newt_stomp_initialize(int argc, VALUE *argv, VALUE self) {
|
43
|
+
stomp_session_t *session;
|
44
|
+
VALUE opts;
|
45
|
+
char *server, *userid, *passwd, *port;
|
46
|
+
|
47
|
+
rb_scan_args(argc, argv, "01", &opts);
|
48
|
+
|
49
|
+
Data_Get_Struct(self, stomp_session_t, session);
|
50
|
+
|
51
|
+
// zero-set for initialization
|
52
|
+
server = userid = passwd = port = NULL;
|
53
|
+
|
54
|
+
if(! NIL_P(opts)) {
|
55
|
+
server = get_str_from_hash(opts, NEWT_STOMP_KEY_SERVER);
|
56
|
+
userid = get_str_from_hash(opts, NEWT_STOMP_KEY_USERID);
|
57
|
+
passwd = get_str_from_hash(opts, NEWT_STOMP_KEY_PASSWD);
|
58
|
+
port = get_str_from_hash(opts, NEWT_STOMP_KEY_PORT);
|
59
|
+
}
|
60
|
+
|
61
|
+
//set default values
|
62
|
+
if(server == NULL) server = NEWT_STOMP_DEFAULT_SERVER;
|
63
|
+
if(userid == NULL) userid = NEWT_STOMP_DEFAULT_USERID;
|
64
|
+
if(passwd == NULL) passwd = NEWT_STOMP_DEFAULT_PASSWD;
|
65
|
+
if(port == NULL) port = NEWT_STOMP_DEFAULT_PORT;
|
66
|
+
|
67
|
+
if(cnewt_stomp_initialize(session, server, port, userid, passwd) != RET_SUCCESS) {
|
68
|
+
printf("[warning] failed to connect server\n");
|
69
|
+
}
|
70
|
+
|
71
|
+
return self;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE newt_stomp_alloc(VALUE klass) {
|
75
|
+
stomp_session_t *session;
|
76
|
+
pthread_t *thread_id;
|
77
|
+
VALUE ret = Qnil;
|
78
|
+
|
79
|
+
thread_id = (pthread_t *)malloc(sizeof(pthread_t));
|
80
|
+
assert(thread_id != NULL);
|
81
|
+
|
82
|
+
session = stomp_session_new(thread_id);
|
83
|
+
if(session != NULL) {
|
84
|
+
ret = rb_data_object_alloc(klass, session, 0, NULL);
|
85
|
+
}
|
86
|
+
|
87
|
+
return ret;
|
88
|
+
}
|
89
|
+
|
90
|
+
void Init_rbnewt(void) {
|
91
|
+
VALUE module, stomp_kls;
|
92
|
+
|
93
|
+
module = rb_define_module("Newt");
|
94
|
+
stomp_kls = rb_define_class_under(module, "STOMP", rb_cObject);
|
95
|
+
|
96
|
+
rb_define_alloc_func(stomp_kls, newt_stomp_alloc);
|
97
|
+
rb_define_method(stomp_kls, "initialize", newt_stomp_initialize, -1);
|
98
|
+
rb_define_method(stomp_kls, "close", newt_stomp_close, 0);
|
99
|
+
}
|
data/src/stomp.c
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#include <stomp/stomp.h>
|
2
|
+
#include <newt/common.h>
|
3
|
+
#include <newt/stomp.h>
|
4
|
+
#include <pthread.h>
|
5
|
+
|
6
|
+
static void *thread_stomp(void *data) {
|
7
|
+
stomp_session_t *session = (stomp_session_t *)data;
|
8
|
+
|
9
|
+
//here is main-loop
|
10
|
+
stomp_run(session);
|
11
|
+
|
12
|
+
stomp_session_free(session);
|
13
|
+
}
|
14
|
+
|
15
|
+
int cnewt_stomp_initialize(stomp_session_t *session, char *server, char *port, char *userid, char *passwd) {
|
16
|
+
const struct stomp_hdr connection_headers[] = {
|
17
|
+
{"login", userid},
|
18
|
+
{"passcode", passwd},
|
19
|
+
};
|
20
|
+
int ret = RET_ERROR;
|
21
|
+
pthread_t *thread_id = (pthread_t *)session->ctx;
|
22
|
+
|
23
|
+
if(thread_id != NULL) {
|
24
|
+
stomp_connect(session, server, port, 2, connection_headers);
|
25
|
+
|
26
|
+
pthread_create(thread_id, NULL, thread_stomp, session);
|
27
|
+
|
28
|
+
ret = RET_SUCCESS;
|
29
|
+
}
|
30
|
+
|
31
|
+
return ret;
|
32
|
+
}
|
33
|
+
|
34
|
+
int cnewt_stomp_close(stomp_session_t *session) {
|
35
|
+
pthread_t *thread_id = (pthread_t *)session->ctx;
|
36
|
+
const struct stomp_hdr disconnect_header[] = {{0}};
|
37
|
+
int ret = RET_ERROR;
|
38
|
+
|
39
|
+
if(thread_id != NULL) {
|
40
|
+
// set flag to escape stomp mainloop
|
41
|
+
session->run = 0;
|
42
|
+
|
43
|
+
pthread_join(*thread_id, NULL);
|
44
|
+
|
45
|
+
ret = RET_SUCCESS;
|
46
|
+
}
|
47
|
+
|
48
|
+
return ret;
|
49
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbnewt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyasu OHYAMA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This aims to to be the fastest Ruby client for NewtMQ which is an implementation
|
14
14
|
of STOMP server.
|
@@ -20,6 +20,10 @@ extensions:
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- extconf.rb
|
23
|
+
- include/newt/common.h
|
24
|
+
- include/newt/stomp.h
|
25
|
+
- src/rbnewt.c
|
26
|
+
- src/stomp.c
|
23
27
|
homepage: https://github.com/userlocalhost2000/rbnewt
|
24
28
|
licenses:
|
25
29
|
- MIT
|