1 This document describes the steps which have to be performed in order
2 to create and use an osl table. The code sniplets in this section
3 are taken from the file `osltar.c` in the source distribution.
5 The complete API reference is contained in the file `osl.h.`
7 Define an enum that assigns descriptive names to the columns
8 of your table. Example:
18 The last element is is useful because the number of columns of your
19 table must be specified later, see below.
21 Define an array of struct osl_column_description, one array member
25 struct osl_column_description tar_table_cols[] = {
27 .storage_type = OSL_MAPPED_STORAGE,
28 .storage_flags = OSL_RBTREE | OSL_UNIQUE,
30 .compare_function = string_compare,
33 .storage_type = OSL_MAPPED_STORAGE,
39 Three different storage types are available which may be selected
40 on a per-column basis: `OSL_DISK_STORAGE`, `OSL_MAPPED_STORAGE`, and
43 For columns of type `OSL_MAPPED_STORAGE` and `OSL_NO_STORAGE` an
44 optional rbtree is maintained by the osl library which allows to
45 quickly lookup rows by cell content. Whether or not an rbtree should
46 be used must be specified in the `storage_flags` field which should
47 contain the bitwise or of suitable `osl_storage_flags`.
49 If a column has an associated rbtree, i.e. if the `OSL_RBTREE` flag
50 is set in the storage flags for the column, the `compare_function`
51 field must be initialized to point to a function of type
52 `osl_compare_func`. In this example, `string_compare()` is used,
53 which is just a wrapper for `strcmp()` that interprets osl objects
54 as C-strings and calls `strcmp()` on the object data.
56 Define a struct `osl_table_description` and initialize it with
57 the number of columns of your table and the column descriptions:
60 struct osl_table_description tar_table_desc = {
62 .num_columns = NUM_OT_COLUMNS,
63 .column_descriptions = tar_table_cols,
68 Create the table by calling `osl_create_table()`:
71 ret = osl_create_table(&tar_table_desc);
74 Open the newly created table by calling `osl_open_table()`:
77 struct osl_table *table;
78 ret = osl_open_table(&tar_table_desc, &table);
81 To add a new row to the table, you must define an array of struct
82 osl_object of length `NUM_OT_COLUMNS` which holds the contents of
83 the new row. Note that an osl object is just a blob: It consists of
84 a data pointer and a size value. Once the array has been initialized,
85 pass it to `osl_add_row()` together with the table handle obtained from
89 struct osl_object objs[NUM_OT_COLUMNS];
90 /* ...init the array... */
91 ret = osl_add_row(table, objs);
94 Close the table with `osl_close_table()`.
97 osl_close_table(table, OSL_MARK_CLEAN);
100 The storage type of both columns of the table in this example is
101 `OSL_MAPPED_STORAGE`, so you can later open the table again and
102 retrieve its contents:
105 ret = osl_get_row(table, OTC_NAME, &obj, &row);
107 fprintf(stderr, "osl_get_row(%s): %s\n", name,
111 ret = osl_get_object(table, row, OTC_DATA, &obj);
114 The call to `osl_get_row()` uses the rbtree of the `OTC_NAME`
115 column to find the row whose object in the `OTC_NAME` column
116 matches the given object `obj`. If a row was found, it is
117 passed to `osl_get_object()` which returns the object of
118 the `OTC_DATA` column of this row.
120 This concludes the quick start document. Of course, libosl contains
121 many more public functions than those used above. For details on the
122 C-API, look at the file `osl.h` which contains the declarations of
123 all public functions and the complete documentation of the public
126 The "examples" subdirectory of the source distribution
127 contains the full code of the above example and another
128 small program which illustrates the use of columns of type
129 `OSL_NO_STORAGE`. Larger applications using libosl are <a
130 href="http://people.tuebingen.mpg.de/maan/paraslash/">paraslash</a>,
131 a network audio streaming system, and <a
132 href="http://people.tuebingen.mpg.de/maan/adu/">adu</a>, the advanced