コード例 #1
0
ファイル: uname.c プロジェクト: zigloo99/pdl_prescription
/* An interface for returning uname (platform) information. */
void Init_uname()
{
   VALUE mSys, cUname;

   /* The Sys module serves only as a toplevel namespace */
   mSys = rb_define_module("Sys");

   /* The Uname serves as the base class from which system information can
    * be obtained via various class methods.
    */
   cUname = rb_define_class_under(mSys, "Uname", rb_cObject);

   rb_define_singleton_method(cUname, "sysname", uname_sysname, 0);
   rb_define_singleton_method(cUname, "nodename",uname_nodename,0);
   rb_define_singleton_method(cUname, "machine", uname_machine, 0);
   rb_define_singleton_method(cUname, "version", uname_version, 0);
   rb_define_singleton_method(cUname, "release", uname_release, 0);
   rb_define_singleton_method(cUname, "uname", uname_uname_all, 0);

#ifdef HAVE_SYS_SYSTEMINFO_H
   rb_define_singleton_method(cUname, "architecture", uname_architecture, 0);
   rb_define_singleton_method(cUname, "platform", uname_platform, 0);
   rb_define_singleton_method(cUname, "hw_provider", uname_hw_provider, 0);
   rb_define_singleton_method(cUname, "hw_serial_number", uname_hw_serial, 0);
   rb_define_singleton_method(cUname, "srpc_domain", uname_srpc_domain, 0);
#ifdef SI_ISALIST
   rb_define_singleton_method(cUname, "isa_list", uname_isalist, 0);
#endif
#ifdef SI_DHCP_CACHE
   rb_define_singleton_method(cUname, "dhcp_cache", uname_dhcp_cache, 0);
#endif
#endif

#ifdef HAVE_SYSCTL
   rb_define_singleton_method(cUname, "model", uname_model, 0);
#endif

#if defined(__hpux)
   rb_define_singleton_method(cUname, "id_number", uname_id, 0);
#endif

   /* The UnameStruct encapsulates information associated with system
    * information, such as operating system version, release, etc.
    */
   sUname = rb_struct_define("UnameStruct","sysname","nodename",
      "machine","version","release",
#ifdef HAVE_SYS_SYSTEMINFO_H
      "architecture","platform",
#endif

#ifdef HAVE_SYSCTL
      "model",
#endif

#if defined(__hpux)
      "id_number",
#endif
   NULL);

   /* 0.8.5: The version of this library */
   rb_define_const(cUname, "VERSION", rb_str_new2(SYS_UNAME_VERSION));
}
コード例 #2
0
ファイル: rb_call.c プロジェクト: Saviio/grpc
void Init_grpc_call() {
  /* CallError inherits from Exception to signal that it is non-recoverable */
  grpc_rb_eCallError =
      rb_define_class_under(grpc_rb_mGrpcCore, "CallError", rb_eException);
  grpc_rb_eOutOfTime =
      rb_define_class_under(grpc_rb_mGrpcCore, "OutOfTime", rb_eException);
  grpc_rb_cCall = rb_define_class_under(grpc_rb_mGrpcCore, "Call", rb_cObject);
  grpc_rb_cMdAry =
      rb_define_class_under(grpc_rb_mGrpcCore, "MetadataArray", rb_cObject);

  /* Prevent allocation or inialization of the Call class */
  rb_define_alloc_func(grpc_rb_cCall, grpc_rb_cannot_alloc);
  rb_define_method(grpc_rb_cCall, "initialize", grpc_rb_cannot_init, 0);
  rb_define_method(grpc_rb_cCall, "initialize_copy", grpc_rb_cannot_init_copy,
                   1);

  /* Add ruby analogues of the Call methods. */
  rb_define_method(grpc_rb_cCall, "run_batch", grpc_rb_call_run_batch, 4);
  rb_define_method(grpc_rb_cCall, "cancel", grpc_rb_call_cancel, 0);
  rb_define_method(grpc_rb_cCall, "peer", grpc_rb_call_get_peer, 0);
  rb_define_method(grpc_rb_cCall, "status", grpc_rb_call_get_status, 0);
  rb_define_method(grpc_rb_cCall, "status=", grpc_rb_call_set_status, 1);
  rb_define_method(grpc_rb_cCall, "metadata", grpc_rb_call_get_metadata, 0);
  rb_define_method(grpc_rb_cCall, "metadata=", grpc_rb_call_set_metadata, 1);
  rb_define_method(grpc_rb_cCall, "write_flag", grpc_rb_call_get_write_flag, 0);
  rb_define_method(grpc_rb_cCall, "write_flag=", grpc_rb_call_set_write_flag,
                   1);
  rb_define_method(grpc_rb_cCall, "set_credentials!",
                   grpc_rb_call_set_credentials, 1);

  /* Ids used to support call attributes */
  id_metadata = rb_intern("metadata");
  id_status = rb_intern("status");
  id_write_flag = rb_intern("write_flag");

  /* Ids used by the c wrapping internals. */
  id_cq = rb_intern("__cq");
  id_flags = rb_intern("__flags");
  id_input_md = rb_intern("__input_md");
  id_credentials = rb_intern("__credentials");

  /* Ids used in constructing the batch result. */
  sym_send_message = ID2SYM(rb_intern("send_message"));
  sym_send_metadata = ID2SYM(rb_intern("send_metadata"));
  sym_send_close = ID2SYM(rb_intern("send_close"));
  sym_send_status = ID2SYM(rb_intern("send_status"));
  sym_message = ID2SYM(rb_intern("message"));
  sym_status = ID2SYM(rb_intern("status"));
  sym_cancelled = ID2SYM(rb_intern("cancelled"));

  /* The Struct used to return the run_batch result. */
  grpc_rb_sBatchResult = rb_struct_define(
      "BatchResult", "send_message", "send_metadata", "send_close",
      "send_status", "message", "metadata", "status", "cancelled", NULL);

  /* The hash for reference counting calls, to ensure they can't be destroyed
   * more than once */
  hash_all_calls = rb_hash_new();
  rb_define_const(grpc_rb_cCall, "INTERNAL_ALL_CALLs", hash_all_calls);

  Init_grpc_error_codes();
  Init_grpc_op_codes();
  Init_grpc_write_flags();
}
コード例 #3
0
/*
 * The etc module provides access to information from the running OS.
 *
 * Documented by mathew <*****@*****.**>.
 */
void
Init_etc(void)
{
    VALUE mEtc;

    mEtc = rb_define_module("Etc");
    rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);

    rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
    rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
    rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
    rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
    rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
    rb_define_module_function(mEtc, "passwd", etc_passwd, 0);

    rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
    rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
    rb_define_module_function(mEtc, "group", etc_group, 0);
    rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
    rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
    rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
    rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
    rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);

    sPasswd =  rb_struct_define("Passwd",
                                "name", "passwd", "uid", "gid",
#ifdef HAVE_ST_PW_GECOS
                                "gecos",
#endif
                                "dir", "shell",
#ifdef HAVE_ST_PW_CHANGE
                                "change",
#endif
#ifdef HAVE_ST_PW_QUOTA
                                "quota",
#endif
#ifdef HAVE_ST_PW_AGE
                                "age",
#endif
#ifdef HAVE_ST_PW_CLASS
                                "uclass",
#endif
#ifdef HAVE_ST_PW_COMMENT
                                "comment",
#endif
#ifdef HAVE_ST_PW_EXPIRE
                                "expire",
#endif
                                NULL);
    rb_define_const(mEtc, "Passwd", sPasswd);
    rb_extend_object(sPasswd, rb_mEnumerable);
    rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);

#ifdef HAVE_GETGRENT
    sGroup = rb_struct_define("Group", "name",
#ifdef HAVE_ST_GR_PASSWD
                              "passwd",
#endif
                              "gid", "mem", NULL);

    rb_define_const(mEtc, "Group", sGroup);
    rb_extend_object(sGroup, rb_mEnumerable);
    rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
#endif
}
コード例 #4
0
ファイル: proctable.c プロジェクト: jrafanie/sys-proctable
/*
 * A Ruby interface for gathering process table information.
 */
