完成获取系统激活信息dbus接口调用
This commit is contained in:
parent
50b5dcb328
commit
67d25e6214
|
@ -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架构
|
||||
|
@ -44,3 +58,6 @@ extern unsigned int kdk_cpu_get_corenums();
|
|||
extern const char* kdk_cpu_get_virt();
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -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 获取系统中所有的网卡
|
||||
|
@ -71,3 +84,6 @@ extern char** kdk_nc_get_ipv6(const char *nc);
|
|||
extern inline void kdk_nc_freeall(char **ptr);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -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,
|
||||
|
@ -71,3 +84,6 @@ extern char* kdk_package_get_version(const char *name);
|
|||
extern int kdk_package_is_installed(const char *name, const char *version);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -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 获取系统中物理内存总大小
|
||||
*
|
||||
|
@ -97,3 +110,6 @@ 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
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -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(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;
|
||||
}
|
||||
|
||||
dbus_pending_call_block(pending);
|
||||
msg = dbus_pending_call_steal_reply(pending);
|
||||
//释放status_pending
|
||||
dbus_pending_call_unref(status_pending);
|
||||
|
||||
if (NULL == msg) {
|
||||
fprintf(stderr, "Reply Null\n");
|
||||
return -1;
|
||||
}
|
||||
if (!dbus_message_iter_init(msg, &args)){
|
||||
klog_err("未收到激活状态接口返回值\n");
|
||||
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)
|
||||
{
|
||||
//获取技术服务日期
|
||||
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)
|
||||
{
|
||||
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__
|
||||
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);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
char* kdk_system_get_serialNumber()
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* @defgroup 获取系统基础信息
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -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 获取操作系统服务序列号
|
||||
|
@ -66,3 +72,7 @@ extern char* kdk_system_get_kernelVersion();
|
|||
extern char* kdk_system_get_currentUser();
|
||||
|
||||
#endif // KYSDK_SYSTEM_SYSINFO_H__
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue