Welcome to little lamb

Code » limb » commit b3034ca

Add obuffers_set{extra,log,dbg}lvl()

author Olivier Brunel
2023-04-02 07:03:46 UTC
committer Olivier Brunel
2023-05-20 18:06:34 UTC
parent b986d1158a94200a82d8fe33624b14f258ea0a5c

Add obuffers_set{extra,log,dbg}lvl()

Forgot an interface to change the output level of an extra buffer.

src/doc/obuffers.h.0.md +9 -0
src/doc/obuffers.h/obuffers_addextra.3.md +5 -1
src/doc/obuffers.h/obuffers_addlog.3.md +15 -2
src/liblimb/include/limb/obuffers.h +3 -0
src/liblimb/obuffers.h/obuffers_setdbglvl.c +12 -0
src/liblimb/obuffers.h/obuffers_setextralvl.c +17 -0
src/liblimb/obuffers.h/obuffers_setloglvl.c +12 -0

diff --git a/src/doc/obuffers.h.0.md b/src/doc/obuffers.h.0.md
index 5ee45b9..8192f7f 100644
--- a/src/doc/obuffers.h.0.md
+++ b/src/doc/obuffers.h.0.md
@@ -31,6 +31,9 @@ The following functions are defined :
 : [obuffers_addextra](3)
 :: Set up a new extra output buffer.
 
+: [obuffers_setextralvl](3)
+:: Define the output level of an extra output buffer.
+
 : [obuffers_remextra](3)
 :: Remove an extra output buffer.
 
@@ -41,6 +44,12 @@ The following functions are defined :
 : [obufers_adddbg](3)
 :: Similar to [obuffers_addlog](3) but this buffer will default to *OLVL_DEBUG*
 
+: [obuffers_setloglvl](3)
+:: Define the output level of the log buffer from extra output buffers.
+
+: [obuffers_setdbglvl](3)
+:: Define the output level of the debug buffer from extra output buffers.
+
 : [obuffers_remlog](3)
 :: Remove the log buffer from extra output buffers
 
diff --git a/src/doc/obuffers.h/obuffers_addextra.3.md b/src/doc/obuffers.h/obuffers_addextra.3.md
index 9514b3b..f117c18 100644
--- a/src/doc/obuffers.h/obuffers_addextra.3.md
+++ b/src/doc/obuffers.h/obuffers_addextra.3.md
@@ -11,6 +11,7 @@ obuffers\_addextra, obuffers\_remextra - add/remove an extra output buffer
 
 ```pre hl
 int obuffers_addextra(buffer *<em>buf</em>, u8 <em>level</em>)
+int obuffers_setextralvl(buffer *<em>buf</em>, u8 <em>level</em>)
 int obuffers_remextra(buffer *<em>buf</em>)
 ```
 
@@ -21,6 +22,9 @@ the given buffer `buf` (which must be set up for writing), using `level` as the
 buffer's level -- meaning only sent messages with the same level or lower will
 be written into `buf`.
 
+The `obuffers_setextralvl`() function will set the output level of extra buffer
+set up using buffer `buf` to `level`.
+
 The `obuffers_remextra`() function will remove the extra buffer set up using the
 buffer `buf`.
 
@@ -36,7 +40,7 @@ The `obuffers_addextra`() function may fail if :
 : *ENOBUFS*
 :: All extra buffers are already set up.
 
-The `obuffers_remextra`() function may fail if :
+The `obuffers_setextralvl`() and `obuffers_remextra`() functions may fail if :
 
 : *ENOENT*
 :: No extra buffer found using the specified buffer
diff --git a/src/doc/obuffers.h/obuffers_addlog.3.md b/src/doc/obuffers.h/obuffers_addlog.3.md
index 189b472..3adddfe 100644
--- a/src/doc/obuffers.h/obuffers_addlog.3.md
+++ b/src/doc/obuffers.h/obuffers_addlog.3.md
@@ -14,6 +14,9 @@ set up/remove an extra buffer from a file descriptor
 int obuffers_addlog(int <em>fd</em>)
 int obuffers_adddbg(int <em>fd</em>)
 
