From 67d25e6214541057d90e230c69f2588bc431fcf1 Mon Sep 17 00:00:00 2001 From: chenzhikai Date: Thu, 18 Nov 2021 11:45:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=8E=B7=E5=8F=96=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=BF=80=E6=B4=BB=E4=BF=A1=E6=81=AFdbus=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hardware/libkycpu.h | 19 +++- src/hardware/libkync.h | 18 ++- src/packages/libkypackages.h | 18 ++- src/proc/libkyrtinfo.h | 18 ++- src/systeminfo/libkysysinfo.c | 162 +++++++++++++++++++++------ src/systeminfo/libkysysinfo.h | 16 ++- src/systeminfo/test/kysysinfo_test.c | 6 +- 7 files changed, 216 insertions(+), 41 deletions(-) diff --git a/src/hardware/libkycpu.h b/src/hardware/libkycpu.h index fe28e58..8e0a030 100644 --- a/src/hardware/libkycpu.h +++ b/src/hardware/libkycpu.h @@ -1,5 +1,19 @@ #ifndef KDK_SYSTEM_HW_CPU_H__ #define KDK_SYSTEM_HW_CPU_H__ +/** + * @file libkycpu.h + * @author liuyunhe (liuyunhe@kylinos.cn) + * @brief CPU信息 + * @version 0.1 + * @date 2021-11-17 + * + * @copyright Copyright (c) 2021 + * @defgroup 获取硬件信息 + * @{ + * + */ + + /** * @brief 获取CPU架构 @@ -43,4 +57,7 @@ extern unsigned int kdk_cpu_get_corenums(); */ extern const char* kdk_cpu_get_virt(); -#endif \ No newline at end of file +#endif +/** + * @} + */ \ No newline at end of file diff --git a/src/hardware/libkync.h b/src/hardware/libkync.h index cbdfe90..c3bc771 100644 --- a/src/hardware/libkync.h +++ b/src/hardware/libkync.h @@ -1,5 +1,18 @@ #ifndef KDK_SYSTEM_HW_NWCARD_H__ #define KDK_SYSTEM_HW_NWCARD_H__ +/** + * @file libkync.h + * @author liuyunhe (liuyunhe@kylinos.cn) + * @brief 网卡信息 + * @version 0.1 + * @date 2021-11-17 + * + * @copyright Copyright (c) 2021 + * + * @defgroup 获取硬件信息 + * @{ + * + */ /** * @brief 获取系统中所有的网卡 @@ -70,4 +83,7 @@ extern char** kdk_nc_get_ipv6(const char *nc); */ extern inline void kdk_nc_freeall(char **ptr); -#endif \ No newline at end of file +#endif +/** + * @} + */ \ No newline at end of file diff --git a/src/packages/libkypackages.h b/src/packages/libkypackages.h index ac0c867..d685562 100644 --- a/src/packages/libkypackages.h +++ b/src/packages/libkypackages.h @@ -1,6 +1,19 @@ #ifndef KDK_SYSTEM_PACKAGES_H__ #define KDK_SYSTEM_PACKAGES_H__ +/** + * @file libkypackages.h + * @author liuyunhe (liuyunhe@kylinos.cn) + * @brief 包列表信息 + * @version 0.1 + * @date 2021-11-17 + * + * @copyright Copyright (c) 2021 + * @defgroup 获取包列表信息 + * @{ + * + * + */ // typedef enum kdk_packageStatus { // UNINIT, // INSTALLED, @@ -70,4 +83,7 @@ extern char* kdk_package_get_version(const char *name); */ extern int kdk_package_is_installed(const char *name, const char *version); -#endif \ No newline at end of file +#endif +/** + * @} + */ \ No newline at end of file diff --git a/src/proc/libkyrtinfo.h b/src/proc/libkyrtinfo.h index 5adc1ec..c7b7269 100644 --- a/src/proc/libkyrtinfo.h +++ b/src/proc/libkyrtinfo.h @@ -1,6 +1,19 @@ #ifndef KDK_SYSTEM_PROC_H__ #define KDK_SYSTEM_PROC_H__ +/** + * @file libkyrtinfo.h + * @author liuyunhe (liuyunhe@kylinos.cn) + * @brief 当前系统资源占用信息 + * @version 0.1 + * @date 2021-11-17 + * + * @copyright Copyright (c) 2021 + * @defgroup 获取系统当前资源使用信息 + * @{ + * + */ + /** * @brief 获取系统中物理内存总大小 * @@ -96,4 +109,7 @@ extern float kdk_rti_get_cpu_current_usage(); */ extern int kdk_rti_get_uptime(unsigned int *day, unsigned int *hour, unsigned int *min, unsigned int *sec); -#endif \ No newline at end of file +#endif +/** + * @} + */ \ No newline at end of file diff --git a/src/systeminfo/libkysysinfo.c b/src/systeminfo/libkysysinfo.c index 6ddfe5b..e197064 100644 --- a/src/systeminfo/libkysysinfo.c +++ b/src/systeminfo/libkysysinfo.c @@ -96,8 +96,14 @@ char* kdk_system_get_version(bool verbose) return sysversion; } -int kdk_system_get_activationStatus() +int kdk_system_get_activationStatus(int *status_error_num,int *date_error_num) { + if (NULL == status_error_num | NULL == date_error_num) + { + klog_err("激活状态接口调用失败:参数错误\n"); + return -1; + } + int res = 0; #ifdef __linux__ #ifdef _KYLIN_ACTIVATION_H_ @@ -140,75 +146,165 @@ int kdk_system_get_activationStatus() } if (NULL == conn) { - exit(1); + return -1; } - DBusMessage* msg; + DBusMessage* status_msg=NULL; + DBusMessage* status_pending_msg=NULL; + DBusMessage* date_msg=NULL; + DBusMessage* date_pending_msg=NULL; DBusMessageIter args; - DBusPendingCall* pending; + DBusPendingCall* status_pending=NULL; + DBusPendingCall* date_pending=NULL; int stat; - int err_nu; - msg = dbus_message_new_method_call("org.freedesktop.activation", // target for the method call + //获取激活状态 + status_msg = dbus_message_new_method_call("org.freedesktop.activation", // target for the method call "/org/freedesktop/activation", // object to call on "org.freedesktop.activation.interface", // interface to call on "status"); // method name - if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout - fprintf(stderr, "Out Of Memory!\n"); + if (!dbus_connection_send_with_reply (conn, status_msg, &status_pending, -1)) { // -1 is default timeout + klog_err("status_msg:dbus_connection_send_with_reply调用失败\n"); return -1; } - if (NULL == pending){ - fprintf(stderr, "Pending Call Null\n"); + if (NULL == status_pending){ + klog_err("status_pending:返回值为null\n"); return -1; } + dbus_connection_flush(conn); + dbus_message_unref(status_msg); - dbus_pending_call_block(pending); - msg = dbus_pending_call_steal_reply(pending); - - if (NULL == msg) { - fprintf(stderr, "Reply Null\n"); + //接收返回值 + dbus_pending_call_block(status_pending); + status_pending_msg = dbus_pending_call_steal_reply(status_pending); + if (NULL == status_pending_msg) { + klog_err("status_pending_msg:获取激活状态接口返回值异常\n"); return -1; } - if (!dbus_message_iter_init(msg, &args)){ - klog_err("未收到激活状态接口返回值\n"); + + //释放status_pending + dbus_pending_call_unref(status_pending); + + if (!dbus_message_iter_init(status_pending_msg, &args)){ + klog_err("status_pending_msg:dbus_message_iter_init获取激活状态接口返回值异常\n"); return -1; } else dbus_message_iter_get_basic(&args, &stat); if (!dbus_message_iter_next(&args)){ - klog_err("未收到激活状态接口返回值\n"); + klog_err("status_pending_msg:dbus_message_iter_next获取激活状态接口返回值异常\n"); return -1; } else - dbus_message_iter_get_basic(&args, &err_nu); - klog_debug("激活状态:%d,错误码:%d\n",stat,err_nu); - if (err_nu == 0) - { + dbus_message_iter_get_basic(&args, status_error_num); + klog_debug("激活状态:%d,错误码:%d\n",stat,*status_error_num); + + //释放status_pending_msg + dbus_message_unref(status_pending_msg); + + if (*status_error_num == 0) + { + char *date_stat=""; if (stat == 0) { - return 0; + //获取技术服务日期 + date_msg = dbus_message_new_method_call("org.freedesktop.activation", // target for the method call + "/org/freedesktop/activation", // object to call on + "org.freedesktop.activation.interface", // interface to call on + "date"); // method name + if (!dbus_connection_send_with_reply (conn, date_msg, &date_pending, -1)) { // -1 is default timeout + klog_err("date_msg:dbus_connection_send_with_reply 接口调用失败\n"); + return -1; + } + if (NULL == date_pending){ + klog_err("date_pending:返回值为null\n"); + return -1; + } + dbus_connection_flush(conn); + dbus_message_unref(date_msg); + //接收返回值 + dbus_pending_call_block(date_pending); + date_pending_msg = dbus_pending_call_steal_reply(date_pending); + + if (NULL == date_pending_msg) { + klog_err(stderr, "date_pending_msg:Reply Null\n"); + return -1; + } + if (!dbus_message_iter_init(date_pending_msg, &args)){ + dbus_message_unref(date_pending_msg); + klog_err("date_pending_msg:dbus_message_iter_init获取技术服务日期接口返回值异常\n"); + return -1; + } + else + dbus_message_iter_get_basic(&args, &date_stat); + if (!dbus_message_iter_next(&args)){ + dbus_message_unref(date_pending_msg); + klog_err("date_pending_msg:dbus_message_iter_next获取技术服务日期接口返回值异常\n"); + return -1; + } + else + dbus_message_iter_get_basic(&args, date_error_num); + klog_debug("技术服务日期:%s,错误码:%d\n",date_stat,*date_error_num); + if (*date_error_num == 0) + { + if (date_stat) + { + dbus_message_unref(date_pending_msg); + return 2; + } + else + { + dbus_message_unref(date_pending_msg); + return 0; + } + } } - else if(stat == 1) + else if (stat == 1) { - return 1; + return stat; } - else if (stat == 2) + else { - return 2; - } + // /usr/include/kylin-activation.h规定了错误码 + klog_err("技术服务状态:技术服务日期:%s,错误码:%d\n",date_stat,*date_error_num); + return -1; + } } else{ + // /usr/include/kylin-activation.h规定了错误码 + klog_err("激活状态:激活状态码:%d,错误码:%d\n",stat,*status_error_num); return -1; } - - - #endif // _KYLIN_ACTIVATION_H_ #endif // __linux__ - - return res; +data_free: + if (status_msg) + { + dbus_message_unref(status_msg); + } + if (status_pending_msg) + { + dbus_message_unref(status_pending_msg); + } + if (date_msg) + { + dbus_message_unref(date_msg); + } + if (date_pending_msg) + { + dbus_message_unref(date_pending_msg); + } + if (status_pending) + { + dbus_pending_call_unref(status_pending); + } + if (date_pending) + { + dbus_pending_call_unref(date_pending); + } + } char* kdk_system_get_serialNumber() diff --git a/src/systeminfo/libkysysinfo.h b/src/systeminfo/libkysysinfo.h index bd9f4eb..c765714 100644 --- a/src/systeminfo/libkysysinfo.h +++ b/src/systeminfo/libkysysinfo.h @@ -10,6 +10,9 @@ * * @copyright Copyright (c) 2021 * + * @defgroup 获取系统基础信息 + * @{ + * */ #include @@ -40,9 +43,12 @@ extern char* kdk_system_get_version(bool verbose); /** * @brief 获取操作系统激活状态 * - * @return int 2表示激活/试用期已过期;0表示未激活,处于试用期;1表示已激活;-1表示获取信息异常; + * @param status_error_num 用于接收激活状态的错误信息 + * @param date_error_num 用于接收获取技术服务状态错误信息 + * + * @return int 2表示已过期;0表示未激活,处于试用期;1表示已激活;-1表示接口内部错误; */ -extern int kdk_system_get_activationStatus(); +extern int kdk_system_get_activationStatus(int *status_error_num, int *date_error_num); /** * @brief 获取操作系统服务序列号 @@ -65,4 +71,8 @@ extern char* kdk_system_get_kernelVersion(); */ extern char* kdk_system_get_currentUser(); -#endif // KYSDK_SYSTEM_SYSINFO_H__ \ No newline at end of file +#endif // KYSDK_SYSTEM_SYSINFO_H__ + +/** + * @} + */ \ No newline at end of file diff --git a/src/systeminfo/test/kysysinfo_test.c b/src/systeminfo/test/kysysinfo_test.c index 20379d4..5291c1f 100644 --- a/src/systeminfo/test/kysysinfo_test.c +++ b/src/systeminfo/test/kysysinfo_test.c @@ -22,7 +22,11 @@ int main() res = kdk_system_get_serialNumber(); printf("序列号:%s\n", res); free(res); - int act = kdk_system_get_activationStatus(); + int p; + int d; + int act = kdk_system_get_activationStatus(&p,&d); + printf("--------------\n"); + printf("激活状态码:%d\n",act); printf("激活状态:%s\n", act == 1 ? "已激活" : act == 0 ? "未激活" : "已过期"); return 0; } \ No newline at end of file