rpm  5.4.4
ruby/rpmps-rb.c
Go to the documentation of this file.
00001 
00007 #include "system.h"
00008 
00009 #include "rpm-rb.h"
00010 #include "rpmps-rb.h"
00011 
00012 #ifdef  NOTYET
00013 #include <argv.h>
00014 #include <mire.h>
00015 #endif
00016 
00017 #define _RPMFI_INTERNAL
00018 #include <rpmtag.h>
00019 #include <rpmtypes.h>
00020 #include <rpmio.h>
00021 #include <rpmfi.h>
00022 #include <rpmps.h>
00023 
00024 #include "../debug.h"
00025 
00026 
00027 VALUE rpmpsClass;
00028 
00029 /*@unchecked@*/
00030 static int _debug = 0;
00031 
00032 
00033 /* --- helpers */
00034 static void *
00035 rpmps_ptr(VALUE s)
00036 {
00037     void *ptr;
00038     Data_Get_Struct(s, void, ptr);
00039     return ptr;
00040 }
00041 
00042 /* --- Object methods */
00043 static VALUE
00044 rpmps_push(VALUE s)
00045 {
00046     void *ptr = rpmps_ptr(s);
00047     rpmps ps = ptr;
00048     char *pkgNEVR = "PKG";
00049     char *altNEVR = "ALT";
00050     char *key = "KEY";
00051     rpmProblemType type = RPMPROB_PKG_INSTALLED;
00052     char *dn = "/root/";
00053     char *bn = "file";
00054     unsigned ui = 1234;
00055 
00056 if (_debug)
00057 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
00058     rpmpsAppend(ps, type, pkgNEVR, key, dn, bn, altNEVR, ui);
00059     return INT2FIX(rpmpsNumProblems(ps));
00060 }
00061 
00062 static VALUE
00063 rpmps_print(VALUE s)
00064 {
00065     void *ptr = rpmps_ptr(s);
00066     rpmps ps = ptr;
00067 
00068 if (_debug)
00069 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
00070     rpmpsPrint(NULL, ps);
00071     return INT2FIX(rpmpsNumProblems(ps));
00072 }
00073 
00074 static void
00075 initMethods(VALUE klass)
00076 {
00077     rb_define_method(klass, "push", rpmps_push, 7);
00078     rb_define_method(klass, "print", rpmps_print, 0);
00079 }
00080 
00081 /* --- Object properties */
00082 static VALUE
00083 rpmps_debug_get(VALUE s)
00084 {
00085 if (_debug)
00086 fprintf(stderr, "==> %s(0x%lx)\n", __FUNCTION__, s);
00087     return INT2FIX(_debug);
00088 }
00089 
00090 static VALUE
00091 rpmps_debug_set(VALUE s, VALUE v)
00092 {
00093 if (_debug)
00094 fprintf(stderr, "==> %s(0x%lx, 0x%lx)\n", __FUNCTION__, s, v);
00095     return INT2FIX(_debug = FIX2INT(v));
00096 }
00097 
00098 static VALUE
00099 rpmps_length_get(VALUE s)
00100 {
00101     void *ptr = rpmps_ptr(s);
00102     rpmps ps = ptr;
00103 if (_debug)
00104 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
00105     return INT2FIX(rpmpsNumProblems(ps));
00106 }
00107 
00108 #ifdef  NOTYET
00109 static VALUE
00110 rpmps_rootdir_set(VALUE s, VALUE v)
00111 {
00112     void *ptr = rpmps_ptr(s);
00113     rpmps ps = ptr;
00114 if (_debug)
00115 fprintf(stderr, "==> %s(0x%lx, 0x%lx) ptr %p\n", __FUNCTION__, s, v, ptr);
00116     rpmpsSetRootDir(ps, StringValueCStr(v));
00117     return rb_str_new2(rpmpsRootDir(ps));
00118 }
00119 
00120 static VALUE
00121 rpmps_vsflags_get(VALUE s)
00122 {
00123     void *ptr = rpmps_ptr(s);
00124     rpmps ps = ptr;
00125 if (_debug)
00126 fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ptr);
00127     return INT2FIX(_debug);
00128 }
00129 
00130 static VALUE
00131 rpmps_vsflags_set(VALUE s, VALUE v)
00132 {
00133     void *ptr = rpmps_ptr(s);
00134     rpmps ps = ptr;
00135 if (_debug)
00136 fprintf(stderr, "==> %s(0x%lx, 0x%lx) ptr %p\n", __FUNCTION__, s, v, ptr);
00137     rpmpsSetVSFlags(ps, FIX2INT(v));
00138     return INT2FIX(rpmpsVSFlags(ps));
00139 }
00140 #endif  /* NOTYET */
00141 
00142 static void
00143 initProperties(VALUE klass)
00144 {
00145     rb_define_method(klass, "debug", rpmps_debug_get, 0);
00146     rb_define_method(klass, "debug=", rpmps_debug_set, 1);
00147     rb_define_method(klass, "length", rpmps_length_get, 0);
00148 #ifdef  NOTYET
00149     rb_define_method(klass, "rootdir", rpmps_rootdir_get, 0);
00150     rb_define_method(klass, "rootdir=", rpmps_rootdir_set, 1);
00151     rb_define_method(klass, "vsflags", rpmps_vsflags_get, 0);
00152     rb_define_method(klass, "vsflags=", rpmps_vsflags_set, 1);
00153 #endif  /* NOTYET */
00154 }
00155 
00156 /* --- Object ctors/dtors */
00157 static void
00158 rpmps_free(rpmps ps)
00159 {
00160 if (_debug)
00161 fprintf(stderr, "==> %s(%p)\n", __FUNCTION__, ps);
00162     ps = rpmpsFree(ps);
00163 }
00164 
00165 static VALUE
00166 rpmps_alloc(VALUE klass)
00167 {
00168     rpmps ps = rpmpsCreate();
00169     VALUE obj = Data_Wrap_Struct(klass, 0, rpmps_free, ps);
00170 if (_debug)
00171 fprintf(stderr, "==> %s(0x%lx) obj 0x%lx ps %p\n", __FUNCTION__, klass, obj, ps);
00172     return obj;
00173 }
00174 
00175 /* --- Class initialization */
00176 
00177 void
00178 Init_rpmps(void)
00179 {
00180     rpmpsClass = rb_define_class("Ps", rb_cObject);
00181 if (_debug)
00182 fprintf(stderr, "==> %s() rpmpsClass 0x%lx\n", __FUNCTION__, rpmpsClass);
00183     rb_define_alloc_func(rpmpsClass, rpmps_alloc);
00184     initProperties(rpmpsClass);
00185     initMethods(rpmpsClass);
00186 }