void Init_proctable(){
  VALUE mSys, cProcTable;

  /* The Sys module serves as a namespace only */
  mSys = rb_define_module("Sys");

  /* The ProcTable class encapsulates process table information */
  cProcTable = rb_define_class_under(mSys, "ProcTable", rb_cObject);

  /* The Error class typically raised if any of the ProcTable methods fail */
  cProcTableError = rb_define_class_under(cProcTable, "Error", rb_eStandardError);

  /* Singleton methods */

  rb_define_singleton_method(cProcTable, "ps", pt_ps, -1);
  rb_define_singleton_method(cProcTable, "fields", pt_fields, 0);

  /* There is no constructor */
  rb_funcall(cProcTable, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));

  /* 0.9.9: The version of the sys-proctable library */
  rb_define_const(cProcTable, "VERSION", rb_str_new2("0.9.9"));

  /* Structs */

  sProcStruct = rb_struct_define("ProcTableStruct",
    "pid",         /* Process identifier */
    "ppid",        /* Parent process id */
    "pgid",        /* Process group id */
    "ruid",        /* Real user id */
    "rgid",        /* Real group id */
    "euid",        /* Effective user id */
    "egid",        /* Effective group id */
    "groups",      /* All effective group ids */
    "svuid",       /* Saved effective user id */
    "svgid",       /* Saved effective group id */
    "comm",        /* Command name (15 chars) */
    "state",       /* Process status */
    "pctcpu",      /* %cpu for this process during p_swtime */
    "oncpu",       /* nil */
    "tnum",        /* Controlling tty dev */
    "tdev",        /* Controlling tty name */
    "wmesg",       /* Wchan message */
    "rtime",       /* Real time */
    "priority",    /* Process priority */
    "usrpri",      /* User-priority */
    "nice",        /* Process "nice" value */
    "cmdline",     /* Complete command line */
    "exe",         /* Saved pathname of the executed command */
    "environ",     /* Hash with process environment variables */
    "starttime",   /* Process start time */
    "maxrss",      /* Max resident set size (PL) */
    "ixrss",       /* Integral shared memory size (NU) */
    "idrss",       /* Integral unshared data (NU) */
    "isrss",       /* Integral unshared stack (NU) */
    "minflt",      /* Page reclaims (NU) */
    "majflt",      /* Page faults (NU) */
    "nswap",       /* Swaps (NU) */
    "inblock",     /* Block input operations (atomic) */
    "oublock",     /* Block output operations (atomic) */
    "msgsnd",      /* Messages sent (atomic) */
    "msgrcv",      /* Messages received (atomic) */
    "nsignals",    /* Signals received (atomic) */
    "nvcsw",       /* Voluntary context switches (atomic) */
    "nivcsw",      /* Involuntary context switches (atomic) */
    "utime",       /* User time used (PL) */
    "stime",       /* System time used (PL) */
    NULL
  );
}
コード例 #5
0
ファイル: etc.c プロジェクト: Chatto/VGdesk
/*
 * The Etc module provides access to information typically stored in
 * files in the /etc directory on Unix systems.
 *
 * The information accessible consists of the information found in the
 * /etc/passwd and /etc/group files, plus information about the system's
 * temporary directory (/tmp) and configuration directory (/etc).
 *
 * The Etc module provides a more reliable way to access information about
 * the logged in user than environment variables such as +$USER+.
 *
 * == Example:
 *
 *     require 'etc'
 *
 *     login = Etc.getlogin
 *     info = Etc.getpwnam(login)
 *     username = info.gecos.split(/,/).first
 *     puts "Hello #{username}, I see your login name is #{login}"
 *
 * Note that the methods provided by this module are not always secure.
 * It should be used for informational purposes, and not for security.
 *
 * All operations defined in this module are class methods, so that you can
 * include the Etc module into your class.
 */
