<commit_before>#include "cim_client.h"
#include "cim_enumeration.h"
#include "cim_object_path.h"
#include "cim_class.h"
#include "cim_instance.h"

static void
dealloc(CMCIClient *client)
{
  SFCC_DEC_REFCOUNT(client);
}

/**
 * call-seq:
 *  get_class(object_path, flags=0, properties=nil)
 *
 * Get Class using +object_path+ as reference. Class structure can be
 * controled using the flags parameter.
 *
 * +object_path+ ObjectPath containing nameSpace and classname components.
 *
 * +flags+ Any combination of the following flags are supported:
 *  Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 *
 * +properties+ If not nil, the members of the array define one or more Property
 * names. Each returned Object MUST NOT include elements for any Properties
 * missing from this list
 */
static VALUE get_class(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;
  VALUE properties;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  CMPIConstClass *cimclass = NULL;
  CMPIConstClass *cimclassnew = NULL;
  char **props;

  rb_scan_args(argc, argv, "12", &object_path, &flags, &properties);

  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  props = sfcc_value_array_to_string_array(properties);
  cimclass = client->ft->getClass(client, op, NUM2INT(flags), props, &status);
  free(props);

  if (!status.rc) {
      cimclassnew = cimclass->ft->clone(cimclass, NULL);
      cimclass->ft->release(cimclass);
      return Sfcc_wrap_cim_class(cimclassnew);
  }
  sfcc_rb_raise_if_error(status, "Can't get class at %s", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
  return Qnil;
}

/**
 * call-seq:
 *  class_names(object_path, flags=0)
 *
 * return the available class names for the given
 * +object_path+ and +flags+
 *
 * The following flag is supported: Flags::DeepInheritance.
 */
static VALUE class_names(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  VALUE rbenm = Qnil;

  rb_scan_args(argc, argv, "11", &object_path, &flags);
  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  CMPIEnumeration *enm = client->ft->enumClassNames(client, op, NUM2INT(flags), &status);
  if (enm && !status.rc ) {
    rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
    enm->ft->release(enm);
    return rbenm;
  }

  sfcc_rb_raise_if_error(status, "Can't get class names");
  return Qnil;
}

/**
 * call-seq:
 *  classes(object_path, flags=0)
 *
 * classes and subclasses in the namespace defined by +object_path+.
 *
 * Class structure and inheritance scope can be controled using the +flags+ parameter
 * Any combination of the following flags are supported:
 * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 */
static VALUE classes(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  VALUE rbenm = Qnil;

  rb_scan_args(argc, argv, "11", &object_path, &flags);
  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  CMPIEnumeration *enm = client->ft->enumClasses(client, op, NUM2INT(flags), &status);
  if (enm && !status.rc ) {
    rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
    enm->ft->release(enm);
    return rbenm;
  }

  sfcc_rb_raise_if_error(status, "Can't get classes");
  return Qnil;
}

/**
 * call-seq:
 *  get_instance(object_path, flags=0, properties=nil)
 *
 * get instance using +object_path+ as reference. Instance structure
 * can be controlled using the flags parameter.
 *
 * +object_path+ an ObjectPath containing namespace, class name and key
 * components.
 *
 * +flags+ Any combination of the following flags are supported:
 * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 *
 * +properties+ If not nil, the members of the array define one or more Property
 * names. Each returned Object MUST NOT include elements for any Properties
 * missing from this list
 */
static VALUE get_instance(int argc, VALUE *argv, VALUE self)<commit_msg>Add a hint if EnumerateClasses fails (due to maxMsgLen too low)<commit_after>#include "cim_client.h"
#include "cim_enumeration.h"
#include "cim_object_path.h"
#include "cim_class.h"
#include "cim_instance.h"

static void
dealloc(CMCIClient *client)
{
  SFCC_DEC_REFCOUNT(client);
}

/**
 * call-seq:
 *  get_class(object_path, flags=0, properties=nil)
 *
 * Get Class using +object_path+ as reference. Class structure can be
 * controled using the flags parameter.
 *
 * +object_path+ ObjectPath containing nameSpace and classname components.
 *
 * +flags+ Any combination of the following flags are supported:
 *  Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 *
 * +properties+ If not nil, the members of the array define one or more Property
 * names. Each returned Object MUST NOT include elements for any Properties
 * missing from this list
 */
static VALUE get_class(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;
  VALUE properties;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  CMPIConstClass *cimclass = NULL;
  CMPIConstClass *cimclassnew = NULL;
  char **props;

  rb_scan_args(argc, argv, "12", &object_path, &flags, &properties);

  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  props = sfcc_value_array_to_string_array(properties);
  cimclass = client->ft->getClass(client, op, NUM2INT(flags), props, &status);
  free(props);

  if (!status.rc) {
      cimclassnew = cimclass->ft->clone(cimclass, NULL);
      cimclass->ft->release(cimclass);
      return Sfcc_wrap_cim_class(cimclassnew);
  }
  sfcc_rb_raise_if_error(status, "Can't get class at %s", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
  return Qnil;
}

/**
 * call-seq:
 *  class_names(object_path, flags=0)
 *
 * return the available class names for the given
 * +object_path+ and +flags+
 *
 * The following flag is supported: Flags::DeepInheritance.
 */
static VALUE class_names(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  VALUE rbenm = Qnil;

  rb_scan_args(argc, argv, "11", &object_path, &flags);
  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  CMPIEnumeration *enm = client->ft->enumClassNames(client, op, NUM2INT(flags), &status);
  if (enm && !status.rc ) {
    rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
    enm->ft->release(enm);
    return rbenm;
  }

  sfcc_rb_raise_if_error(status, "Can't get class names");
  return Qnil;
}

/**
 * call-seq:
 *  classes(object_path, flags=0)
 *
 * classes and subclasses in the namespace defined by +object_path+.
 *
 * Class structure and inheritance scope can be controled using the +flags+ parameter
 * Any combination of the following flags are supported:
 * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 */
static VALUE classes(int argc, VALUE *argv, VALUE self)
{
  VALUE object_path;
  VALUE flags;

  CMPIStatus status = {CMPI_RC_OK, NULL};
  CMPIObjectPath *op = NULL;
  CMCIClient *client = NULL;
  VALUE rbenm = Qnil;

  rb_scan_args(argc, argv, "11", &object_path, &flags);
  if (NIL_P(flags)) flags = INT2NUM(0);

  Data_Get_Struct(self, CMCIClient, client);
  Data_Get_Struct(object_path, CMPIObjectPath, op);

  CMPIEnumeration *enm = client->ft->enumClasses(client, op, NUM2INT(flags), &status);
  if (enm && !status.rc ) {
    rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
    enm->ft->release(enm);
    return rbenm;
  }

  sfcc_rb_raise_if_error(status, "Can't get classes, try increasing maxMsgLen in sfcb.cfg ?");
  return Qnil;
}

/**
 * call-seq:
 *  get_instance(object_path, flags=0, properties=nil)
 *
 * get instance using +object_path+ as reference. Instance structure
 * can be controlled using the flags parameter.
 *
 * +object_path+ an ObjectPath containing namespace, class name and key
 * components.
 *
 * +flags+ Any combination of the following flags are supported:
 * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
 *
 * +properties+ If not nil, the members of the array define one or more Property
 * names. Each returned Object MUST NOT include elements for any Properties
 * missing from this list
 */
static VALUE get_instance(int argc, VALUE *argv, VALUE self)
{'fraction_non_alphanumeric': 0.11597252990695614, 'fraction_numerical': 0.004209127159946832, 'mean_word_length': 4.7363405336721724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6573287', 'n_tokens_mistral': 3175, 'n_tokens_neox': 3116, 'n_words': 848}