Class Termios::Termios
In: lib/termios.rb
lib/termios.rb
termios.c
Parent: Object

Encupsalates termios parameters.

See also: termios(3)

Methods

c_cc=   c_cflag=   c_iflag=   c_ispeed=   c_lflag=   c_oflag=   c_ospeed=   cc=   cflag=   clone   dup   iflag=   inspect   inspect   ispeed=   lflag=   new   oflag=   ospeed=  

External Aliases

iflag -> c_iflag
oflag -> c_oflag
cflag -> c_cflag
lflag -> c_lflag
cc -> c_cc
ispeed -> c_ispeed
ospeed -> c_ospeed

Attributes

cc  [R]  control characters
cflag  [R]  control modes
iflag  [R]  input modes
ispeed  [R]  input baud rate
lflag  [R]  local modes
oflag  [R]  output modes
ospeed  [R]  output baud rate

Public Class methods

Returns new Termios::Termios object.

[Source]

/*
 * call-seq:
 *   Termios.new
 *
 * Returns new Termios::Termios object.
 */
static VALUE
termios_initialize(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE c_iflag, c_oflag, c_cflag, c_lflag, c_cc, c_ispeed, c_ospeed;
    VALUE cc_ary;
    int i;

    cc_ary = rb_ary_new2(NCCS);
    for (i = 0; i < NCCS; i++) {
        rb_ary_store(cc_ary, i, INT2FIX(0));
    }

    rb_ivar_set(self, id_iflag,  INT2FIX(0));
    rb_ivar_set(self, id_oflag,  INT2FIX(0));
    rb_ivar_set(self, id_cflag,  INT2FIX(0));
    rb_ivar_set(self, id_lflag,  INT2FIX(0));
    rb_ivar_set(self, id_cc,     cc_ary);
    rb_ivar_set(self, id_ispeed, INT2FIX(0));
    rb_ivar_set(self, id_ospeed, INT2FIX(0));

    rb_scan_args(argc, argv, "07", 
                 &c_iflag, &c_oflag, &c_cflag, &c_lflag, 
                 &c_cc, &c_ispeed, &c_ospeed);

    if (!NIL_P(c_iflag))
        termios_set_iflag(self, c_iflag);

    if (!NIL_P(c_oflag))
        termios_set_oflag(self, c_oflag);

    if (!NIL_P(c_cflag))
        termios_set_cflag(self, c_cflag);

    if (!NIL_P(c_lflag))
        termios_set_lflag(self, c_lflag);

    if (!NIL_P(c_cc))
        termios_set_cc(self, c_cc);

    if (!NIL_P(c_ispeed))
        termios_set_ispeed(self, c_ispeed);

    if (!NIL_P(c_ospeed))
        termios_set_ispeed(self, c_ospeed);

    return self;
}

Public Instance methods

c_cc=(p1)

Alias for cc=

c_cflag=(p1)

Alias for cflag=

c_iflag=(p1)

Alias for iflag=

c_ispeed=(p1)

Alias for ispeed=

c_lflag=(p1)

Alias for lflag=

c_oflag=(p1)

Alias for oflag=

c_ospeed=(p1)

Alias for ospeed=

Updates control characters of the object.

[Source]

/*
 * call-seq:
 *   termios.cc = value
 *
 * Updates control characters of the object.
 */
static VALUE
termios_set_cc(self, value)
    VALUE self, value;
{
    Check_Type(value, T_ARRAY);
    rb_ivar_set(self, id_cc, value);

    return value;
}

Updates control modes of the object.

[Source]

/*
 * call-seq:
 *   termios.cflag = flag
 *
 * Updates control modes of the object.
 */
static VALUE
termios_set_cflag(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_cflag, validate_ulong(value));

    return value;
}

Produces a shallow copy of the object.

[Source]

/*
 * call-seq:
 *   termios.dup
 *
 * Produces a shallow copy of the object.
 */
static VALUE
termios_dup(self)
    VALUE self;
{
    VALUE result;
    VALUE cc_ary;

    result = rb_call_super(0, 0);
    cc_ary = rb_ivar_get(self, id_cc);
    rb_ivar_set(result, id_cc, rb_ary_dup(cc_ary));

    return result;
}

Produces a shallow copy of the object.

[Source]

/*
 * call-seq:
 *   termios.dup
 *
 * Produces a shallow copy of the object.
 */
static VALUE
termios_dup(self)
    VALUE self;
{
    VALUE result;
    VALUE cc_ary;

    result = rb_call_super(0, 0);
    cc_ary = rb_ivar_get(self, id_cc);
    rb_ivar_set(result, id_cc, rb_ary_dup(cc_ary));

    return result;
}

Updates input modes of the object.

[Source]

/*
 * call-seq:
 *   termios.iflag = flag
 *
 * Updates input modes of the object.
 */
