Archived
1
0
Fork 0

Implement Tox#loop

This commit is contained in:
Braiden Vasco 2015-09-13 10:36:55 +00:00
parent 225e695a3d
commit 1200500545
3 changed files with 30 additions and 0 deletions

View file

@ -14,5 +14,7 @@ have_library LIBTOXCORE, 'tox_self_get_address' and
have_library LIBTOXCORE, 'tox_bootstrap' and have_library LIBTOXCORE, 'tox_bootstrap' and
have_library LIBTOXCORE, 'tox_kill' and have_library LIBTOXCORE, 'tox_kill' and
have_library LIBTOXCORE, 'tox_version_is_compatible' and have_library LIBTOXCORE, 'tox_version_is_compatible' and
have_library LIBTOXCORE, 'tox_iteration_interval' and
have_library LIBTOXCORE, 'tox_iterate' and
create_makefile "#{NAME}/#{NAME}" or exit(1) create_makefile "#{NAME}/#{NAME}" or exit(1)

View file

@ -1,5 +1,7 @@
#include <ruby.h> #include <ruby.h>
#include <time.h>
#include <tox/tox.h> #include <tox/tox.h>
#define TOX_IS_COMPATIBLE TOX_VERSION_IS_API_COMPATIBLE #define TOX_IS_COMPATIBLE TOX_VERSION_IS_API_COMPATIBLE
@ -34,6 +36,7 @@ static VALUE cTox_savedata(VALUE self);
static VALUE cTox_id(VALUE self); static VALUE cTox_id(VALUE self);
static VALUE cTox_bootstrap(VALUE self, VALUE options); static VALUE cTox_bootstrap(VALUE self, VALUE options);
static VALUE cTox_kill(VALUE self); static VALUE cTox_kill(VALUE self);
static VALUE cTox_loop(VALUE self);
typedef struct Tox_Options cTox_cOptions_; typedef struct Tox_Options cTox_cOptions_;
@ -55,6 +58,7 @@ void Init_tox()
rb_define_method(cTox, "id", cTox_id, 0); rb_define_method(cTox, "id", cTox_id, 0);
rb_define_method(cTox, "bootstrap", cTox_bootstrap, 1); rb_define_method(cTox, "bootstrap", cTox_bootstrap, 1);
rb_define_method(cTox, "kill", cTox_kill, 0); rb_define_method(cTox, "kill", cTox_kill, 0);
rb_define_method(cTox, "loop", cTox_loop, 0);
cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject); cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc); rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
@ -201,6 +205,28 @@ VALUE cTox_kill(const VALUE self)
return self; return self;
} }
VALUE cTox_loop(const VALUE self)
{
cTox_ *tox;
struct timespec delay;
Data_Get_Struct(self, cTox_, tox);
rb_funcall(self, rb_intern("running="), 1, Qtrue);
delay.tv_sec = 0;
while (rb_funcall(self, rb_intern("running"), 0)) {
delay.tv_nsec = tox_iteration_interval(tox->tox) * 1000000;
nanosleep(&delay, NULL);
tox_iterate(tox->tox);
}
return self;
}
/****************************************************************************** /******************************************************************************
* Tox::Options * Tox::Options
******************************************************************************/ ******************************************************************************/

View file

@ -1,6 +1,8 @@
require 'tox/tox' require 'tox/tox'
class Tox class Tox
attr_accessor :running
def initialize(options = Tox::Options.new) def initialize(options = Tox::Options.new)
initialize_with(options) initialize_with(options)
end end