Add bsdcontrol_feature_find_by_name

This commit is contained in:
0x1eef 2024-10-12 13:35:58 -03:00
parent 3662599891
commit e6a48c3216
4 changed files with 17 additions and 13 deletions

View file

@ -40,12 +40,3 @@ bsdcontrol_open(VALUE path)
} }
return fd; return fd;
} }
hbsdctrl_feature_t *
bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature)
{
VALUE name;
name = rb_funcall(rbfeature, rb_intern("name"), 0);
Check_Type(name, T_STRING);
return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name));
}

View file

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

View file

@ -20,7 +20,7 @@ bsdcontrol_feature_status(VALUE self, VALUE path)
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_context_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_feature_find_by_name(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)
{ {
@ -51,7 +51,7 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
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_context_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_feature_find_by_name(ctx, self);
state = NUM2INT(rbstate); state = NUM2INT(rbstate);
errno = 0; errno = 0;
if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL) if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL)
@ -80,7 +80,7 @@ bsdcontrol_feature_sysdef(VALUE self, VALUE path)
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_context_unwrap(rbcontext); ctx = bsdcontrol_context_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self); feature = bsdcontrol_feature_find_by_name(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)
{ {
@ -94,3 +94,12 @@ bsdcontrol_feature_sysdef(VALUE self, VALUE path)
return Qtrue; return Qtrue;
} }
} }
hbsdctrl_feature_t *
bsdcontrol_feature_find_by_name(hbsdctrl_ctx_t *ctx, VALUE rbfeature)
{
VALUE name;
name = rb_funcall(rbfeature, rb_intern("name"), 0);
Check_Type(name, T_STRING);
return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name));
}

View file

@ -1,4 +1,9 @@
#pragma once
#include <ruby.h> #include <ruby.h>
#include <libhbsdcontrol.h>
VALUE bsdcontrol_feature_status(VALUE, VALUE); VALUE bsdcontrol_feature_status(VALUE, VALUE);
VALUE bsdcontrol_feature_set(VALUE,VALUE,VALUE); VALUE bsdcontrol_feature_set(VALUE,VALUE,VALUE);
VALUE bsdcontrol_feature_sysdef(VALUE, VALUE); VALUE bsdcontrol_feature_sysdef(VALUE, VALUE);
hbsdctrl_feature_t* bsdcontrol_feature_find_by_name(hbsdctrl_ctx_t*, VALUE);