capn_proto-rpc 0.1.1.alpha.rpc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +19 -0
- data/Gemfile +2 -0
- data/LICENSE +19 -0
- data/README.md +249 -0
- data/Rakefile +44 -0
- data/capn_proto.gemspec +37 -0
- data/examples/addressbook.bin +0 -0
- data/examples/addressbook.capnp +31 -0
- data/examples/create_test_data.py +39 -0
- data/examples/example.rb +38 -0
- data/ext/capn_proto/.ycm_extra_conf.py +65 -0
- data/ext/capn_proto/EzRpc_client.cc +52 -0
- data/ext/capn_proto/EzRpc_client.h +21 -0
- data/ext/capn_proto/EzRpc_server.cc +79 -0
- data/ext/capn_proto/EzRpc_server.h +32 -0
- data/ext/capn_proto/call_context.cc +67 -0
- data/ext/capn_proto/call_context.h +25 -0
- data/ext/capn_proto/capability_client.cc +47 -0
- data/ext/capn_proto/capability_client.h +21 -0
- data/ext/capn_proto/class_builder.cc +80 -0
- data/ext/capn_proto/class_builder.h +72 -0
- data/ext/capn_proto/cxx_compiler.rb +126 -0
- data/ext/capn_proto/dynamic_capability_client.cc +73 -0
- data/ext/capn_proto/dynamic_capability_client.h +22 -0
- data/ext/capn_proto/dynamic_list_builder.cc +123 -0
- data/ext/capn_proto/dynamic_list_builder.h +27 -0
- data/ext/capn_proto/dynamic_list_reader.cc +63 -0
- data/ext/capn_proto/dynamic_list_reader.h +25 -0
- data/ext/capn_proto/dynamic_object_builder.cc +57 -0
- data/ext/capn_proto/dynamic_object_builder.h +22 -0
- data/ext/capn_proto/dynamic_object_reader.cc +56 -0
- data/ext/capn_proto/dynamic_object_reader.h +22 -0
- data/ext/capn_proto/dynamic_struct_builder.cc +180 -0
- data/ext/capn_proto/dynamic_struct_builder.h +34 -0
- data/ext/capn_proto/dynamic_struct_reader.cc +69 -0
- data/ext/capn_proto/dynamic_struct_reader.h +25 -0
- data/ext/capn_proto/dynamic_value_builder.cc +53 -0
- data/ext/capn_proto/dynamic_value_builder.h +13 -0
- data/ext/capn_proto/dynamic_value_reader.cc +55 -0
- data/ext/capn_proto/dynamic_value_reader.h +13 -0
- data/ext/capn_proto/exception.cc +34 -0
- data/ext/capn_proto/exception.h +20 -0
- data/ext/capn_proto/extconf.rb +32 -0
- data/ext/capn_proto/field_list.cc +51 -0
- data/ext/capn_proto/field_list.h +23 -0
- data/ext/capn_proto/flat_array_message_reader.cc +61 -0
- data/ext/capn_proto/flat_array_message_reader.h +21 -0
- data/ext/capn_proto/init.cc +71 -0
- data/ext/capn_proto/interface_method.cc +38 -0
- data/ext/capn_proto/interface_method.h +21 -0
- data/ext/capn_proto/interface_schema.cc +51 -0
- data/ext/capn_proto/interface_schema.h +26 -0
- data/ext/capn_proto/list_nested_node_reader.cc +53 -0
- data/ext/capn_proto/list_nested_node_reader.h +24 -0
- data/ext/capn_proto/malloc_message_builder.cc +51 -0
- data/ext/capn_proto/malloc_message_builder.h +21 -0
- data/ext/capn_proto/message_builder.cc +22 -0
- data/ext/capn_proto/message_builder.h +17 -0
- data/ext/capn_proto/message_reader.cc +30 -0
- data/ext/capn_proto/message_reader.h +17 -0
- data/ext/capn_proto/nested_node_reader.cc +42 -0
- data/ext/capn_proto/nested_node_reader.h +21 -0
- data/ext/capn_proto/parsed_schema.cc +65 -0
- data/ext/capn_proto/parsed_schema.h +24 -0
- data/ext/capn_proto/rb.cc +0 -0
- data/ext/capn_proto/rb.h +0 -0
- data/ext/capn_proto/remote_promise.cc +116 -0
- data/ext/capn_proto/remote_promise.h +30 -0
- data/ext/capn_proto/ruby_capability_server.cc +23 -0
- data/ext/capn_proto/ruby_capability_server.h +21 -0
- data/ext/capn_proto/ruby_capn_proto.cc +4 -0
- data/ext/capn_proto/ruby_capn_proto.h +42 -0
- data/ext/capn_proto/schema_node_reader.cc +59 -0
- data/ext/capn_proto/schema_node_reader.h +23 -0
- data/ext/capn_proto/schema_parser.cc +61 -0
- data/ext/capn_proto/schema_parser.h +20 -0
- data/ext/capn_proto/stream_fd_message_reader.cc +59 -0
- data/ext/capn_proto/stream_fd_message_reader.h +21 -0
- data/ext/capn_proto/struct_schema.cc +59 -0
- data/ext/capn_proto/struct_schema.h +23 -0
- data/ext/capn_proto/util.cc +30 -0
- data/ext/capn_proto/util.h +17 -0
- data/lib/capn_proto.rb +231 -0
- data/lib/capn_proto/version.rb +3 -0
- data/media/captain_proto.png +0 -0
- data/media/captain_proto_small.png +0 -0
- data/spec/addressbook.bin +0 -0
- data/spec/addressbook.capnp +31 -0
- data/spec/capn_proto_spec.rb +80 -0
- data/spec/create_test_data.py +38 -0
- data/spec/spec_helper.rb +8 -0
- data/tests/hidraCordatus.capnp +16 -0
- data/tests/hidraCordatusEmployer.rb +33 -0
- data/tests/hidraCordatusMaster.rb +51 -0
- metadata +216 -0
data/examples/example.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path("../../lib", __FILE__)
|
3
|
+
$: << File.expand_path("../../ext", __FILE__)
|
4
|
+
require 'capn_proto'
|
5
|
+
|
6
|
+
ADDRESSBOOK_SCHEMA = File.expand_path("../addressbook.capnp", __FILE__);
|
7
|
+
MESSAGE = File.expand_path("../addressbook.bin", __FILE__);
|
8
|
+
|
9
|
+
module AddressBook extend CapnProto::SchemaLoader
|
10
|
+
load_schema(ADDRESSBOOK_SCHEMA)
|
11
|
+
end
|
12
|
+
|
13
|
+
def print_address_book(file)
|
14
|
+
addresses = AddressBook::AddressBook.read_from(file)
|
15
|
+
|
16
|
+
addresses.people.each do |person|
|
17
|
+
puts "#{person.name} : #{person.email}"
|
18
|
+
person.phones.each do |phone|
|
19
|
+
puts "#{phone.type} : #{phone.number}"
|
20
|
+
end
|
21
|
+
|
22
|
+
which = person.employment.which
|
23
|
+
puts which
|
24
|
+
|
25
|
+
if which == "unemployed"
|
26
|
+
puts "unemployed"
|
27
|
+
elsif which == 'employer'
|
28
|
+
puts "employer: #{person.employment.employer}"
|
29
|
+
elsif which == "school"
|
30
|
+
puts "student at: #{person.employment.school}"
|
31
|
+
elsif which == "selfEmployed"
|
32
|
+
puts "self employed"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
file = File.open(MESSAGE, "rb")
|
38
|
+
print_address_book(file)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# vim: ts=2 et sw=2 sts=2
|
2
|
+
|
3
|
+
import os
|
4
|
+
import ycm_core
|
5
|
+
import glob
|
6
|
+
import subprocess
|
7
|
+
|
8
|
+
def RubyInclude():
|
9
|
+
cmd = ["ruby", "-e", "print RbConfig::CONFIG['rubyhdrdir']"]
|
10
|
+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
11
|
+
rubyhdrdir = process.stdout.read()
|
12
|
+
return rubyhdrdir
|
13
|
+
|
14
|
+
flags = [
|
15
|
+
'-Wall',
|
16
|
+
'-Wextra',
|
17
|
+
'-Werror',
|
18
|
+
'-fexceptions',
|
19
|
+
'-Wc++98-compat',
|
20
|
+
'-std=c++11',
|
21
|
+
'-x', 'c++',
|
22
|
+
'-I', '.',
|
23
|
+
'-I', '/usr/local/include',
|
24
|
+
'-I', RubyInclude(),
|
25
|
+
]
|
26
|
+
|
27
|
+
def DirectoryOfThisScript():
|
28
|
+
return os.path.dirname( os.path.abspath( __file__ ) )
|
29
|
+
|
30
|
+
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
|
31
|
+
if not working_directory:
|
32
|
+
return list( flags )
|
33
|
+
new_flags = []
|
34
|
+
make_next_absolute = False
|
35
|
+
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
|
36
|
+
for flag in flags:
|
37
|
+
new_flag = flag
|
38
|
+
|
39
|
+
if make_next_absolute:
|
40
|
+
make_next_absolute = False
|
41
|
+
if not flag.startswith( '/' ):
|
42
|
+
new_flag = os.path.join( working_directory, flag )
|
43
|
+
|
44
|
+
for path_flag in path_flags:
|
45
|
+
if flag == path_flag:
|
46
|
+
make_next_absolute = True
|
47
|
+
break
|
48
|
+
|
49
|
+
if flag.startswith( path_flag ):
|
50
|
+
path = flag[ len( path_flag ): ]
|
51
|
+
new_flag = path_flag + os.path.join( working_directory, path )
|
52
|
+
break
|
53
|
+
|
54
|
+
if new_flag:
|
55
|
+
new_flags.append( new_flag )
|
56
|
+
return new_flags
|
57
|
+
|
58
|
+
def FlagsForFile( filename ):
|
59
|
+
relative_to = DirectoryOfThisScript()
|
60
|
+
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
|
61
|
+
|
62
|
+
return {
|
63
|
+
'flags': final_flags,
|
64
|
+
'do_cache': True
|
65
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "EzRpc_client.h"
|
3
|
+
#include "capability_client.h"
|
4
|
+
#include "dynamic_capability_client.h"
|
5
|
+
#include "class_builder.h"
|
6
|
+
#include "exception.h"
|
7
|
+
#include "util.h"
|
8
|
+
|
9
|
+
namespace ruby_capn_proto {
|
10
|
+
using WrappedType = capnp::EzRpcClient;
|
11
|
+
VALUE EzRpcCapabilityClient::Class;
|
12
|
+
|
13
|
+
void EzRpcCapabilityClient::Init() {
|
14
|
+
ClassBuilder("EzRpcClient", rb_cObject).
|
15
|
+
defineAlloc(&alloc).
|
16
|
+
defineMethod("client", &make_dynamic).
|
17
|
+
defineMethod("initialize" , &create).
|
18
|
+
store(&Class);
|
19
|
+
}
|
20
|
+
|
21
|
+
void EzRpcCapabilityClient::free(WrappedType* p) {
|
22
|
+
ruby_xfree(p);
|
23
|
+
}
|
24
|
+
|
25
|
+
VALUE EzRpcCapabilityClient::alloc(VALUE klass) {
|
26
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
27
|
+
}
|
28
|
+
|
29
|
+
WrappedType* EzRpcCapabilityClient::unwrap(VALUE self) {
|
30
|
+
WrappedType* p;
|
31
|
+
Data_Get_Struct(self, WrappedType, p);
|
32
|
+
return p;
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE EzRpcCapabilityClient::create(VALUE self, VALUE dir, VALUE interschema) {
|
36
|
+
|
37
|
+
WrappedType* rb_self = unwrap(self);
|
38
|
+
new (rb_self) capnp::EzRpcClient(Util::toString(dir));
|
39
|
+
|
40
|
+
//store the InterfaceSchema
|
41
|
+
rb_iv_set(self,"schema",interschema);
|
42
|
+
|
43
|
+
return self;
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE EzRpcCapabilityClient::make_dynamic(VALUE self){
|
47
|
+
VALUE rb_schema = rb_iv_get(self,"schema");
|
48
|
+
VALUE rb_cap = CapabilityClient::create(unwrap(self)->getMain());
|
49
|
+
return DynamicCapabilityClient::create(rb_cap,rb_schema);
|
50
|
+
}
|
51
|
+
|
52
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef EZRPC_CAPABILITY_CLIENT_H
|
2
|
+
#define EXRPC_CAPABILITY_CLIENT_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class EzRpcCapabilityClient {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::EzRpcClient;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE create(VALUE self, VALUE dir, VALUE schema);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
static VALUE make_dynamic(VALUE self);
|
16
|
+
static VALUE Class;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
#endif /* EZRPC_CAPABILITY_CLIENT_H */
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "EzRpc_server.h"
|
3
|
+
#include "ruby_capability_server.h"
|
4
|
+
#include "interface_schema.h"
|
5
|
+
#include "exception.h"
|
6
|
+
#include "class_builder.h"
|
7
|
+
#include <ruby/thread.h>
|
8
|
+
#include "util.h"
|
9
|
+
|
10
|
+
namespace ruby_capn_proto {
|
11
|
+
using WrappedType = capnp::EzRpcServer;
|
12
|
+
VALUE EzRpcCapabilityServer::Class;
|
13
|
+
|
14
|
+
void EzRpcCapabilityServer::Init() {
|
15
|
+
ClassBuilder("EzRpcServer", rb_cObject).
|
16
|
+
defineAlloc(&alloc).
|
17
|
+
defineMethod("run" , &process).
|
18
|
+
defineMethod("initialize" , &create).
|
19
|
+
store(&Class);
|
20
|
+
}
|
21
|
+
|
22
|
+
void EzRpcCapabilityServer::free(WrappedType* p) {
|
23
|
+
ruby_xfree(p);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE EzRpcCapabilityServer::alloc(VALUE klass) {
|
27
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
28
|
+
}
|
29
|
+
|
30
|
+
WrappedType* EzRpcCapabilityServer::unwrap(VALUE self) {
|
31
|
+
WrappedType* p;
|
32
|
+
Data_Get_Struct(self, WrappedType, p);
|
33
|
+
return p;
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE EzRpcCapabilityServer::create(VALUE self, VALUE rb_capServer, VALUE dir) {
|
37
|
+
|
38
|
+
VALUE interschema = rb_iv_get(rb_capServer,"@schema");
|
39
|
+
auto schema = InterfaceSchema::unwrap(interschema);
|
40
|
+
|
41
|
+
WrappedType* rb_self = unwrap(self);
|
42
|
+
new (rb_self) capnp::EzRpcServer( kj::heap<capnp::RubyCapabilityServer>(*schema, rb_capServer) , Util::toString(dir) );
|
43
|
+
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE EzRpcCapabilityServer::process(VALUE self){
|
48
|
+
try{
|
49
|
+
loopCall l;
|
50
|
+
auto server = unwrap(self);
|
51
|
+
auto to_fulfill = kj::heap<kj::PromiseFulfillerPair<void>>(kj::newPromiseAndFulfiller<void>());
|
52
|
+
l.waitscope = &server->getWaitScope();
|
53
|
+
l.promisepair = to_fulfill.get();
|
54
|
+
rb_thread_call_without_gvl(loopServer, &l, stopLoopServer , l.promisepair);
|
55
|
+
}catch ( kj::Exception t ){
|
56
|
+
Exception::raise(t);
|
57
|
+
}
|
58
|
+
return Qtrue;
|
59
|
+
}
|
60
|
+
|
61
|
+
void * EzRpcCapabilityServer::loopServer(void * p){
|
62
|
+
try {
|
63
|
+
auto* loopcall = (loopCall*) p;
|
64
|
+
loopcall->promisepair->promise.wait(*(loopcall->waitscope));
|
65
|
+
}catch( kj::Exception t ){
|
66
|
+
//adquire the lock to raise a ruby exception
|
67
|
+
rb_thread_call_with_gvl(&Exception::raise,&t);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
void EzRpcCapabilityServer::stopLoopServer(void *p){
|
72
|
+
try {
|
73
|
+
auto* promisefulfiller = (kj::PromiseFulfillerPair<void>*) p;
|
74
|
+
promisefulfiller->fulfiller->fulfill();
|
75
|
+
}catch( kj::Exception t ){
|
76
|
+
Exception::raise(t);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef EZRPC_CAPABILITY_SERVER_H
|
2
|
+
#define EZRPC_CAPABILITY_SERVER_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
|
8
|
+
typedef struct _loopCall{
|
9
|
+
kj::WaitScope* waitscope;
|
10
|
+
kj::PromiseFulfillerPair<void>* promisepair;
|
11
|
+
} loopCall;
|
12
|
+
|
13
|
+
class EzRpcCapabilityServer {
|
14
|
+
public:
|
15
|
+
using WrappedType = capnp::EzRpcServer;
|
16
|
+
static void Init();
|
17
|
+
static VALUE alloc(VALUE klass);
|
18
|
+
static VALUE create(VALUE self, VALUE rb_server, VALUE dir);
|
19
|
+
static void free(WrappedType* p);
|
20
|
+
static WrappedType* unwrap(VALUE self);
|
21
|
+
static VALUE process(VALUE self);
|
22
|
+
static void * loopServer(void* p);
|
23
|
+
static void stopLoopServer(void* p);
|
24
|
+
// schema and rb_server to make new RubyCapabilityServer on the fly
|
25
|
+
static capnp::InterfaceSchema* schema(VALUE self);
|
26
|
+
static VALUE rb_server(VALUE self);
|
27
|
+
static VALUE Class;
|
28
|
+
};
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
#endif /* EZRPC_CAPABILITY_SERVER_H */
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "call_context.h"
|
3
|
+
#include "dynamic_struct_reader.h"
|
4
|
+
#include "dynamic_struct_builder.h"
|
5
|
+
#include "class_builder.h"
|
6
|
+
#include "util.h"
|
7
|
+
|
8
|
+
namespace ruby_capn_proto {
|
9
|
+
using WrappedType = capnp::CallContext<capnp::DynamicStruct, capnp::DynamicStruct>;
|
10
|
+
VALUE CallContext::Class;
|
11
|
+
|
12
|
+
void CallContext::Init() {
|
13
|
+
ClassBuilder("CallContext" , rb_cObject).
|
14
|
+
defineAlloc(&alloc).
|
15
|
+
defineMethod("getParams" , &getParams).
|
16
|
+
defineMethod("releaseParams" , &releaseParams).
|
17
|
+
defineMethod("getResults" , &getResults).
|
18
|
+
defineMethod("initResults" , &initResults).
|
19
|
+
defineMethod("setResults" , &setResults).
|
20
|
+
store(&Class);
|
21
|
+
}
|
22
|
+
|
23
|
+
void CallContext::free(WrappedType* p) {
|
24
|
+
p->~CallContext();
|
25
|
+
ruby_xfree(p);
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE CallContext::alloc(VALUE klass) {
|
29
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
30
|
+
}
|
31
|
+
|
32
|
+
WrappedType* CallContext::unwrap(VALUE self) {
|
33
|
+
WrappedType* p;
|
34
|
+
Data_Get_Struct(self, WrappedType, p);
|
35
|
+
return p;
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE CallContext::create(WrappedType context) {
|
39
|
+
VALUE rb_obj = alloc(Class);
|
40
|
+
WrappedType* wrapped_context = unwrap(rb_obj);
|
41
|
+
*wrapped_context = kj::mv(context);
|
42
|
+
return rb_obj;
|
43
|
+
}
|
44
|
+
|
45
|
+
VALUE CallContext::getParams(VALUE self) {
|
46
|
+
return DynamicStructReader::create(unwrap(self)->getParams(),Qnil);
|
47
|
+
}
|
48
|
+
|
49
|
+
VALUE CallContext::releaseParams(VALUE self) {
|
50
|
+
unwrap(self)->releaseParams();
|
51
|
+
return Qtrue;
|
52
|
+
}
|
53
|
+
|
54
|
+
VALUE CallContext::getResults(VALUE self) {
|
55
|
+
return DynamicStructBuilder::create(unwrap(self)->getResults(), Qnil, Qtrue);
|
56
|
+
}
|
57
|
+
|
58
|
+
VALUE CallContext::initResults(VALUE self) {
|
59
|
+
return DynamicStructBuilder::create(unwrap(self)->initResults(), Qnil, Qtrue );
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE CallContext::setResults(VALUE self, VALUE structReader) {
|
63
|
+
// maybe check the type of structReader?
|
64
|
+
unwrap(self)->setResults( *DynamicStructReader::unwrap(structReader) );
|
65
|
+
return Qtrue;
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#ifndef CONTEXT_H
|
2
|
+
#define CONTEXT_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class CallContext {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::CallContext<capnp::DynamicStruct, capnp::DynamicStruct>;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static void free(WrappedType* p);
|
13
|
+
static VALUE create(WrappedType context);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
static VALUE getParams(VALUE self);
|
16
|
+
static VALUE releaseParams(VALUE self);
|
17
|
+
static VALUE getResults(VALUE self);
|
18
|
+
static VALUE initResults(VALUE self);
|
19
|
+
static VALUE setResults(VALUE self, VALUE structBuilder);
|
20
|
+
|
21
|
+
static VALUE Class;
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
#endif /* CONTEXT_H */
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "capability_client.h"
|
3
|
+
#include "dynamic_capability_client.h"
|
4
|
+
#include "exception.h"
|
5
|
+
#include "class_builder.h"
|
6
|
+
#include "util.h"
|
7
|
+
|
8
|
+
namespace ruby_capn_proto {
|
9
|
+
using WrappedType = capnp::Capability::Client;
|
10
|
+
VALUE CapabilityClient::Class;
|
11
|
+
|
12
|
+
void CapabilityClient::Init() {
|
13
|
+
ClassBuilder("CapabilityClient", rb_cObject).
|
14
|
+
defineAlloc(&alloc).
|
15
|
+
defineMethod("to_dynamic" , &to_dynamic).
|
16
|
+
store(&Class);
|
17
|
+
}
|
18
|
+
|
19
|
+
void CapabilityClient::free(WrappedType* p) {
|
20
|
+
p->~Client();
|
21
|
+
ruby_xfree(p);
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE CapabilityClient::alloc(VALUE klass) {
|
25
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
26
|
+
}
|
27
|
+
|
28
|
+
WrappedType* CapabilityClient::unwrap(VALUE self) {
|
29
|
+
WrappedType* p;
|
30
|
+
Data_Get_Struct(self, WrappedType, p);
|
31
|
+
return p;
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE CapabilityClient::create(WrappedType native_client ) {
|
35
|
+
|
36
|
+
VALUE self = alloc(Class);
|
37
|
+
WrappedType* rb_self = unwrap(self);
|
38
|
+
new (rb_self) capnp::Capability::Client(native_client);
|
39
|
+
|
40
|
+
return self;
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE CapabilityClient::to_dynamic(VALUE self, VALUE schema){
|
44
|
+
return DynamicCapabilityClient::create(self,schema);
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef CAPABILITY_CLIENT_H
|
2
|
+
#define CAPABILITY_CLIENT_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class CapabilityClient {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::Capability::Client;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE create(WrappedType native_client);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
static VALUE to_dynamic(VALUE self, VALUE schema);
|
16
|
+
static VALUE Class;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
#endif /* CAPABILITY_CLIENT_H */
|