static VALUE
termios_set_iflag(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_iflag, validate_ulong(value));

    return value;
}

[Source]

    # File lib/termios.rb, line 46
46:     def inspect
47:       str = "\#<#{self.class}"
48:       if self.ispeed == self.ospeed
49:         speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
50:         str << " speed #{speed} baud;"
51:       else
52:         ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
53:         ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
54:         str << " ispeed #{ispeed} baud; ospeed #{ospeed} baud;"
55:       end
56: 
57:       CCINDEX_NAMES.each {|ccindex|
58:         next if ccindex == :VMIN || ccindex == :VTIME
59:         str << " #{ccindex.to_s[1..-1].downcase}"
60:         str << "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
61:       }
62:       str << " min=#{self.cc[VMIN]}"
63:       str << " time=#{self.cc[VTIME]}"
64: 
65:       [
66:         [:cflag,
67:          CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
68:          CFLAG_CHOICES],
69:         [:iflag, IFLAG_NAMES, nil],
70:         [:oflag, OFLAG_NAMES, OFLAG_CHOICES],
71:         [:lflag, LFLAG_NAMES, nil]
72:       ].each {|l|
73:         str << ";"
74:         flag_type, flag_names, choices = l
75:         flags = self.send(flag_type)
76:         choice_names = choices ? choices.values.flatten : []
77:         (flag_names-choice_names).each {|name|
78:           str << " "
79:           if choices and ns = choices[name]
80:             mask = ::Termios.const_get(name)
81:             ns.each {|n|
82:               if (flags & mask) == ::Termios.const_get(n)
83:                 str << n.to_s.downcase
84:                 break
85:               end
86:             }
87:           else
88:             str << "-" if (flags & ::Termios.const_get(name)) == 0
89:             str << name.to_s.downcase
90:           end
91:         }
92:       }
93: 
94:       str << ">"
95:       str
96:     end

[Source]

    # File lib/termios.rb, line 46
46:     def inspect
47:       str = "\#<#{self.class}"
48:       if self.ispeed == self.ospeed
49:         speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
50:         str << " speed #{speed} baud;"
51:       else
52:         ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
53:         ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
54:         str << " ispeed #{ispeed} baud; ospeed #{ospeed} baud;"
55:       end
56: 
57:       CCINDEX_NAMES.each {|ccindex|
58:         next if ccindex == :VMIN || ccindex == :VTIME
59:         str << " #{ccindex.to_s[1..-1].downcase}"
60:         str << "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
61:       }
62:       str << " min=#{self.cc[VMIN]}"
63:       str << " time=#{self.cc[VTIME]}"
64: 
65:       [
66:         [:cflag,
67:          CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
68:          CFLAG_CHOICES],
69:         [:iflag, IFLAG_NAMES, nil],
70:         [:oflag, OFLAG_NAMES, OFLAG_CHOICES],
71:         [:lflag, LFLAG_NAMES, nil]
72:       ].each {|l|
73:         str << ";"
74:         flag_type, flag_names, choices = l
75:         flags = self.send(flag_type)
76:         choice_names = choices ? choices.values.flatten : []
77:         (flag_names-choice_names).each {|name|
78:           str << " "
79:           if choices and ns = choices[name]
80:             mask = ::Termios.const_get(name)
81:             ns.each {|n|
82:               if (flags & mask) == ::Termios.const_get(n)
83:                 str << n.to_s.downcase
84:                 break
85:               end
86:             }
87:           else
88:             str << "-" if (flags & ::Termios.const_get(name)) == 0
89:             str << name.to_s.downcase
90:           end
91:         }
92:       }
93: 
94:       str << ">"
95:       str
96:     end

Updates input baud rate of the object.

[Source]

/*
 * call-seq:
 *   termios.ispeed = speed
 *
 * Updates input baud rate of the object.
 */
static VALUE
termios_set_ispeed(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_ispeed, validate_ulong(value));

    return value;
}

Updates local modes of the object.

[Source]

/*
 * call-seq:
 *   termios.lflag = flag
 *
 * Updates local modes of the object.
 */
static VALUE
termios_set_lflag(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_lflag, validate_ulong(value));

    return value;
}

Updates output modes of the object.

[Source]

/*
 * call-seq:
 *   termios.oflag = flag
 *
 * Updates output modes of the object.
 */
static VALUE
termios_set_oflag(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_oflag, validate_ulong(value));

    return value;
}

Updates output baud rate of the object.

[Source]

/*
 * call-seq:
 *   termios.ospeed = speed
 *
 * Updates output baud rate of the object.
 */
static VALUE
termios_set_ospeed(self, value)
    VALUE self, value;
{
    rb_ivar_set(self, id_ospeed, validate_ulong(value));

    return value;
}

[Validate]