From e0733eae261f599d7116c7046dceacb7e0084255 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 2 Feb 2019 20:06:49 +0800 Subject: [PATCH] Added and Fixed. --- include/cpart.h | 13 ++++++++++--- src/cpart.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++- src/cproj_proj.cpp | 18 +++++++++++++++++- src/main.cpp | 1 + 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/include/cpart.h b/include/cpart.h index fb7eb4e..41d6caa 100644 --- a/include/cpart.h +++ b/include/cpart.h @@ -21,11 +21,16 @@ //计算模块入口函数类型 typedef int(*PCSFUNC)(void); +struct farg_info { + string type; + int size = 1; +}; + //计算模块类 class CPart{ public: // 参数格式信息列表 - vector fargs_in, fargs_out; + vector fargs_in, fargs_out; // 输入参数与输出参数缓冲区 vector args_in, args_out; // 计算过程入口与出口管理类 @@ -45,12 +50,14 @@ public: // 源文件名 string src_name; -// 唯一的构造函数 +// 构造函数 CPart(string src_path,string lib_path,string src_name,string name,bool ffresh = true); +// 根据数据库信息构造 + CPart(string func_name, sqlite3 *psql); // 析构函数 ~CPart(); // 设置输入输出参数格式信息列表 - void setArgsType(vector fargs_in, vector fargs_out); + void setArgsType(vector fargs_in, vector fargs_out); // 编译源文件 int BuildSo(void); // 获得动态链接库操作柄 diff --git a/src/cpart.cpp b/src/cpart.cpp index 8a7f7bd..4770bfd 100644 --- a/src/cpart.cpp +++ b/src/cpart.cpp @@ -74,6 +74,51 @@ CPart::CPart(string t_srcpath,string t_libpath,string t_srcname,string t_name,bo } +CPart::CPart(string func_name, sqlite3 *psql){ +// 获得动态链接库名 + string sql_quote = "SELECT libfiles.name FROM functions INNER JOIN libfiles ON libfiles.id = functions.libfile_id WHERE functions.name = ?1;"; + sqlite3_stmt *psqlsmt; + const char *pzTail; + sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); + sqlite3_bind_text(psqlsmt, 1, func_name.data(), -1, SQLITE_TRANSIENT); + sqlite3_step(psqlsmt); + lib_name = (char *)sqlite3_column_text(psqlsmt, 0); + sqlite3_finalize(psqlsmt); +// 获得工程信息 + sql_quote = "SELECT * FROM projfile;"; + sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); + sqlite3_step(psqlsmt); + lib_path = (char *)sqlite3_column_text(psqlsmt, 3); + name = (char *)sqlite3_column_text(psqlsmt, 0); + sqlite3_finalize(psqlsmt); +// 获得相关操作柄 + GetSoHandle(); +// 记录形式参数 + sql_quote = "SELECT * FROM fargs_"+func_name+" WHERE io = ?1;"; + sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); + sqlite3_bind_int(psqlsmt, 1, 0); + int rtn = sqlite3_step(psqlsmt); + if(rtn != SQLITE_DONE) + do{ + farg_info nfi; + nfi.type =(char *) sqlite3_column_text(psqlsmt, 1); + nfi.size =sqlite3_column_int(psqlsmt, 5); + fargs_in.push_back(nfi); + + }while (sqlite3_step(psqlsmt) != SQLITE_DONE); + sqlite3_reset(psqlsmt); + sqlite3_clear_bindings(psqlsmt); + sqlite3_bind_int(psqlsmt, 1, 1); + if(rtn != SQLITE_DONE) + do{ + farg_info nfi; + nfi.type =(char *) sqlite3_column_text(psqlsmt, 1); + nfi.size =sqlite3_column_int(psqlsmt, 5); + fargs_out.push_back(nfi); + }while (sqlite3_step(psqlsmt) != SQLITE_DONE); + sqlite3_finalize(psqlsmt); +} + /** 执行源文件编译操作,在指定位置生成动态链接库 @@ -125,7 +170,7 @@ CPart::~CPart(){ @param fargs_in 输入参数格式 @param fargs_out 输出参数格式 */ -void CPart::setArgsType(vector fargs_in, vector fargs_out){ +void CPart::setArgsType(vector fargs_in, vector fargs_out){ this->fargs_in = fargs_in; this->fargs_out = fargs_out; } diff --git a/src/cproj_proj.cpp b/src/cproj_proj.cpp index 8720447..25a9da0 100644 --- a/src/cproj_proj.cpp +++ b/src/cproj_proj.cpp @@ -1173,10 +1173,26 @@ void Proj::UpdateProcess(void){ {"content","?3"} }); for(auto lib : lib_index){ + sql_quote = "SELECT count(*) FROM libfiles WHERE name = ?1"; + sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); + sqlite3_bind_text(psqlsmt, 1, lib.second.data(), -1, SQLITE_TRANSIENT); + int rtn = sqlite3_step(psqlsmt); + if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ + int if_find = sqlite3_column_int(psqlsmt, 0); + sqlite3_finalize(psqlsmt); + if(if_find) continue; + } + else{ + const char *error = sqlite3_errmsg(psql); + int errorcode = sqlite3_extended_errcode(psql); + printf("\033[31mSQL Error: [%d]%s\n\033[0m",errorcode,error); + throw error; + } + sqlite3_bind_int(psqlsmt2, 1, ++last_id); sqlite3_bind_text(psqlsmt2, 2, lib.second.data(), -1, SQLITE_TRANSIENT); // 添加动态链接库 - int rtn = sqlite3_step(psqlsmt2); + rtn = sqlite3_step(psqlsmt2); if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ } diff --git a/src/main.cpp b/src/main.cpp index 74dcbaa..87825fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,7 @@ int update(string instruct, vector &configs, vector &lconfigs, v nproj.UpdateProcess(); } catch (const char *err_info) { printf("\033[31mError: %s\n\033[0m",err_info); + return -1; } printf("\033[32mSucceed.\n\033[0m"); return 0;