Class: StropheRuby::Context

Inherits:
Object
  • Object
show all
Defined in:
ext/strophe_ruby/strophe_ruby.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level) ⇒ Object

Ruby initialize for the context. Hmm… do we really need this?



104
105
106
107
# File 'ext/strophe_ruby/strophe_ruby.c', line 104

static VALUE t_xmpp_ctx_init(VALUE self, VALUE log_level) {
  rb_iv_set(self, "@log_level", log_level);
  return self;
}

Class Method Details

.new(log_level) ⇒ Object

Initialize a run time context



90
91
92
93
94
95
96
97
98
99
100
101
# File 'ext/strophe_ruby/strophe_ruby.c', line 90

VALUE t_xmpp_ctx_new(VALUE class, VALUE log_level) {
    xmpp_log_t *log;
    xmpp_log_level_t level;
    level=FIX2INT(log_level);
    log = xmpp_get_default_logger((xmpp_log_level_t)level);
    xmpp_ctx_t *ctx = xmpp_ctx_new(NULL, log);
    VALUE tdata = Data_Wrap_Struct(class, 0, free, ctx);
    VALUE argv[1];
    argv[0] = log_level;
    rb_obj_call_init(tdata,1,argv);
    return tdata;
}

Instance Method Details

#freeObject

free the context object (because it causes segmentation error once in a while)



65
66
67
68
69
# File 'ext/strophe_ruby/strophe_ruby.c', line 65

static VALUE t_xmpp_ctx_free(VALUE self) {
  xmpp_ctx_t *ctx;
  Data_Get_Struct(self,xmpp_ctx_t,ctx);
  xmpp_ctx_free(ctx);
}

#loop_statusObject

Get the status of the control loop TODO: Define ruby constants for the loop statuses. Currently we have to know them by heart (0 = NOTSTARTED, 1 = RUNNING, 2 = QUIT)



74
75
76
77
78
# File 'ext/strophe_ruby/strophe_ruby.c', line 74

static VALUE t_xmpp_get_loop_status(VALUE self) {
	xmpp_ctx_t *ctx;
	Data_Get_Struct(self, xmpp_ctx_t, ctx);
	return INT2FIX(ctx->loop_status);
}

#loop_status=(rb_loop_status) ⇒ Object

Set the loop status. Don’t call this method if you want to exit the control loop. Call xmpp_stop instead. This method will set the loop status at QUIT



82
83
84
85
86
87
# File 'ext/strophe_ruby/strophe_ruby.c', line 82

static VALUE t_xmpp_set_loop_status(VALUE self, VALUE rb_loop_status) {
	xmpp_ctx_t *ctx;
	Data_Get_Struct(self, xmpp_ctx_t, ctx);
	ctx->loop_status=FIX2INT(rb_loop_status);
	return rb_loop_status;
}