void
Init_etc(void)
{
    VALUE mEtc;

    mEtc = rb_define_module("Etc");
    rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);

    rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
    rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
    rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
    rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
    rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
    rb_define_module_function(mEtc, "passwd", etc_passwd, 0);

    rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
    rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
    rb_define_module_function(mEtc, "group", etc_group, 0);
    rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
    rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
    rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
    rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
    rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);

    sPasswd =  rb_struct_define("Passwd",
				"name", "passwd", "uid", "gid",
#ifdef HAVE_ST_PW_GECOS
				"gecos",
#endif
				"dir", "shell",
#ifdef HAVE_ST_PW_CHANGE
				"change",
#endif
#ifdef HAVE_ST_PW_QUOTA
				"quota",
#endif
#ifdef HAVE_ST_PW_AGE
				"age",
#endif
#ifdef HAVE_ST_PW_CLASS
				"uclass",
#endif
#ifdef HAVE_ST_PW_COMMENT
				"comment",
#endif
#ifdef HAVE_ST_PW_EXPIRE
				"expire",
#endif
				NULL);
    /* Define-const: Passwd
     *
     * Passwd is a Struct that contains the following members:
     *
     * name::
     *	    contains the short login name of the user as a String.
     * passwd::
     *	    contains the encrypted password of the user as a String.
     *	    an 'x' is returned if shadow passwords are in use. An '*' is returned
     *      if the user cannot log in using a password.
     * uid::
     *	    contains the integer user ID (uid) of the user.
     * gid::
     *	    contains the integer group ID (gid) of the user's primary group.
     * dir::
     *	    contains the path to the home directory of the user as a String.
     * shell::
     *	    contains the path to the login shell of the user as a String.
     *
     * === The following members below are optional, and must be compiled with special flags:
     *
     * gecos::
     *     contains a longer String description of the user, such as
     *	   a full name. Some Unix systems provide structured information in the
     *     gecos field, but this is system-dependent.
     *     must be compiled with +HAVE_ST_PW_GECOS+
     * change::
     *     password change time(integer) must be compiled with +HAVE_ST_PW_CHANGE+
     * quota::
     *     quota value(integer) must be compiled with +HAVE_ST_PW_QUOTA+
     * age::
     *     password age(integer) must be compiled with +HAVE_ST_PW_AGE+
     * class::
     *     user access class(string) must be compiled with +HAVE_ST_PW_CLASS+
     * comment::
     *     comment(string) must be compiled with +HAVE_ST_PW_COMMENT+
     * expire::
     *	    account expiration time(integer) must be compiled with +HAVE_ST_PW_EXPIRE+
     */
    rb_define_const(mEtc, "Passwd", sPasswd);
    rb_extend_object(sPasswd, rb_mEnumerable);
    rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);

#ifdef HAVE_GETGRENT
    sGroup = rb_struct_define("Group", "name",
#ifdef HAVE_ST_GR_PASSWD
			      "passwd",
#endif
			      "gid", "mem", NULL);

    /* Define-const: Group
     *
     * Group is a Struct that is only available when compiled with +HAVE_GETGRENT+.
     *
     * The struct contains the following members:
     *
     * name::
     *	    contains the name of the group as a String.
     * passwd::
     *	    contains the encrypted password as a String. An 'x' is
     *	    returned if password access to the group is not available; an empty
     *	    string is returned if no password is needed to obtain membership of
     *	    the group.
     *
     *	    Must be compiled with +HAVE_ST_GR_PASSWD+.
     * gid::
     *	    contains the group's numeric ID as an integer.
     * mem::
     *	    is an Array of Strings containing the short login names of the
     *	    members of the group.
     */
    rb_define_const(mEtc, "Group", sGroup);
    rb_extend_object(sGroup, rb_mEnumerable);
    rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
