diff --git a/.gitignore b/.gitignore
index c8c3296..6c2af04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
.libs/
config.mk
/cli/rtbuf
+/doc/
/gtk3/rtbuf-gtk3
/gtk3/rtbuf_gtk3_resources.c
/lib/*_type
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..d8da1e4
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "doxygen-awesome-css"]
+ path = doxygen-awesome-css
+ url = https://github.com/jothepro/doxygen-awesome-css.git
diff --git a/Makefile b/Makefile
index df27d29..a5600a1 100644
--- a/Makefile
+++ b/Makefile
@@ -12,10 +12,13 @@ clean:
${MAKE} -C ${PWD}/cli clean
${MAKE} -C ${PWD}/gtk3 clean
+doc:
+ doxygen doxygen.conf
+
install:
${MAKE} -C ${PWD}/librtbuf install
${MAKE} -C ${PWD}/lib install
${MAKE} -C ${PWD}/cli install
${MAKE} -C ${PWD}/gtk3 install
-.PHONY: all build clean install
+.PHONY: all build clean doc install
diff --git a/cli/rtbuf_cli.c b/cli/rtbuf_cli.c
index f56cdd1..9efbaac 100644
--- a/cli/rtbuf_cli.c
+++ b/cli/rtbuf_cli.c
@@ -72,7 +72,6 @@ int rtbuf_cli_load (int argc, const char *argv[])
printf("load failed\n");
return -1;
}
- rtbuf_lib_print(lib);
return 0;
}
@@ -123,8 +122,6 @@ int rtbuf_cli_new (int argc, const char *argv[])
sscanf(argv[2], "%hd", &x) == 1 &&
sscanf(argv[3], "%hd", &y) == 1)
g_rtbuf_position_cb(&g_rtbuf[rtb], x, y);
- rtbuf_print(rtb);
- printf("\n");
return 0;
}
@@ -146,14 +143,13 @@ int rtbuf_cli_let (int argc, const char *argv[])
if ((rtb = rtbuf_new(g_rtbuf_lib[rl].proc)) < 0)
return rtbuf_err("buffer not created");
v = rtbuf_var_rtbuf_set(argv[1], rtb);
- assert(v);
+ if (!v)
+ return rtbuf_err("rtbuf_var_rtbuf_set failed");
if (argc == 6 &&
g_rtbuf_position_cb &&
sscanf(argv[5], "%hd", &x) == 1 &&
sscanf(argv[6], "%hd", &y) == 1)
g_rtbuf_position_cb(&g_rtbuf[rtb], x, y);
- rtbuf_var_print(v);
- printf("\n");
return 0;
}
else if (strncmp("buffer", argv[3], 7) == 0) {
@@ -163,8 +159,8 @@ int rtbuf_cli_let (int argc, const char *argv[])
if ((rtb = rtbuf_find(argv[4])) < 0)
return rtbuf_err("buffer not found");
v = rtbuf_var_rtbuf_set(argv[1], rtb);
- assert(v);
- rtbuf_var_print(v);
+ if (!v)
+ return rtbuf_err("rtbuf_var_rtbuf_set failed");
return 0;
}
return rtbuf_err("unknown type for let");
@@ -179,8 +175,6 @@ int rtbuf_cli_delete (int argc, const char *argv[])
if (i < 0)
return rtbuf_err("buffer not found\n");
rtbuf_delete(&g_rtbuf[i]);
- rtbuf_print(i);
- printf("\n");
return 0;
}
@@ -201,7 +195,6 @@ int rtbuf_cli_bind (int argc, const char *argv[])
if ((in = rtbuf_in_find(&g_rtbuf[dest], argv[4])) < 0)
return rtbuf_err("input not found");
rtbuf_bind(src, out, &g_rtbuf[dest], in);
- rtbuf_print_long(dest);
return 0;
}
@@ -220,7 +213,6 @@ int rtbuf_cli_unbind (int argc, const char *argv[])
}
else
rtbuf_unbind_all(&g_rtbuf[rtb]);
- rtbuf_print_long(rtb);
return 0;
}
diff --git a/cli/rtbuf_cli_main.c b/cli/rtbuf_cli_main.c
index 6684a15..4b52d71 100644
--- a/cli/rtbuf_cli_main.c
+++ b/cli/rtbuf_cli_main.c
@@ -20,10 +20,13 @@
int main (int argc, char *argv[])
{
+ int res = 0;
symbols_init();
librtbuf_init();
assert(g_rtbuf);
repl_init();
rtbuf_cli_args(argc, argv);
- return repl();
+ res = repl();
+ librtbuf_shutdown();
+ return res;
}
diff --git a/doxygen-awesome-css b/doxygen-awesome-css
new file mode 160000
index 0000000..4cd6230
--- /dev/null
+++ b/doxygen-awesome-css
@@ -0,0 +1 @@
+Subproject commit 4cd62308d825fe0396d2f66ffbab45d0e247724c
diff --git a/doxygen.conf b/doxygen.conf
index fb8ad2c..ddc0d22 100644
--- a/doxygen.conf
+++ b/doxygen.conf
@@ -38,7 +38,7 @@ PROJECT_NAME = "rtbuf"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER =
+PROJECT_NUMBER = 0.3
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
@@ -187,7 +187,7 @@ SHORT_NAMES = NO
# description.)
# The default value is: NO.
-JAVADOC_AUTOBRIEF = NO
+JAVADOC_AUTOBRIEF = YES
# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line
# such as
@@ -477,7 +477,7 @@ NUM_PROC_THREADS = 1
# normally produced when WARNINGS is set to YES.
# The default value is: NO.
-EXTRACT_ALL = NO
+EXTRACT_ALL = YES
# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
@@ -526,7 +526,7 @@ EXTRACT_LOCAL_METHODS = NO
# are hidden.
# The default value is: NO.
-EXTRACT_ANON_NSPACES = NO
+EXTRACT_ANON_NSPACES = YES
# If this flag is set to YES, the name of an unnamed parameter in a declaration
# will be determined by the corresponding definition. By default unnamed
@@ -1072,7 +1072,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.
-USE_MDFILE_AS_MAINPAGE =
+USE_MDFILE_AS_MAINPAGE = README.md
#---------------------------------------------------------------------------
# Configuration options related to source browsing
@@ -1256,7 +1256,8 @@ HTML_STYLESHEET =
# list). For an example see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_STYLESHEET = doxygen-awesome-css/doxygen-awesome.css \
+ doxygen-awesome-css/doxygen-awesome-sidebar-only.css
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note
@@ -1566,7 +1567,7 @@ DISABLE_INDEX = NO
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
-GENERATE_TREEVIEW = NO
+GENERATE_TREEVIEW = YES
# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the
# FULL_SIDEBAR option determines if the side bar is limited to only the treeview
diff --git a/lib/glfw3/keyboard.c b/lib/glfw3/keyboard.c
index 324b4a5..b33bcc6 100644
--- a/lib/glfw3/keyboard.c
+++ b/lib/glfw3/keyboard.c
@@ -240,10 +240,12 @@ void rtbuf_glfw3_keyboard_close (GLFWwindow *window)
GLFWwindow * rtbuf_glfw3_keyboard_window (s_rtbuf *rtb)
{
GLFWwindow *window;
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+ /*
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+ */
window = glfwCreateWindow(RTBUF_GLFW3_KEYBOARD_WIDTH,
RTBUF_GLFW3_KEYBOARD_HEIGHT,
"rtbuf_glfw3_keyboard",
diff --git a/lib/music.h b/lib/music.h
index 82c6b7e..7def717 100644
--- a/lib/music.h
+++ b/lib/music.h
@@ -23,7 +23,7 @@
#define RTBUF_MUSIC_RELEASE_MAX 1.0
-#define RTBUF_MUSIC_NOTE_SIZE RTBUF_SIGNAL_SAMPLE_SIZE
+#define RTBUF_MUSIC_NOTE_SIZE (RTBUF_SIGNAL_SAMPLE_SIZE * 4)
#define RTBUF_MUSIC_NOTE_TYPE "music_note"
typedef struct rtbuf_music_note {
diff --git a/librtbuf/README.dox b/librtbuf/README.dox
new file mode 100644
index 0000000..797b439
--- /dev/null
+++ b/librtbuf/README.dox
@@ -0,0 +1,5 @@
+/**
+
+Hello, world !
+
+*/
diff --git a/librtbuf/data.c b/librtbuf/data.c
index 54d0ba2..76656c3 100644
--- a/librtbuf/data.c
+++ b/librtbuf/data.c
@@ -23,21 +23,38 @@ s_data_type g_data_alloc_type = {
sizeof(s_data_alloc) * 8,
DATA_TYPE_BITS
};
-s_data_alloc g_data_alloc;
+s_data_alloc g_data_alloc_alloc;
+s_data_alloc *g_data_alloc = NULL;
s_data_type g_data_type_type = {
sizeof(u_data_type) * 8,
DATA_TYPE_BITS
};
-s_data_alloc *g_data_type_alloc = 0;
+s_data_alloc *g_data_type_alloc = NULL;
+u_data_type *g_data_type = NULL;
int libdata_init ()
{
- data_alloc_init(&g_data_alloc, &g_data_alloc_type,
+ data_alloc_init(&g_data_alloc_alloc, &g_data_alloc_type,
DATA_ALLOC_MAX, 0, (f_data_clean*) data_alloc_clean);
+ assert(g_data_alloc_alloc);
+ g_data_alloc = g_data_alloc_alloc.mem;
+ g_data_type_alloc = data_alloc_new(&g_data_type_type, DATA_TYPE_MAX,
+ 0, 0);
+ assert(g_data_type_alloc);
+ g_data_type = g_data_type_alloc->mem;
return 0;
}
+void libdata_shutdown ()
+{
+ if (g_data_alloc) {
+ data_alloc_delete_all();
+ g_data_alloc = 0;
+ data_alloc_clean(&g_data_alloc_alloc);
+ }
+}
+
void data_alloc_init (s_data_alloc *da, s_data_type *t,
unsigned int max, f_data_init *init,
f_data_clean *clean)
@@ -125,7 +142,7 @@ void data_delete (s_data_alloc *da, void *data)
s_data_alloc * data_alloc_new (s_data_type *t, unsigned int max,
f_data_init *init, f_data_clean *clean)
{
- s_data_alloc *da = data_new(&g_data_alloc);
+ s_data_alloc *da = data_new(&g_data_alloc_alloc);
assert(da);
data_alloc_init(da, t, max, init, clean);
return da;
@@ -134,15 +151,25 @@ s_data_alloc * data_alloc_new (s_data_type *t, unsigned int max,
void data_alloc_delete (s_data_alloc *da)
{
assert(da);
- data_delete(&g_data_alloc, da);
+ data_delete(&g_data_alloc_alloc, da);
+}
+
+void data_alloc_delete_all ()
+{
+ unsigned i = 0;
+ int n = g_data_alloc_alloc.n;
+ while (i < g_data_alloc_alloc.max && n > 0) {
+ if (g_data_alloc[i].t) {
+ data_alloc_delete(g_data_alloc + i);
+ n--;
+ }
+ i++;
+ }
}
u_data_type * data_type_new (unsigned int bits, unsigned int type)
{
u_data_type *t;
- if (!g_data_type_alloc)
- g_data_type_alloc = data_alloc_new(&g_data_type_type, DATA_TYPE_MAX,
- 0, 0);
assert(g_data_type_alloc);
t = data_new(g_data_type_alloc);
assert(t);
diff --git a/librtbuf/data.h b/librtbuf/data.h
index e756285..a59b6b5 100644
--- a/librtbuf/data.h
+++ b/librtbuf/data.h
@@ -94,7 +94,9 @@ s_data_alloc * data_alloc_new (s_data_type *t,
unsigned int max, f_data_init *init,
f_data_clean *clean);
void data_alloc_delete (s_data_alloc *da);
+void data_alloc_delete_all ();
int libdata_init ();
+void libdata_shutdown ();
#endif
diff --git a/librtbuf/lib.h b/librtbuf/lib.h
index 2d32ea8..b5bc91c 100644
--- a/librtbuf/lib.h
+++ b/librtbuf/lib.h
@@ -13,35 +13,67 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/**
+ * @file
+ * @brief Rtbuf library header.
+ *
+ * Include <rtbuf/lib.h> to manage rtbuf libraries.
+ *
+ * Use rtbuf_lib_load to load a library, and rtbuf_lib_delete to
+ * free it.
+ *
+ * @see rtbuf_lib_load
+ * @see rtbuf_lib_delete
+ */
#ifndef RTBUF_LIB_H
#define RTBUF_LIB_H
#include "defs.h"
+/**
+ * @brief Maximum number of loaded libraries.
+ */
#define RTBUF_LIB_MAX 1000
+
+/**
+ * @brief Version for library compatibility.
+ */
#define RTBUF_LIB_VER 0x00020001
+/**
+ * @brief Description of a library's proc input.
+ */
struct rtbuf_lib_proc_in {
- const char *name;
- const char *type;
- double def;
- double min;
- double max;
- double log_base;
+ const char *name; /**< Name of the input. */
+ const char *type; /**< Type of the input (as a string). */
+ double def; /**< Default value for the input. */
+ double min; /**< Minimum value for the input. */
+ double max; /**< Maximum value for the input. */
+ double log_base; /**< Base for ogarithmic scale or 0 for linear. */
};
+/**
+ * @brief Description of a library's proc output.
+ */
struct rtbuf_lib_proc_out {
const char *name;
const char *type;
};
+/**
+ * @brief Description of a library's proc.
+ *
+ * A proc is like a class for real time buffers. It has a name, a
+ * description for the buffers inputs and outputs, and pointers to
+ * functions for the buffer's start, run, and stop events.
+ */
struct rtbuf_lib_proc {
- const char *name;
- f_rtbuf_proc *f;
- f_rtbuf_proc *start;
- f_rtbuf_proc *stop;
- s_rtbuf_lib_proc_in *in; /* inputs, end with NULL */
- s_rtbuf_lib_proc_out *out; /* outputs, end with NULL */
+ const char *name; /**< Name of the proc. E.g. "sinus" */
+ f_rtbuf_proc *f; /**< The real time buffer's run function. */
+ f_rtbuf_proc *start; /**< The real time buffer's start function. */
+ f_rtbuf_proc *stop; /**< The real time buffer's stop function. */
+ s_rtbuf_lib_proc_in *in; /**< Description for the buffer's inputs. Must end with NULL. */
+ s_rtbuf_lib_proc_out *out; /**< Description for the buffer's outputs. Must end with NULL. */
};
struct rtbuf_lib {
@@ -57,17 +89,19 @@ extern s_data_alloc g_rtbuf_lib_alloc;
extern s_rtbuf_lib *g_rtbuf_lib;
void rtbuf_lib_delete (s_rtbuf_lib *rl);
+void rtbuf_lib_delete_all ();
int rtbuf_lib_find (const char *str);
void rtbuf_lib_init_ ();
+void rtbuf_lib_shutdown ();
s_rtbuf_lib * rtbuf_lib_load (const char *path);
s_rtbuf_lib * rtbuf_lib_new ();
void rtbuf_lib_print (const s_rtbuf_lib *lib);
void rtbuf_lib_print_long (unsigned int i);
-void rtbuf_lib_proc_var_init_proc (s_rtbuf_proc *proc,
- s_rtbuf_lib_proc_in *in);
-void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
- s_rtbuf_lib_proc_out *out);
-void rtbuf_lib_proc_init_proc (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x);
+void rtbuf_lib_proc_init_in (s_rtbuf_proc *proc,
+ s_rtbuf_lib_proc_in *in);
+void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
+ s_rtbuf_lib_proc_out *out);
+void rtbuf_lib_proc_init (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x);
#endif
diff --git a/librtbuf/proc.h b/librtbuf/proc.h
index 1650b90..21f9971 100644
--- a/librtbuf/proc.h
+++ b/librtbuf/proc.h
@@ -62,13 +62,15 @@ struct rtbuf_proc {
extern s_data_alloc g_rtbuf_proc_alloc;
extern s_rtbuf_proc *g_rtbuf_proc;
-void rtbuf_proc_init ();
-int rtbuf_proc_p (s_rtbuf_proc *proc);
-s_rtbuf_proc * rtbuf_proc_new ();
void rtbuf_proc_delete (s_rtbuf_proc *proc);
+void rtbuf_proc_delete_all ();
s_rtbuf_proc * rtbuf_proc_find (const char *x);
+void rtbuf_proc_init ();
+s_rtbuf_proc * rtbuf_proc_new ();
int rtbuf_proc_out_find (s_rtbuf_proc *proc,
const char *name);
+int rtbuf_proc_p (s_rtbuf_proc *proc);
void rtbuf_proc_print (s_rtbuf_proc *proc);
+void rtbuf_proc_shutdown ();
#endif
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index e9fb1b4..c570bb7 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -13,7 +13,10 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-
+/**
+ * @file
+ * @brief real time buffer implementation
+ */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -55,6 +58,16 @@ int librtbuf_init ()
return 0;
}
+void librtbuf_shutdown ()
+{
+ rtbuf_var_shutdown();
+ rtbuf_lib_shutdown();
+ rtbuf_proc_shutdown();
+ rtbuf_type_shutdown();
+ g_rtbuf = 0;
+ libdata_shutdown();
+}
+
int rtbuf_new (s_rtbuf_proc *rp)
{
return rtbuf_new_ptr(rp, NULL);
diff --git a/librtbuf/rtbuf.h b/librtbuf/rtbuf.h
index e7e6c66..2f2097d 100644
--- a/librtbuf/rtbuf.h
+++ b/librtbuf/rtbuf.h
@@ -13,6 +13,16 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/**
+ * @file
+ * @brief rtbuf main header.
+ *
+ * Main include file for librtbuf. Include this file in your project
+ * to use librtbuf.
+ *
+ * Use librtbuf_init to initialize librtbuf.
+ * You can then load libraries using rtbuf_lib_*
+ */
#ifndef RTBUF_H
#define RTBUF_H
@@ -26,34 +36,80 @@
#define RTBUF_NEW 0x0004
#define RTBUF_READY 0x0008
+/**
+ * @brief Binding to an rtbuf output.
+ *
+ * s_rtbuf_binding is used to bind to an arbitrary output of an
+ * arbitrary rtbuf.
+ */
struct rtbuf_binding
{
- int rtb;
- unsigned int out;
+ int rtb; /**< The source rtbuf index in g_rtbuf. */
+ unsigned int out; /**< The source rtbuf output index. */
};
+/**
+ * @brief Real-time buffer.
+ *
+ * s_rtbuf is a real-time buffer with a procedure (start, run, stop).
+ * Use rtbuf_new or rtbuf_new_ptr to allocate and initialize.
+ */
struct rtbuf
{
- void *data;
- unsigned int flags;
- s_rtbuf_proc *proc;
- unsigned int refc;
- s_rtbuf_binding in[RTBUF_PROC_IN_MAX];
- unsigned int in_n;
- void *user_ptr;
+ void *data; /**< Pointer to buffer memory. */
+ unsigned int flags; /**< Flags for buffer state. */
+ s_rtbuf_proc *proc; /**< The procedure for the buffer (start, run, stop). */
+ unsigned int refc; /**< Reference count. */
+ s_rtbuf_binding in[RTBUF_PROC_IN_MAX]; /**< Inputs are bindings to other buffers outputs. */
+ unsigned int in_n; /**< Number of inputs. */
+ void *user_ptr; /**< User pointer. */
};
+/**
+ * Maximum number of s_rtbuf allocated at the same time globally.
+ */
#define RTBUF_MAX 10000
+
+/**
+ * Maximum number of s_rtbuf allocated at the same time for each
+ * procedure.
+ */
#define RTBUF_INSTANCE_MAX 100
+/**
+ * @brief Real time allocator for g_rtbuf.
+ */
extern s_data_alloc g_rtbuf_alloc;
+
+/**
+ * @brief Global index of s_rtbuf.
+ */
extern s_rtbuf *g_rtbuf;
+
+/**
+ * @brief Run loop should exit when g_rtbuf_run is zero.
+ */
extern int g_rtbuf_run;
+/**
+ * @brief Callback function for rtbuf_new.
+ */
typedef void (*f_rtbuf_new_cb) (s_rtbuf *rtb);
+
+/**
+ * @brief Callback function for rtbuf_delete.
+ */
typedef void (*f_rtbuf_delete_cb) (s_rtbuf *rtb);
+
+/**
+ * @brief Callback function for rtbuf_bind.
+ */
typedef void (*f_rtbuf_bind_cb) (s_rtbuf *src, unsigned int out,
s_rtbuf *dest, unsigned int in);
+
+/**
+ * @brief Callback function for rtbuf_unbind.
+ */
typedef void (*f_rtbuf_unbind_cb) (s_rtbuf *src, unsigned int out,
s_rtbuf *dest, unsigned int in);
@@ -62,10 +118,39 @@ extern f_rtbuf_delete_cb g_rtbuf_delete_cb;
extern f_rtbuf_bind_cb g_rtbuf_bind_cb;
extern f_rtbuf_unbind_cb g_rtbuf_unbind_cb;
-int librtbuf_init ();
+/**
+ * Initialize librtbuf.
+ *
+ * Should be called before any other rtbuf function.
+ *
+ * @sa librtbuf_shutdown
+ */
+int librtbuf_init ();
+
+/**
+ * Shutdown librtbuf.
+ *
+ * Should be called only after any other rtbuf function, when the
+ * program shuts down.
+ *
+ * @sa librtbuf_init
+ */
+void librtbuf_shutdown ();
+
+int rtbuf_err (const char *msg);
+
+/**
+ * Create a new real time buffer.
+ *
+ * The buffer is allocated in real time and ready to be bound.
+ * This is equivalent to calling rtbuf_new_ptr with user_ptr
+ * set to NULL.
+ *
+ * @param rp The procedure for the new rtbuf.
+ * @return The index of the new rtbuf in g_rtbuf.
+ */
+int rtbuf_new (s_rtbuf_proc *rp);
-int rtbuf_err (const char *msg);
-int rtbuf_new (s_rtbuf_proc *rp);
int rtbuf_new_ptr (s_rtbuf_proc *rp, void *user_ptr);
void rtbuf_in_unbind (s_rtbuf *rtb, unsigned int in);
void rtbuf_out_unbind (s_rtbuf *rtb, unsigned int out);
diff --git a/librtbuf/rtbuf_lib.c b/librtbuf/rtbuf_lib.c
index d5392dd..8161020 100644
--- a/librtbuf/rtbuf_lib.c
+++ b/librtbuf/rtbuf_lib.c
@@ -56,6 +56,15 @@ void rtbuf_lib_init_ ()
*out = 0;
}
+void rtbuf_lib_shutdown ()
+{
+ if (g_rtbuf_lib) {
+ rtbuf_lib_delete_all();
+ g_rtbuf_lib = 0;
+ data_alloc_clean(&g_rtbuf_lib_alloc);
+ }
+}
+
int rtbuf_lib_p (s_rtbuf_lib *lib)
{
return lib->lib ? 1 : 0;
@@ -101,6 +110,19 @@ void rtbuf_lib_delete (s_rtbuf_lib *rl)
data_delete(&g_rtbuf_lib_alloc, rl);
}
+void rtbuf_lib_delete_all ()
+{
+ unsigned i = 0;
+ int n = g_rtbuf_lib_alloc.n;
+ while (i < g_rtbuf_lib_alloc.max && n > 0) {
+ if (g_rtbuf_lib[i].name) {
+ rtbuf_lib_delete(g_rtbuf_lib + i);
+ n--;
+ }
+ i++;
+ }
+}
+
int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
{
char **path = g_rtbuf_lib_path;
@@ -110,7 +132,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
lib_path = g_str_append(*path, strlen(*path));
g_str_append(name, strlen(name));
ext = g_str_append(".so", 4);
- printf("lib find in path \"%s\"\n", lib_path);
+ /*printf("lib find in path \"%s\"\n", lib_path);*/
if (access(lib_path, R_OK) == 0 &&
(lib->lib = dlopen(lib_path, RTLD_NOW))) {
lib->path = lib_path;
@@ -118,7 +140,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
}
g_str_reset(ext);
g_str_append(".so.0.0", 8);
- printf("lib find in path \"%s\"\n", lib_path);
+ /*printf("lib find in path \"%s\"\n", lib_path);*/
if (access(lib_path, R_OK) == 0 &&
(lib->lib = dlopen(lib_path, RTLD_NOW))) {
lib->path = lib_path;
@@ -126,7 +148,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
}
g_str_reset(ext);
g_str_append("-0.dll", 7);
- printf("lib find in path \"%s\"\n", lib_path);
+ /*printf("lib find in path \"%s\"\n", lib_path);*/
if (access(lib_path, R_OK) == 0 &&
(lib->lib = dlopen(lib_path, RTLD_NOW))) {
lib->path = lib_path;
@@ -175,7 +197,7 @@ s_rtbuf_lib * rtbuf_lib_load (const char *name)
proc = dlsym(lib->lib, "rtbuf_lib_proc");
lib->proc = rtbuf_proc_new();
assert(lib->proc);
- rtbuf_lib_proc_init_proc(lib->proc, proc);
+ rtbuf_lib_proc_init(lib->proc, proc);
lib->proc->lib = lib;
return lib;
}
@@ -194,8 +216,8 @@ unsigned int add_padding (unsigned int offset, unsigned int size)
return (offset + align - 1) / align * align;
}
-void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
- s_rtbuf_lib_proc_in *in)
+void rtbuf_lib_proc_init_in (s_rtbuf_proc *proc,
+ s_rtbuf_lib_proc_in *in)
{
unsigned int i = 0;
unsigned int offset = proc->out_bytes;
@@ -233,8 +255,8 @@ void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
NULL, NULL);
}
-void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
- s_rtbuf_lib_proc_out *out)
+void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
+ s_rtbuf_lib_proc_out *out)
{
unsigned int i = 0;
bzero(proc->out, sizeof(proc->out));
@@ -264,14 +286,14 @@ void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
proc->out_n = i;
}
-void rtbuf_lib_proc_init_proc (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x)
+void rtbuf_lib_proc_init (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x)
{
proc->name = symbol_intern(x->name);
proc->f = x->f;
proc->start = x->start;
proc->stop = x->stop;
- rtbuf_lib_proc_out_init_proc(proc, x->out);
- rtbuf_lib_proc_in_init_proc(proc, x->in);
+ rtbuf_lib_proc_init_out(proc, x->out);
+ rtbuf_lib_proc_init_in(proc, x->in);
}
void rtbuf_lib_print (const s_rtbuf_lib *lib)
diff --git a/librtbuf/rtbuf_proc.c b/librtbuf/rtbuf_proc.c
index eb3d8eb..bb25e8e 100644
--- a/librtbuf/rtbuf_proc.c
+++ b/librtbuf/rtbuf_proc.c
@@ -37,6 +37,15 @@ void rtbuf_proc_init ()
assert(g_rtbuf_proc);
}
+void rtbuf_proc_shutdown ()
+{
+ if (g_rtbuf_proc) {
+ rtbuf_proc_delete_all();
+ data_alloc_clean(&g_rtbuf_proc_alloc);
+ g_rtbuf_proc = 0;
+ }
+}
+
int rtbuf_proc_p (s_rtbuf_proc *proc)
{
return proc && proc->name;
@@ -54,6 +63,19 @@ void rtbuf_proc_delete (s_rtbuf_proc *proc)
data_delete(&g_rtbuf_proc_alloc, proc);
}
+void rtbuf_proc_delete_all ()
+{
+ unsigned i = 0;
+ int n = g_rtbuf_proc_alloc.n;
+ while (i < g_rtbuf_proc_alloc.max && n > 0) {
+ if (g_rtbuf_proc[i].name) {
+ rtbuf_proc_delete(g_rtbuf_proc + i);
+ n--;
+ }
+ i++;
+ }
+}
+
s_rtbuf_proc * rtbuf_proc_find (const char *x)
{
const char *sym = symbol_find(x);
diff --git a/librtbuf/rtbuf_type.c b/librtbuf/rtbuf_type.c
index e07f7e2..09b78d2 100644
--- a/librtbuf/rtbuf_type.c
+++ b/librtbuf/rtbuf_type.c
@@ -47,6 +47,15 @@ void rtbuf_type_init ()
rtbuf_type_define("double" , sizeof(double));
}
+void rtbuf_type_shutdown ()
+{
+ if (g_rtbuf_data_type) {
+ rtbuf_type_delete_all();
+ g_rtbuf_data_type = 0;
+ data_alloc_clean(&g_rtbuf_data_type_alloc);
+ }
+}
+
s_rtbuf_type * rtbuf_type_new (const char *name, unsigned int size)
{
s_rtbuf_type *rt = data_new(&g_rtbuf_data_type_alloc);
@@ -64,6 +73,19 @@ void rtbuf_type_delete (s_rtbuf_type *rt)
data_delete(&g_rtbuf_data_type_alloc, rt);
}
+void rtbuf_type_delete_all ()
+{
+ unsigned i = 0;
+ int n = g_rtbuf_data_type_alloc.n;
+ while (i < g_rtbuf_data_type_alloc.max && n > 0) {
+ if (g_rtbuf_data_type[i].name) {
+ rtbuf_type_delete(g_rtbuf_data_type + i);
+ n--;
+ }
+ i++;
+ }
+}
+
s_rtbuf_type * rtbuf_type_find (symbol name)
{
unsigned int i = 0;
diff --git a/librtbuf/rtbuf_var.c b/librtbuf/rtbuf_var.c
index 1eaeb45..a96fc6e 100644
--- a/librtbuf/rtbuf_var.c
+++ b/librtbuf/rtbuf_var.c
@@ -34,12 +34,39 @@ void rtbuf_var_init (void)
assert(g_rtbuf_var);
}
+void rtbuf_var_shutdown (void)
+{
+ if (g_rtbuf_var) {
+ rtbuf_var_delete_all();
+ g_rtbuf_var = 0;
+ data_alloc_clean(&g_rtbuf_var_alloc);
+ }
+}
+
s_rtbuf_var * rtbuf_var_new (const char *name)
{
- s_rtbuf_var *v = data_new(&g_rtbuf_var_alloc);
- if (v)
- v->name = symbol_intern(name);
- return v;
+ s_rtbuf_var *var = data_new(&g_rtbuf_var_alloc);
+ if (var)
+ var->name = symbol_intern(name);
+ return var;
+}
+
+void rtbuf_var_delete (s_rtbuf_var *var)
+{
+ data_delete(&g_rtbuf_var_alloc, var);
+}
+
+void rtbuf_var_delete_all ()
+{
+ unsigned i = 0;
+ int n = g_rtbuf_var_alloc.n;
+ while (i < g_rtbuf_var_alloc.max) {
+ if (g_rtbuf_var[i].name) {
+ rtbuf_var_delete(g_rtbuf_var + i);
+ n--;
+ }
+ i++;
+ }
}
s_rtbuf_var * rtbuf_var_find (const char *name)
diff --git a/librtbuf/type.h b/librtbuf/type.h
index 3c3713b..39a1b8d 100644
--- a/librtbuf/type.h
+++ b/librtbuf/type.h
@@ -28,9 +28,11 @@ struct rtbuf_type {
#define RTBUF_TYPE_MAX 1024
void rtbuf_type_init ();
+void rtbuf_type_shutdown ();
s_rtbuf_type * rtbuf_type_new (const char *name,
unsigned int size);
void rtbuf_type_delete (s_rtbuf_type *rt);
+void rtbuf_type_delete_all ();
s_rtbuf_type * rtbuf_type_find (symbol name);
s_rtbuf_type * rtbuf_type_define (const char *name,
unsigned int size);
diff --git a/librtbuf/var.h b/librtbuf/var.h
index 5e7ce75..54e6fd8 100644
--- a/librtbuf/var.h
+++ b/librtbuf/var.h
@@ -27,6 +27,9 @@ struct rtbuf_var {
};
void rtbuf_var_init (void);
+void rtbuf_var_shutdown (void);
+void rtbuf_var_delete (s_rtbuf_var *var);
+void rtbuf_var_delete_all ();
s_rtbuf_var * rtbuf_var_find (const char *name);
s_rtbuf_var * rtbuf_var_rtbuf_set (const char *name, unsigned i);
void rtbuf_var_print (const s_rtbuf_var *v);