rbnewt 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +259 -0
- data/include/newt/rbnewt.h +16 -0
- data/src/rbnewt.c +126 -22
- data/src/stomp.c +8 -26
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c26cde6bba16893211200d19f988832981f1d90
|
4
|
+
data.tar.gz: f90478c6a6038072b168f909c53bd5f337aadffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 297dc08ec4d1d167659f0fd8f1f144898d100ddefa8a51a54f2d323177419bcbfca58776b8b85cd213478fd262141acc9be04c218319ba9c320cb94dbddf073b
|
7
|
+
data.tar.gz: 86258abb18f69c7fc2d55c28a6897a9e3b663716d2631ec7c999fbc1a47162c188c48d4e3e223e7189c3c53a97cc8ecc9d5a6045114783d22c03e85227308885
|
data/Makefile
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
5
|
+
V = 0
|
6
|
+
Q1 = $(V:1=)
|
7
|
+
Q = $(Q1:0=@)
|
8
|
+
ECHO1 = $(V:1=@:)
|
9
|
+
ECHO = $(ECHO1:0=@echo)
|
10
|
+
NULLCMD = :
|
11
|
+
|
12
|
+
#### Start of system configuration section. ####
|
13
|
+
|
14
|
+
srcdir = src
|
15
|
+
topdir = /home/vagrant/.rbenv/versions/2.2.2/include/ruby-2.2.0
|
16
|
+
hdrdir = $(topdir)
|
17
|
+
arch_hdrdir = /home/vagrant/.rbenv/versions/2.2.2/include/ruby-2.2.0/x86_64-linux
|
18
|
+
PATH_SEPARATOR = :
|
19
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
20
|
+
prefix = $(DESTDIR)/home/vagrant/.rbenv/versions/2.2.2
|
21
|
+
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
|
22
|
+
rubyarchprefix = $(rubylibprefix)/$(arch)
|
23
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
24
|
+
exec_prefix = $(prefix)
|
25
|
+
vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
|
26
|
+
sitearchhdrdir = $(sitehdrdir)/$(sitearch)
|
27
|
+
rubyarchhdrdir = $(rubyhdrdir)/$(arch)
|
28
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
29
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
30
|
+
rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
|
31
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
32
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
33
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
34
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
35
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
36
|
+
sitedir = $(rubylibprefix)/site_ruby
|
37
|
+
rubyarchdir = $(rubylibdir)/$(arch)
|
38
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
39
|
+
sitearchincludedir = $(includedir)/$(sitearch)
|
40
|
+
archincludedir = $(includedir)/$(arch)
|
41
|
+
sitearchlibdir = $(libdir)/$(sitearch)
|
42
|
+
archlibdir = $(libdir)/$(arch)
|
43
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
44
|
+
mandir = $(datarootdir)/man
|
45
|
+
localedir = $(datarootdir)/locale
|
46
|
+
libdir = $(exec_prefix)/lib
|
47
|
+
psdir = $(docdir)
|
48
|
+
pdfdir = $(docdir)
|
49
|
+
dvidir = $(docdir)
|
50
|
+
htmldir = $(docdir)
|
51
|
+
infodir = $(datarootdir)/info
|
52
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
53
|
+
oldincludedir = $(DESTDIR)/usr/include
|
54
|
+
includedir = $(prefix)/include
|
55
|
+
localstatedir = $(prefix)/var
|
56
|
+
sharedstatedir = $(prefix)/com
|
57
|
+
sysconfdir = $(prefix)/etc
|
58
|
+
datadir = $(datarootdir)
|
59
|
+
datarootdir = $(prefix)/share
|
60
|
+
libexecdir = $(exec_prefix)/libexec
|
61
|
+
sbindir = $(exec_prefix)/sbin
|
62
|
+
bindir = $(exec_prefix)/bin
|
63
|
+
archdir = $(rubyarchdir)
|
64
|
+
|
65
|
+
|
66
|
+
CC = gcc
|
67
|
+
CXX = g++
|
68
|
+
LIBRUBY = $(LIBRUBY_A)
|
69
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
70
|
+
LIBRUBYARG_SHARED = -Wl,-R$(libdir) -L$(libdir)
|
71
|
+
LIBRUBYARG_STATIC = -Wl,-R$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
|
72
|
+
empty =
|
73
|
+
OUTFLAG = -o $(empty)
|
74
|
+
COUTFLAG = -o $(empty)
|
75
|
+
|
76
|
+
RUBY_EXTCONF_H =
|
77
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
78
|
+
optflags = -O3 -fno-fast-math
|
79
|
+
debugflags = -ggdb3
|
80
|
+
warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat
|
81
|
+
CCDLFLAGS = -fPIC
|
82
|
+
CFLAGS = $(CCDLFLAGS) -I./include $(ARCH_FLAG)
|
83
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
84
|
+
DEFS =
|
85
|
+
CPPFLAGS = -DHAVE_STOMP_STOMP_H -DHAVE_PTHREAD_H -I/home/vagrant/.rbenv/versions/2.2.2/include $(DEFS) $(cppflags)
|
86
|
+
CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
|
87
|
+
ldflags = -L. -L/home/vagrant/.rbenv/versions/2.2.2/lib -fstack-protector -rdynamic -Wl,-export-dynamic
|
88
|
+
dldflags =
|
89
|
+
ARCH_FLAG =
|
90
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
91
|
+
LDSHARED = $(CC) -shared
|
92
|
+
LDSHAREDXX = $(CXX) -shared
|
93
|
+
AR = ar
|
94
|
+
EXEEXT =
|
95
|
+
|
96
|
+
RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
|
97
|
+
RUBY_SO_NAME = ruby
|
98
|
+
RUBYW_INSTALL_NAME =
|
99
|
+
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
|
100
|
+
RUBYW_BASE_NAME = rubyw
|
101
|
+
RUBY_BASE_NAME = ruby
|
102
|
+
|
103
|
+
arch = x86_64-linux
|
104
|
+
sitearch = $(arch)
|
105
|
+
ruby_version = 2.2.0
|
106
|
+
ruby = $(bindir)/$(RUBY_BASE_NAME)
|
107
|
+
RUBY = $(ruby)
|
108
|
+
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
|
109
|
+
|
110
|
+
RM = rm -f
|
111
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
112
|
+
RMDIRS = rmdir --ignore-fail-on-non-empty -p
|
113
|
+
MAKEDIRS = /bin/mkdir -p
|
114
|
+
INSTALL = /usr/bin/install -c
|
115
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
116
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
117
|
+
COPY = cp
|
118
|
+
TOUCH = exit >
|
119
|
+
|
120
|
+
#### End of system configuration section. ####
|
121
|
+
|
122
|
+
preload =
|
123
|
+
|
124
|
+
libpath = . $(libdir)
|
125
|
+
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
|
126
|
+
DEFFILE =
|
127
|
+
|
128
|
+
CLEANFILES = mkmf.log
|
129
|
+
DISTCLEANFILES =
|
130
|
+
DISTCLEANDIRS =
|
131
|
+
|
132
|
+
extout =
|
133
|
+
extout_prefix =
|
134
|
+
target_prefix =
|
135
|
+
LOCAL_LIBS =
|
136
|
+
LIBS = -lpthread -lstomp -lpthread -lstomp -lpthread -ldl -lcrypt -lm -lc
|
137
|
+
ORIG_SRCS = stomp.c rbframe.c rbnewt.c
|
138
|
+
SRCS = $(ORIG_SRCS)
|
139
|
+
OBJS = stomp.o rbframe.o rbnewt.o
|
140
|
+
HDRS =
|
141
|
+
TARGET = rbnewt
|
142
|
+
TARGET_NAME = rbnewt
|
143
|
+
TARGET_ENTRY = Init_$(TARGET_NAME)
|
144
|
+
DLLIB = $(TARGET).so
|
145
|
+
EXTSTATIC =
|
146
|
+
STATIC_LIB =
|
147
|
+
|
148
|
+
TIMESTAMP_DIR = .
|
149
|
+
BINDIR = $(bindir)
|
150
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
151
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
152
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
153
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
154
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
155
|
+
|
156
|
+
TARGET_SO = $(DLLIB)
|
157
|
+
CLEANLIBS = $(TARGET).so
|
158
|
+
CLEANOBJS = *.o *.bak
|
159
|
+
|
160
|
+
all: $(DLLIB)
|
161
|
+
static: $(STATIC_LIB)
|
162
|
+
.PHONY: all install static install-so install-rb
|
163
|
+
.PHONY: clean clean-so clean-static clean-rb
|
164
|
+
|
165
|
+
clean-static::
|
166
|
+
clean-rb-default::
|
167
|
+
clean-rb::
|
168
|
+
clean-so::
|
169
|
+
clean: clean-so clean-static clean-rb-default clean-rb
|
170
|
+
-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
171
|
+
|
172
|
+
distclean-rb-default::
|
173
|
+
distclean-rb::
|
174
|
+
distclean-so::
|
175
|
+
distclean-static::
|
176
|
+
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
|
177
|
+
-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
178
|
+
-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
179
|
+
-$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
180
|
+
|
181
|
+
realclean: distclean
|
182
|
+
install: install-so install-rb
|
183
|
+
|
184
|
+
install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
|
185
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
186
|
+
clean-static::
|
187
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
188
|
+
install-rb: pre-install-rb install-rb-default
|
189
|
+
install-rb-default: pre-install-rb-default
|
190
|
+
pre-install-rb: Makefile
|
191
|
+
pre-install-rb-default: Makefile
|
192
|
+
pre-install-rb-default:
|
193
|
+
@$(NULLCMD)
|
194
|
+
$(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
|
195
|
+
$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
|
196
|
+
$(Q) $(TOUCH) $@
|
197
|
+
|
198
|
+
site-install: site-install-so site-install-rb
|
199
|
+
site-install-so: install-so
|
200
|
+
site-install-rb: install-rb
|
201
|
+
|
202
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
|
203
|
+
|
204
|
+
.cc.o:
|
205
|
+
$(ECHO) compiling $(<)
|
206
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
207
|
+
|
208
|
+
.cc.S:
|
209
|
+
$(ECHO) translating $(<)
|
210
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
|
211
|
+
|
212
|
+
.mm.o:
|
213
|
+
$(ECHO) compiling $(<)
|
214
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
215
|
+
|
216
|
+
.mm.S:
|
217
|
+
$(ECHO) translating $(<)
|
218
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
|
219
|
+
|
220
|
+
.cxx.o:
|
221
|
+
$(ECHO) compiling $(<)
|
222
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
223
|
+
|
224
|
+
.cxx.S:
|
225
|
+
$(ECHO) translating $(<)
|
226
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
|
227
|
+
|
228
|
+
.cpp.o:
|
229
|
+
$(ECHO) compiling $(<)
|
230
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
231
|
+
|
232
|
+
.cpp.S:
|
233
|
+
$(ECHO) translating $(<)
|
234
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
|
235
|
+
|
236
|
+
.c.o:
|
237
|
+
$(ECHO) compiling $(<)
|
238
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
239
|
+
|
240
|
+
.c.S:
|
241
|
+
$(ECHO) translating $(<)
|
242
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
|
243
|
+
|
244
|
+
.m.o:
|
245
|
+
$(ECHO) compiling $(<)
|
246
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
247
|
+
|
248
|
+
.m.S:
|
249
|
+
$(ECHO) translating $(<)
|
250
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
|
251
|
+
|
252
|
+
$(DLLIB): $(OBJS) Makefile
|
253
|
+
$(ECHO) linking shared-object $(DLLIB)
|
254
|
+
-$(Q)$(RM) $(@)
|
255
|
+
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
$(OBJS): $(HDRS) $(ruby_headers)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef __NEWT_RBNEWT_H__
|
2
|
+
#define __NEWT_RBNEWT_H__
|
3
|
+
|
4
|
+
#include <stomp/stomp.h>
|
5
|
+
#include <ruby/ruby.h>
|
6
|
+
|
7
|
+
/* internal data structure to share in the session */
|
8
|
+
typedef struct rbnewt_context_t {
|
9
|
+
VALUE self;
|
10
|
+
} rbnewt_context_t;
|
11
|
+
|
12
|
+
void newt_stomp_callback_connected(stomp_session_t *, void *, void *);
|
13
|
+
void newt_stomp_callback_message(stomp_session_t *, void *, void *);
|
14
|
+
void newt_stomp_callback_error(stomp_session_t *, void *, void *);
|
15
|
+
|
16
|
+
#endif
|
data/src/rbnewt.c
CHANGED
@@ -1,9 +1,58 @@
|
|
1
|
-
#include <ruby.h>
|
1
|
+
#include <ruby/ruby.h>
|
2
|
+
#include <ruby/intern.h>
|
2
3
|
#include <assert.h>
|
3
4
|
#include <stdlib.h>
|
4
|
-
#include <
|
5
|
+
#include <string.h>
|
5
6
|
#include <stomp/stomp.h>
|
7
|
+
|
6
8
|
#include <newt/stomp.h>
|
9
|
+
#include <newt/rbnewt.h>
|
10
|
+
|
11
|
+
static VALUE get_headers(struct stomp_ctx_message *ctx) {
|
12
|
+
VALUE ret;
|
13
|
+
|
14
|
+
assert(ctx != NULL);
|
15
|
+
|
16
|
+
// XXX no implementation
|
17
|
+
ret = Qnil;
|
18
|
+
|
19
|
+
return ret;
|
20
|
+
}
|
21
|
+
|
22
|
+
static VALUE get_body(struct stomp_ctx_message *ctx) {
|
23
|
+
VALUE ret;
|
24
|
+
|
25
|
+
assert(ctx != NULL);
|
26
|
+
|
27
|
+
// XXX no implementation
|
28
|
+
ret = Qnil;
|
29
|
+
|
30
|
+
return ret;
|
31
|
+
}
|
32
|
+
|
33
|
+
void newt_stomp_callback_connected(stomp_session_t *s, void *callback_ctx, void *session_ctx) {
|
34
|
+
rbnewt_context_t *rbnewt_ctx = (rbnewt_context_t *)s->ctx;
|
35
|
+
|
36
|
+
assert(rbnewt_ctx != NULL);
|
37
|
+
|
38
|
+
//VALUE kls = rb_obj_class(rbnewt_ctx->self);
|
39
|
+
if(rb_respond_to(rbnewt_ctx->self, rb_intern("callback_connected"))) {
|
40
|
+
VALUE header = get_headers((struct stomp_ctx_message *)callback_ctx);
|
41
|
+
VALUE body = get_body((struct stomp_ctx_message *)callback_ctx);
|
42
|
+
|
43
|
+
rb_funcall(rbnewt_ctx->self, rb_intern("callback_connected"), 2, header, body);
|
44
|
+
}
|
45
|
+
|
46
|
+
if(rb_block_given_p()) {
|
47
|
+
rb_yield(Qnil);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
void newt_stomp_callback_message(stomp_session_t *s, void *callback_ctx, void *session_ctx) {
|
51
|
+
// nope
|
52
|
+
}
|
53
|
+
void newt_stomp_callback_error(stomp_session_t *s, void *callback_ctx, void *session_ctx) {
|
54
|
+
// nope
|
55
|
+
}
|
7
56
|
|
8
57
|
static char *get_str_from_hash(VALUE hash, char *key) {
|
9
58
|
assert(TYPE(hash) == T_HASH);
|
@@ -27,22 +76,11 @@ static int get_int_from_hash(VALUE hash, char *key) {
|
|
27
76
|
return -1;
|
28
77
|
}
|
29
78
|
|
30
|
-
VALUE
|
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) {
|
79
|
+
static VALUE newt_stomp_initialize(int argc, VALUE *argv, VALUE self) {
|
43
80
|
stomp_session_t *session;
|
44
81
|
VALUE opts;
|
45
82
|
char *server, *userid, *passwd, *port;
|
83
|
+
rbnewt_context_t *context;
|
46
84
|
|
47
85
|
rb_scan_args(argc, argv, "01", &opts);
|
48
86
|
|
@@ -58,12 +96,16 @@ VALUE newt_stomp_initialize(int argc, VALUE *argv, VALUE self) {
|
|
58
96
|
port = get_str_from_hash(opts, NEWT_STOMP_KEY_PORT);
|
59
97
|
}
|
60
98
|
|
61
|
-
//set default values
|
99
|
+
// set default values
|
62
100
|
if(server == NULL) server = NEWT_STOMP_DEFAULT_SERVER;
|
63
101
|
if(userid == NULL) userid = NEWT_STOMP_DEFAULT_USERID;
|
64
102
|
if(passwd == NULL) passwd = NEWT_STOMP_DEFAULT_PASSWD;
|
65
103
|
if(port == NULL) port = NEWT_STOMP_DEFAULT_PORT;
|
66
104
|
|
105
|
+
// set self object to context
|
106
|
+
context = (rbnewt_context_t *)session->ctx;
|
107
|
+
context->self = self;
|
108
|
+
|
67
109
|
if(cnewt_stomp_initialize(session, server, port, userid, passwd) != RET_SUCCESS) {
|
68
110
|
printf("[warning] failed to connect server\n");
|
69
111
|
}
|
@@ -71,17 +113,78 @@ VALUE newt_stomp_initialize(int argc, VALUE *argv, VALUE self) {
|
|
71
113
|
return self;
|
72
114
|
}
|
73
115
|
|
116
|
+
static VALUE newt_stomp_send(int argc, VALUE *argv, VALUE self) {
|
117
|
+
stomp_session_t *session;
|
118
|
+
VALUE rb_dest, rb_data, rb_opts, rb_headers;
|
119
|
+
int header_len = 1;
|
120
|
+
|
121
|
+
// initialize each rb values
|
122
|
+
rb_headers = Qnil;
|
123
|
+
rb_scan_args(argc, argv, "21", &rb_dest, &rb_data, &rb_opts);
|
124
|
+
|
125
|
+
Data_Get_Struct(self, stomp_session_t, session);
|
126
|
+
|
127
|
+
char *body = StringValuePtr(rb_data);
|
128
|
+
|
129
|
+
if(! NIL_P(rb_opts)) {
|
130
|
+
assert(TYPE(rb_opts) == T_HASH);
|
131
|
+
|
132
|
+
VALUE rb_headers = rb_funcall(rb_opts, rb_intern("to_a"), 0);
|
133
|
+
|
134
|
+
assert(TYPE(rb_headers) == T_ARRAY);
|
135
|
+
|
136
|
+
header_len += RARRAY_LEN(rb_headers);
|
137
|
+
}
|
138
|
+
|
139
|
+
// making headers
|
140
|
+
struct stomp_hdr *headers = (struct stomp_hdr*)malloc(sizeof(struct stomp_hdr) * header_len);
|
141
|
+
headers[0].key = "destination";
|
142
|
+
headers[0].val = StringValuePtr(rb_dest);
|
143
|
+
int i;
|
144
|
+
for(i=1; i<header_len; i++) {
|
145
|
+
VALUE entry = rb_ary_entry(rb_opts, i);
|
146
|
+
|
147
|
+
VALUE key = rb_ary_entry(entry, 0);
|
148
|
+
VALUE val = rb_ary_entry(entry, 1);
|
149
|
+
|
150
|
+
headers[i].key = StringValueCStr(key);
|
151
|
+
headers[i].val = StringValueCStr(val);
|
152
|
+
}
|
153
|
+
|
154
|
+
stomp_send(session, header_len, headers, body, strlen(body));
|
155
|
+
|
156
|
+
free(headers);
|
157
|
+
|
158
|
+
return self;
|
159
|
+
}
|
160
|
+
|
161
|
+
static VALUE newt_stomp_receiving(VALUE self) {
|
162
|
+
stomp_session_t *session;
|
163
|
+
|
164
|
+
Data_Get_Struct(self, stomp_session_t, session);
|
165
|
+
|
166
|
+
cnewt_stomp_start(session);
|
167
|
+
|
168
|
+
return Qnil;
|
169
|
+
}
|
170
|
+
|
171
|
+
static void context_free(void *ptr) {
|
172
|
+
stomp_session_t *session = (stomp_session_t *)ptr;
|
173
|
+
|
174
|
+
stomp_session_free(session);
|
175
|
+
}
|
176
|
+
|
74
177
|
static VALUE newt_stomp_alloc(VALUE klass) {
|
75
178
|
stomp_session_t *session;
|
76
|
-
|
179
|
+
rbnewt_context_t *context;
|
77
180
|
VALUE ret = Qnil;
|
78
181
|
|
79
|
-
|
80
|
-
assert(
|
182
|
+
context = (rbnewt_context_t *)malloc(sizeof(rbnewt_context_t));
|
183
|
+
assert(context != NULL);
|
81
184
|
|
82
|
-
session = stomp_session_new(
|
185
|
+
session = stomp_session_new(context);
|
83
186
|
if(session != NULL) {
|
84
|
-
ret = rb_data_object_alloc(klass, session, 0,
|
187
|
+
ret = rb_data_object_alloc(klass, session, 0, context_free);
|
85
188
|
}
|
86
189
|
|
87
190
|
return ret;
|
@@ -95,5 +198,6 @@ void Init_rbnewt(void) {
|
|
95
198
|
|
96
199
|
rb_define_alloc_func(stomp_kls, newt_stomp_alloc);
|
97
200
|
rb_define_method(stomp_kls, "initialize", newt_stomp_initialize, -1);
|
98
|
-
rb_define_method(stomp_kls, "
|
201
|
+
rb_define_method(stomp_kls, "send", newt_stomp_send, -1);
|
202
|
+
rb_define_method(stomp_kls, "receiving", newt_stomp_receiving, 0);
|
99
203
|
}
|
data/src/stomp.c
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
#include <stomp/stomp.h>
|
2
|
+
|
3
|
+
#include <newt/rbnewt.h>
|
2
4
|
#include <newt/common.h>
|
3
5
|
#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
6
|
|
7
|
+
void cnewt_stomp_start(stomp_session_t *session) {
|
9
8
|
//here is main-loop
|
10
9
|
stomp_run(session);
|
11
|
-
|
12
|
-
stomp_session_free(session);
|
13
10
|
}
|
14
11
|
|
15
12
|
int cnewt_stomp_initialize(stomp_session_t *session, char *server, char *port, char *userid, char *passwd) {
|
@@ -18,29 +15,14 @@ int cnewt_stomp_initialize(stomp_session_t *session, char *server, char *port, c
|
|
18
15
|
{"passcode", passwd},
|
19
16
|
};
|
20
17
|
int ret = RET_ERROR;
|
21
|
-
|
18
|
+
rbnewt_context_t *context = (rbnewt_context_t *)session->ctx;
|
22
19
|
|
23
|
-
if(
|
20
|
+
if(context != NULL) {
|
24
21
|
stomp_connect(session, server, port, 2, connection_headers);
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
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);
|
23
|
+
stomp_callback_set(session, SCB_CONNECTED, newt_stomp_callback_connected);
|
24
|
+
stomp_callback_set(session, SCB_MESSAGE, newt_stomp_callback_message);
|
25
|
+
stomp_callback_set(session, SCB_ERROR, newt_stomp_callback_error);
|
44
26
|
|
45
27
|
ret = RET_SUCCESS;
|
46
28
|
}
|
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.4
|
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-06-
|
11
|
+
date: 2016-06-04 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.
|
@@ -19,8 +19,10 @@ extensions:
|
|
19
19
|
- extconf.rb
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- Makefile
|
22
23
|
- extconf.rb
|
23
24
|
- include/newt/common.h
|
25
|
+
- include/newt/rbnewt.h
|
24
26
|
- include/newt/stomp.h
|
25
27
|
- src/rbnewt.c
|
26
28
|
- src/stomp.c
|