Browse Source

kdb: kdb object contain faux_error_t list

Serj Kalichev 2 years ago
parent
commit
bf39b89e53
3 changed files with 33 additions and 7 deletions
  1. 21 6
      dbs/libxml2/libxml2_plugin.c
  2. 5 0
      klish/kdb.h
  3. 7 1
      klish/kscheme/kdb.c

+ 21 - 6
dbs/libxml2/libxml2_plugin.c

@@ -1,22 +1,37 @@
+#include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#include <assert.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
 #include <faux/faux.h>
 #include <faux/str.h>
+#include <faux/error.h>
 #include <klish/kxml.h>
 #include <klish/kscheme.h>
+#include <klish/kdb.h>
 
 
-kscheme_t *kxml_load_scheme(const char *xml_path, faux_error_t *error);
+uint8_t kdb_libxml2_major = KDB_MAJOR;
+uint8_t kdb_libxml2_minor = KDB_MINOR;
 
 
-bool_t kdb_libxml2_init(void)
+kscheme_t *kdb_libxml2_load_scheme(kdb_t *db)
 {
-	kscheme_t *scheme = NULL;
+	faux_ini_t *ini = NULL;
+	faux_error_t *error = NULL;
+	const char *xml_path = NULL;
 
-	scheme = kxml_load_scheme(NULL, NULL);
-scheme = scheme;
-	return BOOL_TRUE;
+	assert(db);
+	if (!db)
+		return BOOL_FALSE;
+
+	// Get configuration info from kdb object
+	ini = kdb_ini(db);
+	if (ini)
+		xml_path = faux_ini_find(ini, "XMLPath");
+	error = kdb_error(db);
+
+	return kxml_load_scheme(xml_path, error);
 }

+ 5 - 0
klish/kdb.h

@@ -9,6 +9,7 @@
 #include <stdint.h>
 
 #include <faux/ini.h>
+#include <faux/error.h>
 #include <klish/kscheme.h>
 
 // Current API version
@@ -22,14 +23,17 @@
 #define KDB_SONAME_FMT "kdb_%s.so"
 
 // db's API version symbols
+// One byte (uint8_t) for major and one byte for minor numbers
 #define KDB_MAJOR_FMT "kdb_%s_major"
 #define KDB_MINOR_FMT "kdb_%s_minor"
 
 // db's init and fini functions
+// Init and fini functions can be not defined
 #define KDB_INIT_FMT "kdb_%s_init"
 #define KDB_FINI_FMT "kdb_%s_fini"
 
 // db's load and deploy functions
+// One of these function must be non-NULL else plugin has no usefull functions
 #define KDB_LOAD_FMT "kdb_%s_load_scheme"
 #define KDB_DEPLOY_FMT "kdb_%s_deploy_scheme"
 
@@ -58,6 +62,7 @@ uint8_t kdb_minor(const kdb_t *db);
 // static bool_t kdb_set_minor(kdb_t *db, uint8_t minor);
 void *kdb_udata(const kdb_t *db);
 bool_t kdb_set_udata(kdb_t *db, void *udata);
+faux_error_t *kdb_error(const kdb_t *db);
 bool_t kdb_load_plugin(kdb_t *db);
 bool_t kdb_init(kdb_t *db);
 bool_t kdb_fini(kdb_t *db);

+ 7 - 1
klish/kscheme/kdb.c

@@ -7,6 +7,7 @@
 
 #include <faux/str.h>
 #include <faux/ini.h>
+#include <faux/error.h>
 #include <klish/khelper.h>
 #include <klish/kscheme.h>
 #include <klish/kdb.h>
@@ -24,6 +25,7 @@ struct kdb_s {
 	kdb_load_fn load_fn;
 	kdb_deploy_fn deploy_fn;
 	void *udata; // User data
+	faux_error_t *error;
 };
 
 
@@ -51,6 +53,9 @@ static KSET(db, uint8_t, minor);
 KGET(db, void *, udata);
 KSET(db, void *, udata);
 
+// faux_error_t object (list of errors)
+KGET(db, faux_error_t *, error);
+
 
 kdb_t *kdb_new(const char *name, const char *file)
 {
@@ -76,6 +81,7 @@ kdb_t *kdb_new(const char *name, const char *file)
 	db->load_fn = NULL;
 	db->deploy_fn = NULL;
 	db->udata = NULL;
+	db->error = faux_error_new();
 
 	return db;
 }
@@ -89,9 +95,9 @@ void kdb_free(kdb_t *db)
 	faux_str_free(db->name);
 	faux_str_free(db->file);
 	faux_ini_free(db->ini);
-
 	if (db->dlhan)
 		dlclose(db->dlhan);
+	faux_error_free(db->error);
 
 	faux_free(db);
 }