#endif
}
コード例 #6
0
ファイル: talib.c プロジェクト: adawley/glowing-octo-robot
void Init_talib()
{

  /*
   * Ruby extension for technical functions library api.
   */
  rb_mTaLib = rb_define_module("TaLib");

  rb_define_const(rb_mTaLib, "TA_Input_Price", INT2FIX(TA_Input_Price));
  rb_define_const(rb_mTaLib, "TA_Input_Real", INT2FIX(TA_Input_Real));
  rb_define_const(rb_mTaLib, "TA_Input_Integer", INT2FIX(TA_Input_Integer));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPEN", INT2FIX(TA_IN_PRICE_OPEN));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_HIGH", INT2FIX(TA_IN_PRICE_HIGH));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_LOW", INT2FIX(TA_IN_PRICE_LOW));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_CLOSE", INT2FIX(TA_IN_PRICE_CLOSE));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_VOLUME", INT2FIX(TA_IN_PRICE_VOLUME));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPENINTEREST", INT2FIX(TA_IN_PRICE_OPENINTEREST));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_TIMESTAMP", INT2FIX(TA_IN_PRICE_TIMESTAMP));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealRange", INT2FIX(TA_OptInput_RealRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealList", INT2FIX(TA_OptInput_RealList));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerRange", INT2FIX(TA_OptInput_IntegerRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerList", INT2FIX(TA_OptInput_IntegerList));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_PERCENT", INT2FIX(TA_OPTIN_IS_PERCENT));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_DEGREE", INT2FIX(TA_OPTIN_IS_DEGREE));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_CURRENCY", INT2FIX(TA_OPTIN_IS_CURRENCY));
  rb_define_const(rb_mTaLib, "TA_OPTIN_ADVANCED", INT2FIX(TA_OPTIN_ADVANCED));
  rb_define_const(rb_mTaLib, "TA_Output_Real", INT2FIX(TA_Output_Real));
  rb_define_const(rb_mTaLib, "TA_Output_Integer", INT2FIX(TA_Output_Integer));
  rb_define_const(rb_mTaLib, "TA_OUT_LINE", INT2FIX(TA_OUT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT_LINE", INT2FIX(TA_OUT_DOT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DASH_LINE", INT2FIX(TA_OUT_DASH_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT", INT2FIX(TA_OUT_DOT));
  rb_define_const(rb_mTaLib, "TA_OUT_HISTO", INT2FIX(TA_OUT_HISTO));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BOOL", INT2FIX(TA_OUT_PATTERN_BOOL));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BULL_BEAR", INT2FIX(TA_OUT_PATTERN_BULL_BEAR));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_STRENGTH", INT2FIX(TA_OUT_PATTERN_STRENGTH));
  rb_define_const(rb_mTaLib, "TA_OUT_POSITIVE", INT2FIX(TA_OUT_POSITIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_NEGATIVE", INT2FIX(TA_OUT_NEGATIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_ZERO", INT2FIX(TA_OUT_ZERO));
  rb_define_const(rb_mTaLib, "TA_OUT_UPPER_LIMIT", INT2FIX(TA_OUT_UPPER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_OUT_LOWER_LIMIT", INT2FIX(TA_OUT_LOWER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_MAType_SMA", INT2FIX((int)(TA_MAType_SMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_EMA", INT2FIX((int)(TA_MAType_EMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_WMA", INT2FIX((int)(TA_MAType_WMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_DEMA", INT2FIX((int)(TA_MAType_DEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TEMA", INT2FIX((int)(TA_MAType_TEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TRIMA", INT2FIX((int)(TA_MAType_TRIMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_KAMA", INT2FIX((int)(TA_MAType_KAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_MAMA", INT2FIX((int)(TA_MAType_MAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_T3", INT2FIX((int)(TA_MAType_T3)));


  rb_define_const(rb_mTaLib, "TA_BodyLong", INT2FIX((int)(TA_BodyLong)));
  rb_define_const(rb_mTaLib, "TA_BodyVeryLong", INT2FIX((int)(TA_BodyVeryLong)));
  rb_define_const(rb_mTaLib, "TA_BodyShort",  INT2FIX((int)(TA_BodyShort)));
  rb_define_const(rb_mTaLib, "TA_BodyDoji",  INT2FIX((int)(TA_BodyDoji)));
  rb_define_const(rb_mTaLib, "TA_ShadowLong",  INT2FIX((int)(TA_ShadowLong)));
  rb_define_const(rb_mTaLib, "TA_ShadowVeryLong",  INT2FIX((int)(TA_ShadowVeryLong)));
  rb_define_const(rb_mTaLib, "TA_ShadowShort",  INT2FIX((int)(TA_ShadowShort)));
  rb_define_const(rb_mTaLib, "TA_ShadowVeryShort",  INT2FIX((int)(TA_ShadowVeryShort)));
  rb_define_const(rb_mTaLib, "TA_Near",  INT2FIX((int)(TA_Near)));
  rb_define_const(rb_mTaLib, "TA_Far",  INT2FIX((int)(TA_Far)));
  rb_define_const(rb_mTaLib, "TA_Equal",  INT2FIX((int)(TA_Equal)));
  rb_define_const(rb_mTaLib, "TA_AllCandleSettings",  INT2FIX((int)(TA_AllCandleSettings)));

  rb_define_const(rb_mTaLib, "TA_RangeType_RealBody",  INT2FIX((int)(TA_RangeType_RealBody)));
  rb_define_const(rb_mTaLib, "TA_RangeType_HighLow",  INT2FIX((int)(TA_RangeType_HighLow)));
  rb_define_const(rb_mTaLib, "TA_RangeType_Shadows",  INT2FIX((int)(TA_RangeType_Shadows)));

  rb_define_module_function( rb_mTaLib, "set_candle_settings", ta_set_candle_settings, 4);
  rb_define_module_function( rb_mTaLib, "restore_candle_default_settings", ta_restore_candle_default_settings, 1);

  rb_struct_define("TA_RealRange", "min", "max", "precision", NULL);
  rb_struct_define("TA_IntegerRange", "min", "max", NULL );
  rb_struct_define("TA_RealDataPair", "value", "string", NULL );
  rb_struct_define("TA_IntegerDataPair", "value", "string", NULL );
  rb_struct_define("TA_RealList", "data", "nb_element", NULL );
  rb_struct_define("TA_IntegerList", "data", "nb_element", NULL );

  rb_sInParamInfo = rb_struct_define("TA_InputParameterInfo", "type", "param_name", "flags", NULL );
  rb_sOptInParamInfo = rb_struct_define("TA_OptionalInputParameterInfo", "type", "param_name", "flags", "display_name", "data_set", "default_value", "hint", "help_file", NULL );
  rb_sOutParamInfo = rb_struct_define("TA_OutputParameterInfo", "type", "param_name", "flags", NULL );

  /*
   * Class for technical analysis function.
   */
  rb_cTAFunction = rb_define_class_under(rb_mTaLib, "Function", rb_cObject);
  rb_define_alloc_func(rb_cTAFunction, ta_func_alloc);
  rb_define_method(rb_cTAFunction, "initialize", ta_func_initialize, 1);
  rb_define_attr(rb_cTAFunction, "result", 1, 1);

  rb_define_module_function( rb_cTAFunction, "init_tables", init_tables,            0 );
  rb_define_module_function( rb_cTAFunction, "groups",      ta_func_get_groups,     0 );
  rb_define_module_function( rb_cTAFunction, "functions",   ta_func_get_functions,  0 );

  rb_define_method( rb_cTAFunction, "ins",  ta_func_get_input_count,                0 );
  rb_define_method( rb_cTAFunction, "outs", ta_func_get_output_count,               0 );
  rb_define_method( rb_cTAFunction, "opts", ta_func_get_option_input_count,         0 );
  rb_define_method( rb_cTAFunction, "hint", ta_func_get_hint,                       0 );
  rb_define_method( rb_cTAFunction, "camel_case_name", ta_func_get_camel_case_name, 0 );

  rb_define_method( rb_cTAFunction, "in",  ta_func_input_param_info,                1 );
  rb_define_method( rb_cTAFunction, "opt", ta_func_option_param_info,               1 );
  rb_define_method( rb_cTAFunction, "out", ta_func_output_param_info,               1 );

  rb_define_method( rb_cTAFunction, "in_int",   ta_func_setup_in_integer,           2 );
  rb_define_method( rb_cTAFunction, "in_real",  ta_func_setup_in_real,              2 );
  rb_define_method( rb_cTAFunction, "in_price", ta_func_setup_in_price,             7 );
  rb_define_method( rb_cTAFunction, "opt_int",  ta_func_setup_opt_in_integer,       2 );
  rb_define_method( rb_cTAFunction, "opt_real", ta_func_setup_opt_in_real,          2 );
  rb_define_method( rb_cTAFunction, "out_int",  ta_func_setup_out_integer,          2 );
  rb_define_method( rb_cTAFunction, "out_real", ta_func_setup_out_real,             2 );

  rb_define_method( rb_cTAFunction, "lookback", ta_func_lookback,                   0 );
  rb_define_method( rb_cTAFunction, "call", ta_func_call,                           2 );
}
コード例 #7
0
ファイル: host.c プロジェクト: djberg96/sys-host
/* :call-seq:
 *    Sys::Host.info
 *
 * Returns an array of HostInfo structs containing various bits of
 * information about the local machine for each entry in the hosts
 * table.
 *
 * The Struct::HostInfo struct contains 5 fields:
 *
 * * name      (String)
 * * aliases   (Array)
 * * addr_type (Integer) => Typically 2 (AF_INET) or 28 (AF_INET6)
 * * length    (Integer) => Typically 4 (IPv4) or 16 (IPv6)
 * * addr_list (Array)
 */
static VALUE host_info(VALUE klass){
  char ibuf[INET6_ADDRSTRLEN];
  struct hostent* host;
  VALUE v_hostinfo, v_aliases, v_addr;
  VALUE v_array = rb_ary_new();

  sethostent(0);

#ifdef HAVE_GETHOSTENT_R
  struct hostent temp;
  char sbuf[HOSTENT_BUF];
  int err;
#endif

#ifdef HAVE_GETHOSTENT_R
  while(!gethostent_r(&temp, sbuf, HOSTENT_BUF, &host, &err)){
#else
  while((host = gethostent())){
#endif
    char **aliases = host->h_aliases;
    char **addrs = host->h_addr_list;
    v_aliases = rb_ary_new();
    v_addr    = rb_ary_new();

    while(*aliases){
      rb_ary_push(v_aliases, rb_str_new2(*aliases));
      *aliases++;
    }

    while(*addrs){
      if(!inet_ntop(host->h_addrtype, addrs, ibuf, sizeof(ibuf)))
        rb_raise(cHostError, "inet_ntop() failed: %s", strerror(errno));

      rb_ary_push(v_addr, rb_str_new2(ibuf));
      *addrs++;
    }

    v_hostinfo = rb_struct_new(sHostInfo,
      rb_str_new2(host->h_name),
      v_aliases,
      INT2FIX(host->h_addrtype),
      INT2FIX(host->h_length),
      v_addr
    );

    OBJ_FREEZE(v_hostinfo);
    rb_ary_push(v_array, v_hostinfo);
  }

  endhostent();

  return v_array;
}

#ifdef HAVE_GETHOSTID
/*
 * Sys::Host.host_id
 *
 * Returns the host id of the current machine.
 */
static VALUE host_host_id(){
  return ULL2NUM(gethostid());
}
#endif

void Init_host()
{
   VALUE sys_mSys, cHost;

   /* The Sys module serves as a toplevel namespace, nothing more. */
   sys_mSys = rb_define_module("Sys");

   /* The Host class encapsulates information about your machine, such as
    * the host name and IP address.
    */
   cHost = rb_define_class_under(sys_mSys, "Host", rb_cObject);

   /* This error is raised if any of the Host methods fail. */
   cHostError = rb_define_class_under(cHost, "Error", rb_eStandardError);

   /* 0.6.3: The version of this library. This is a string, not a number. */
   rb_define_const(cHost, "VERSION", rb_str_new2(SYS_HOST_VERSION));
   
   /* Structs */
   sHostInfo = rb_struct_define("HostInfo", "name", "aliases", "addr_type",
      "length", "addr_list", NULL
   );

   /* Class Methods */
   rb_define_singleton_method(cHost, "hostname", host_hostname, 0);
   rb_define_singleton_method(cHost, "ip_addr", host_ip_addr, 0);
   rb_define_singleton_method(cHost, "info", host_info, 0);

#ifdef HAVE_GETHOSTID
   rb_define_singleton_method(cHost, "host_id", host_host_id, 0);
#endif
}