+int obuffers_setloglvl(u8 <em>level</em>)
+int obuffers_setdbglvl(u8 <em>level</em>)
+
 int obuffers_remlog(void)
 int obuffers_remdbg(void)
 ```
@@ -27,6 +30,12 @@ The `obuffers_adddbg`() is similar except that the output buffer will default to
 *OLVL_DEBUG* (instead of *OLVL_NORMAL*), thusly receiving any debug messages
 sent.
 
+The `obuffers_setloglvl`() function will set the output level to `level` for
+the extra buffer previously set up using `obuffers_addlog`().
+
+The `obuffers_setlogdbg`() function will set the output level to `level` for
+the extra buffer previously set up using `obuffers_adddbg`().
+
 The `obuffers_remlog`() function will remove the extra buffer previously set up
 using `obuffers_addlog`().
 
@@ -35,8 +44,9 @@ using `obuffers_adddbg`().
 
 # RETURN VALUE
 
-The `obuffers_addlog`() and `obuffers_adddbg`() functions return 1 on success.
-Otherwise they returns 0 and sets `errno` to indicate the error.
+The `obuffers_addlog`(), `obuffers_adddbg`(), `obuffers_setloglvl`() and
+`obuffers_setdbglvl`() functions return 1 on success. Otherwise they returns 0
+and sets `errno` to indicate the error.
 
 The `obuffers_remlog`() and `obuffers_remdbg`() functions return the file
 descriptor that was used in the buffer on success. Otherwise, they return -1 and
@@ -51,5 +61,8 @@ The `obuffers_addlog`() and `obuffers_adddbg`() functions may fail if :
 
 They may also fail for any of the errors specified for [obuffers_addextra](3).
 
+The `obuffers_setloglvl`() and `obuffers_setdbglvl`() functions may fail for any
+of the errors specified for [obuffers_setextralvl](3).
+
 The `obuffers_remlog`() and `obuffers_remdbg`() functions may fail for any of
 the errors specified for [obuffers_remextra](3).
diff --git a/src/liblimb/include/limb/obuffers.h b/src/liblimb/include/limb/obuffers.h
index 8152dc8..a0d7bb6 100644
--- a/src/liblimb/include/limb/obuffers.h
+++ b/src/liblimb/include/limb/obuffers.h
@@ -7,10 +7,13 @@
 #include <limb/obuffer.h>
 
 extern int obuffers_addextra(buffer *b, u8 level);
+extern int obuffers_setextralvl(buffer *b, u8 level);
 extern int obuffers_remextra(buffer *b);
 
 extern int obuffers_addlog(int fd);
 extern int obuffers_adddbg(int fd);
+extern int obuffers_setloglvl(u8 level);
+extern int obuffers_setdbglvl(u8 level);
 extern int obuffers_remlog(void);
 extern int obuffers_remdbg(void);
 
diff --git a/src/liblimb/obuffers.h/obuffers_setdbglvl.c b/src/liblimb/obuffers.h/obuffers_setdbglvl.c
new file mode 100644
index 0000000..1d258fb
--- /dev/null
+++ b/src/liblimb/obuffers.h/obuffers_setdbglvl.c
@@ -0,0 +1,12 @@
+/* This file is part of limb                           https://lila.oss/limb
+ * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <limb/obuffers.h>
+
+extern buffer buffer_dbg_;
+
+int
+obuffers_setdbglvl(u8 level)
+{
+    return obuffers_setextralvl(&buffer_dbg_, level);
+}
diff --git a/src/liblimb/obuffers.h/obuffers_setextralvl.c b/src/liblimb/obuffers.h/obuffers_setextralvl.c
new file mode 100644
index 0000000..7419d4c
--- /dev/null
+++ b/src/liblimb/obuffers.h/obuffers_setextralvl.c
@@ -0,0 +1,17 @@
+/* This file is part of limb                           https://lila.oss/limb
+ * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <errno.h>
+#include <limb/obuffers.h>
+
+int
+obuffers_setextralvl(buffer *b, u8 level)
+{
+    int n = sizeof(obuffer_extras) / sizeof(obuffer_extras[0]);
+    for (int i = 0; i < n; ++i)
+        if (obuffer_extras[i].b == b) {
+            obuffer_extras[i].lvl = level;
+            return 1;
+        }
+    return (errno = ENOENT, 0);
+}
diff --git a/src/liblimb/obuffers.h/obuffers_setloglvl.c b/src/liblimb/obuffers.h/obuffers_setloglvl.c
new file mode 100644
index 0000000..4fc7f3f
--- /dev/null
+++ b/src/liblimb/obuffers.h/obuffers_setloglvl.c
@@ -0,0 +1,12 @@
+/* This file is part of limb                           https://lila.oss/limb
+ * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <limb/obuffers.h>
+
+extern buffer buffer_log_;
+
+int
+obuffers_setloglvl(u8 level)
+{
+    return obuffers_setextralvl(&buffer_log_, level);
+}