1gensio_add_default(3)      Library Functions Manual      gensio_add_default(3)
2
3
4

NAME

6       gensio_add_default,    gensio_set_default,   gensio_get_default,   gen‐
7       sio_get_defaultaddr, gensio_del_default, gensio_reset_defaults - Handle
8       default values for gensios
9

SYNOPSIS

11       #include <gensio/gensio.h>
12       struct gensio_enum_val {
13           char *name;
14           int val;
15       };
16
17       int gensio_add_default(struct gensio_os_funcs *o,
18                           const char *name,
19                           enum gensio_default_type type,
20                           const char *strval, int intval,
21                           int minval, int maxval,
22                           const struct gensio_enum_val *enums);
23
24       int gensio_set_default(struct gensio_os_funcs *o,
25                           const char *class, const char *name,
26                           const char *strval, int intval);
27
28       int gensio_get_default(struct gensio_os_funcs *o,
29                           const char *class, const char *name,
30                           bool classonly,
31                           enum gensio_default_type type,
32                           char **strval, int *intval);
33
34       int gensio_get_defaultaddr(struct gensio_os_funcs *o,
35                           const char *class, const char *name,
36                           bool classonly,
37                           int iprotocol, bool listen,
38                           bool require_port,
39                           struct addrinfo **rai);
40
41       int gensio_del_default(struct gensio_os_funcs *o,
42                           const char *class, const char *name,
43                           bool delclasses);
44
45       int gensio_reset_defaults(struct gensio_os_funcs *o);
46

DESCRIPTION

48       Defaults  provide a way to set overall or class-based defaults for gen‐
49       sio options (or you can use it yourself to create your  own  defaults).
50       The various options for gensios are described in gensio(5).
51
52       For  default  values, each class will use gensio_get_default with their
53       class (serialdev, telnet, ssl, etc.) with the name as the given  option
54       name.   If  a value has been set for its class, it will use that value.
55       If a value has been set with class set to  NULL  (a  "global"  default)
56       then  the  value  will be used from there.  Otherwise the code will use
57       it's own internal default value.
58
59       Any option provided in the gensio  string  will  override  any  default
60       value, of course.
61
62       The  classonly  parameter means to not look in the global defaults.  If
63       you use this for your own defaults, it is recommended that you use your
64       own class and set classonly to true.
65
66       Defaults  come  in  one  of  four  formats  defined by type: GENSIO_DE‐
67       FAULT_INT,   GENSIO_DEFAULT_BOOL,    GENSIO_DEFAULT_ENUM,    GENSIO_DE‐
68       FAULT_STR,  GENSIO_DEFAULT_DATA.  int and bool are pretty self-explana‐
69       tory.  Except that if you pass in a non-NULL strval when  setting  one,
70       the  code will attempt to get the value from the strval and will return
71       NULL if the value is not valid.  It will attempt  to  translate  "true"
72       and  "false"  for  bool  values.   If  the value is <minval or >maxval,
73       GE_OUTOFRANGE is returned from any set operation.
74
75       When setting a str, the value is copied, you don't  have  to  keep  the
76       copy around for yourself.
77
78       When  getting  a  string  value,  the  value  is  duplicated  with gen‐
79       sio_strdup, you should free it with o->free().
80
81       Data is like strings, except the length is passed in intval and  it  is
82       returned  the  same  way.   This  will  hold  arbitrary raw data.  Like
83       strings, when you get a data value you should free it with o->free().
84
85       If it's a enum, setting the value you will pass in a string and a table
86       of  possible  values  in  enum (terminated with a NULL name).  The code
87       will look up the string you pass in in the enums  table,  and  set  the
88       value  to  the integer value.  If the string is not in the enums table,
89       it will return GE_INVAL.  When you get the value, it  will  return  the
90       value in intval.
91
92       When  getting  the  value,  the  type must match what is set in the set
93       call.  If the name is not found, GE_NOTFOUND is returned.  If the  type
94       does  not  match,  then  GE_INVAL is returned.  Note that if you save a
95       value as an enum, you can fetch it as an int.
96
97       Setting the same default again will replace the old value.
98
99       gensio_del_default deletes the given  default.   You  can  only  delete
100       user-added  defaults, not ones created by the gensio library.  If there
101       are any class-specific default registered  against  the  default,  this
102       call  will  fail  with  GE_INUSE  unless delclasses is true, which will
103       cause all the class defaults to be deleted, too.
104
105       gensio_reset_defaults will reset all defaults to  the  value  set  when
106       gensio_add_default  was  called  to create the default, or the built-in
107       default value.
108
109       gesnio_get_defaultaddr gets an address from the given  default  string.
110       See  gensi_scan_network_port  in gensio/gensio.h for details on how the
111       string is formatted, what the parameters mean, and how  to  handle  the
112       addrinfo struct.
113

RETURN VALUES

115       Zero is returned on success, or a gensio error on failure.
116

SEE ALSO

118       gensio_err(3), gensio(5)
119
120
121
122                                  27 Feb 2019            gensio_add_default(3)
Impressum