Add bsdcontrol_context_unwrap

This commit is contained in:
0x1eef 2024-10-12 13:30:29 -03:00
parent f7f3471e25
commit 3662599891
5 changed files with 14 additions and 14 deletions

View file

@ -41,14 +41,6 @@ bsdcontrol_open(VALUE path)
return fd; return fd;
} }
hbsdctrl_ctx_t *
bsdcontrol_unwrap(VALUE rbcontext)
{
hbsdctrl_ctx_t *ctx;
Data_Get_Struct(rbcontext, hbsdctrl_ctx_t, ctx);
return ctx;
}
hbsdctrl_feature_t * hbsdctrl_feature_t *
bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature) bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature)
{ {

View file

@ -3,5 +3,4 @@
#include <libhbsdcontrol.h> #include <libhbsdcontrol.h>
int bsdcontrol_open(VALUE); int bsdcontrol_open(VALUE);
hbsdctrl_ctx_t* bsdcontrol_unwrap(VALUE);
hbsdctrl_feature_t* bsdcontrol_find_feature(hbsdctrl_ctx_t*, VALUE); hbsdctrl_feature_t* bsdcontrol_find_feature(hbsdctrl_ctx_t*, VALUE);

View file

@ -19,6 +19,14 @@ bsdcontrol_context_alloc(VALUE klass)
return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, ctx); return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, ctx);
} }
hbsdctrl_ctx_t *
bsdcontrol_context_unwrap(VALUE rbcontext)
{
hbsdctrl_ctx_t *ctx;
Data_Get_Struct(rbcontext, hbsdctrl_ctx_t, ctx);
return ctx;
}
static void static void
bsdcontrol_context_free(hbsdctrl_ctx_t *ctx) bsdcontrol_context_free(hbsdctrl_ctx_t *ctx)
{ {
@ -39,7 +47,7 @@ bsdcontrol_context_available_features(VALUE self)
feature = 0, features = rb_ary_new(); feature = 0, features = rb_ary_new();
hbsdctrl_ctx_t *ctx; hbsdctrl_ctx_t *ctx;
char **name; char **name;
ctx = bsdcontrol_unwrap(self); ctx = bsdcontrol_context_unwrap(self);
name = hbsdctrl_ctx_all_feature_names(ctx); name = hbsdctrl_ctx_all_feature_names(ctx);
while (*name != NULL) while (*name != NULL)
{ {
@ -59,6 +67,6 @@ VALUE
bsdcontrol_context_library_version(VALUE self) bsdcontrol_context_library_version(VALUE self)
{ {
hbsdctrl_ctx_t *ctx; hbsdctrl_ctx_t *ctx;
ctx = bsdcontrol_unwrap(self); ctx = bsdcontrol_context_unwrap(self);
return ULONG2NUM(ctx->hc_version); return ULONG2NUM(ctx->hc_version);
} }

View file

@ -4,3 +4,4 @@
VALUE bsdcontrol_context_alloc(VALUE); VALUE bsdcontrol_context_alloc(VALUE);
VALUE bsdcontrol_context_library_version(VALUE); VALUE bsdcontrol_context_library_version(VALUE);
VALUE bsdcontrol_context_available_features(VALUE); VALUE bsdcontrol_context_available_features(VALUE);
hbsdctrl_ctx_t* bsdcontrol_context_unwrap(VALUE);

View file

@ -19,7 +19,7 @@ bsdcontrol_feature_status(VALUE self, VALUE path)
hbsdctrl_ctx_t *ctx; hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0); rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path); fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_find_feature(ctx, self);
errno = 0; errno = 0;
if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL) if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL)
@ -50,7 +50,7 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
int state; int state;
rbcontext = rb_funcall(self, rb_intern("context"), 0); rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path); fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_find_feature(ctx, self);
state = NUM2INT(rbstate); state = NUM2INT(rbstate);
errno = 0; errno = 0;
@ -79,7 +79,7 @@ bsdcontrol_feature_sysdef(VALUE self, VALUE path)
hbsdctrl_ctx_t *ctx; hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0); rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path); fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_find_feature(ctx, self);
errno = 0; errno = 0;
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL) if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)