Merge tag 'upstream/2.0.0.0' into packaging/openkylin/yangtze
Upstream version 2.0.0.0
This commit is contained in:
commit
cd74c4481e
|
@ -1,3 +1,11 @@
|
|||
libkysdk-base (2.0.0.0-0k0.5) v101; urgency=medium
|
||||
|
||||
* BUG号 : 无
|
||||
* 需求号 : 无
|
||||
* 其他修改 :
|
||||
|
||||
-- szm-min <shaozhimin@kylinos.cn> Tue, 06 Jun 2023 15:30:08 +0800
|
||||
|
||||
libkysdk-base (1.2.0.5kylin1-ok1~0715) yangtze; urgency=medium
|
||||
|
||||
* 合并主线v1.2
|
||||
|
@ -20,4 +28,4 @@ libkysdk-base (1.1.1kylin1) yangtze; urgency=medium
|
|||
* 其他修改 :
|
||||
* publish for v1.1 update
|
||||
|
||||
-- liuyunhe <liuyunhe@kylinos.cn> Tue, 17 May 2022 16:17:53 +0800
|
||||
-- liuyunhe <liuyunhe@kylinos.cn> Tue, 17 May 2022 16:17:53 +0800
|
||||
|
|
|
@ -7,7 +7,9 @@ Build-Depends: debhelper-compat (= 12),
|
|||
cmake,
|
||||
libsystemd-dev,
|
||||
libdbus-1-dev,
|
||||
libssl-dev
|
||||
libssl-dev,
|
||||
libgtk-3-dev,
|
||||
libglib2.0-dev
|
||||
Standards-Version: 4.4.1
|
||||
Homepage: http://gitlab2.kylin.com/kysdk/kysdk-base
|
||||
|
||||
|
@ -16,25 +18,27 @@ Architecture: any
|
|||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-timer,
|
||||
libkysdk-log,
|
||||
libkysdk-config,
|
||||
libkysdk-utils,
|
||||
libkysdk-basecommon
|
||||
libkysdk-timer (= ${binary:Version}),
|
||||
libkysdk-log (= ${binary:Version}),
|
||||
libkysdk-config (= ${binary:Version}),
|
||||
libkysdk-utils (= ${binary:Version}),
|
||||
libkysdk-basecommon(= ${binary:Version}),
|
||||
libkysdk-gsetting(= ${binary:Version})
|
||||
Multi-Arch: same
|
||||
Description: 麒麟开发者套件 - 基础层套件,提供日志管理、消息通信、进程守护、线程管理、定时器、调试与埋点、配置文件、utils
|
||||
|
||||
Package: libkysdk-base-dev
|
||||
Architecture: any
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-base,
|
||||
libkysdk-timer-dev,
|
||||
libkysdk-log-dev,
|
||||
libkysdk-config-dev,
|
||||
libkysdk-utils-dev
|
||||
Multi-Arch: same
|
||||
libkysdk-base(= ${binary:Version}),
|
||||
libkysdk-timer-dev(= ${binary:Version}),
|
||||
libkysdk-log-dev(= ${binary:Version}),
|
||||
libkysdk-config-dev(= ${binary:Version}),
|
||||
libkysdk-utils-dev(= ${binary:Version}),
|
||||
libkysdk-gsetting-dev(= ${binary:Version})
|
||||
Multi-Arch: foreign
|
||||
Description: 麒麟开发者套件 - 基础层套件 - 开发库,提供日志管理、消息通信、进程守护、线程管理、定时器、调试与埋点、配置文件、utils
|
||||
|
||||
Package: libkysdk-timer
|
||||
|
@ -48,14 +52,14 @@ Multi-Arch: same
|
|||
Description: 定制器模块库
|
||||
|
||||
Package: libkysdk-timer-dev
|
||||
Architecture: any
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-utils-dev,
|
||||
libkysdk-timer,
|
||||
libkysdk-basecommon
|
||||
Multi-Arch: same
|
||||
Multi-Arch: foreign
|
||||
Description: 定时器模块 - 开发库
|
||||
|
||||
Package: libkysdk-log
|
||||
|
@ -66,7 +70,8 @@ Depends: ${shlibs:Depends},
|
|||
libkysdk-config,
|
||||
logrotate,
|
||||
libkysdk-basecommon,
|
||||
libkysdk-utils
|
||||
libkysdk-utils,
|
||||
dbus
|
||||
Multi-Arch: same
|
||||
Description: 日志库
|
||||
|
||||
|
@ -79,7 +84,7 @@ Multi-Arch: same
|
|||
Description: kysdk-base层公用数据包
|
||||
|
||||
Package: libkysdk-log-dev
|
||||
Architecture: any
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
|
@ -87,7 +92,7 @@ Depends: ${shlibs:Depends},
|
|||
libkysdk-config-dev,
|
||||
libkysdk-utils-dev,
|
||||
libsystemd-dev
|
||||
Multi-Arch: same
|
||||
Multi-Arch: foreign
|
||||
Description: 日志库 - 开发库
|
||||
|
||||
Package: libkysdk-config
|
||||
|
@ -101,13 +106,13 @@ Multi-Arch: same
|
|||
Description: 配置文件库
|
||||
|
||||
Package: libkysdk-config-dev
|
||||
Architecture: any
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-utils-dev,
|
||||
libkysdk-config
|
||||
Multi-Arch: same
|
||||
Multi-Arch: foreign
|
||||
Description: 配置文件库 - 开发库
|
||||
|
||||
Package: libkysdk-utils
|
||||
|
@ -120,11 +125,30 @@ Multi-Arch: same
|
|||
Description: 开发者utils
|
||||
|
||||
Package: libkysdk-utils-dev
|
||||
Architecture: any
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-utils
|
||||
Multi-Arch: same
|
||||
Multi-Arch: foreign
|
||||
Description: 开发者utils - 开发库
|
||||
|
||||
Package: libkysdk-gsetting
|
||||
Architecture: any
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libgtk-3-0,
|
||||
libglib2.0-0,
|
||||
libkysdk-basecommon
|
||||
Multi-Arch: same
|
||||
Description: 开发者gsetting
|
||||
|
||||
Package: libkysdk-gsetting-dev
|
||||
Architecture: all
|
||||
Section: utils
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libkysdk-gsetting
|
||||
Multi-Arch: foreign
|
||||
Description: 开发者gsetting - 开发库
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
src/gsettings/libkygsetting.h usr/include/kysdk/kysdk-base
|
||||
development-files/kysdk-gsetting.pc usr/share/pkgconfig/
|
|
@ -0,0 +1 @@
|
|||
usr/lib/kysdk/kysdk-base/libkygsetting.so*
|
|
@ -1,4 +1,4 @@
|
|||
usr/lib/kysdk/kysdk-base/libkylog.so*
|
||||
src/log/kylog-default.conf etc/kysdk/kysdk-base
|
||||
src/log/kylog-rotate-default etc/kysdk/kysdk-base
|
||||
src/log/logrotate.cron etc/kysdk/kysdk-base
|
||||
usr/lib/kysdk/kysdk-base/libkylog.so*
|
||||
src/log/logrotate.cron etc/kysdk/kysdk-base
|
|
@ -1,6 +1,6 @@
|
|||
base_version=1.2.0
|
||||
base_version=2.0.0
|
||||
|
||||
Name: libkysdk-base
|
||||
Description: kysdk base layer
|
||||
Requires: kysdk-log >= ${base_version} kysdk-config >= ${base_version} kysdk-timer >= ${base_version} kysdk-utils >= ${base_version}
|
||||
Version: 1.2.0
|
||||
Version: 2.0.0
|
|
@ -1,8 +1,8 @@
|
|||
base_version=1.2.0
|
||||
base_version=2.0.0
|
||||
|
||||
Name: libkysdk-config
|
||||
Description: kysdk base layer config component
|
||||
Requires: kysdk-utils
|
||||
Version: 1.2.0
|
||||
Version: 2.0.0
|
||||
Cflags: -I/usr/include/kysdk/kysdk-base/
|
||||
Libs: -L/usr/lib/kysdk/kysdk-base/ -lkyconf -Wl,-rpath=/usr/lib/kysdk/kysdk-base/
|
|
@ -0,0 +1,6 @@
|
|||
Name: libkysdk-gsetting
|
||||
Description: kysdk base layer gsettings component
|
||||
Requires: gtk+-3.0 glib-2.0
|
||||
Version: 2.0.0
|
||||
Libs: -L/usr/lib/kysdk/kysdk-base/ -lkygsetting -Wl,-rpath=/usr/lib/kysdk/kysdk-base/
|
||||
Cflags: -I/usr/include/kysdk/kysdk-base/
|
|
@ -1,8 +1,8 @@
|
|||
base_version=1.2.0
|
||||
base_version=2.0.0
|
||||
|
||||
Name: libkysdk-log
|
||||
Description: kysdk base layer log component
|
||||
Requires: kysdk-config kysdk-utils libsystemd
|
||||
Version: 1.2.0
|
||||
Version: 2.0.0
|
||||
Cflags: -I/usr/include/kysdk/kysdk-base/
|
||||
Libs: -L/usr/lib/kysdk/kysdk-base/ -lkylog -Wl,-rpath=/usr/lib/kysdk/kysdk-base/
|
|
@ -1,6 +1,6 @@
|
|||
Name: libkysdk-timer
|
||||
Description: kysdk base layer time component
|
||||
Requires: kysdk-utils
|
||||
Version: 1.2.0
|
||||
Version: 2.0.0
|
||||
Cflags: -I/usr/include/kysdk/kysdk-base/
|
||||
Libs: -L/usr/lib/kysdk/kysdk-base/ -lkytimer -Wl,-rpath=/usr/lib/kysdk/kysdk-base/
|
|
@ -1,5 +1,5 @@
|
|||
Name: libkysdk-utils
|
||||
Description: kysdk base layer utils component
|
||||
Version: 1.2.0
|
||||
Version: 2.0.0
|
||||
Cflags:-I/usr/include/kysdk/kysdk-base/
|
||||
Libs: -L/usr/lib/kysdk/kysdk-base/ -lkydatastruct -lkyutils -Wl,-rpath=/usr/lib/kysdk/kysdk-base/
|
|
@ -2,6 +2,7 @@ include_directories(config)
|
|||
include_directories(utils)
|
||||
include_directories(log)
|
||||
include_directories(timer)
|
||||
include_directories(gsettings)
|
||||
|
||||
# add_subdirectory(communication)
|
||||
add_subdirectory(config)
|
||||
|
@ -11,4 +12,5 @@ add_subdirectory(log)
|
|||
# add_subdirectory(thread)
|
||||
add_subdirectory(timer)
|
||||
add_subdirectory(utils)
|
||||
# add_subdirectory(diagnostics)
|
||||
# add_subdirectory(diagnostics)
|
||||
add_subdirectory(gsettings)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
aux_source_directory(. SOURCESCODE)
|
||||
add_library(kyconf SHARED ${SOURCESCODE})
|
||||
set_target_properties(kyconf PROPERTIES VERSION 1.2.0 SOVERSION 1)
|
||||
set_target_properties(kyconf PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
add_executable(kyconf-test-struct test/test_structlist.c)
|
||||
target_link_libraries(kyconf-test-struct kyconf kylog pthread)
|
||||
|
||||
|
|
|
@ -210,6 +210,7 @@ int kdk_conf_reload(int id)
|
|||
|
||||
if (S_parseFile(data, conf->confpath))
|
||||
{
|
||||
free(data);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -329,4 +330,17 @@ char** const kdk_conf_list_group(int id)
|
|||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void kdk_config_freeall(char **list)
|
||||
{
|
||||
if (! list)
|
||||
return;
|
||||
size_t index = 0;
|
||||
while (list[index])
|
||||
{
|
||||
free(list[index]);
|
||||
index ++;
|
||||
}
|
||||
free(list);
|
||||
}
|
|
@ -103,6 +103,13 @@ extern char** const kdk_conf_list_key(int id, const char* group);
|
|||
*/
|
||||
extern char** const kdk_conf_list_group(int id);
|
||||
|
||||
/**
|
||||
* @brief 用于回收字符串列表
|
||||
*
|
||||
* @param ptr 字符串列表
|
||||
*/
|
||||
extern inline void kdk_config_freeall(char **ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,7 +45,7 @@ static KconfigureDataNode* append_group(structParse *parse, const char *group)
|
|||
parse->content.groupList = newGroupList;
|
||||
}
|
||||
KconfigureDataNode *groupnode = (KconfigureDataNode *)calloc(1, sizeof(KconfigureDataNode));
|
||||
if (!group)
|
||||
if (!groupnode)
|
||||
return NULL;
|
||||
|
||||
groupnode->nodeType = KconfigureNodeGroup;
|
||||
|
@ -101,7 +101,7 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
ASSERT_NOT_NULL(cfp, -1);
|
||||
|
||||
KconfigureDataNode *cur_group_node = NULL;
|
||||
|
||||
char *tmp_buf = NULL;
|
||||
char buf[LINEMAX];
|
||||
while (feof(cfp) == 0)
|
||||
{
|
||||
|
@ -124,12 +124,13 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
// Group
|
||||
if (strstartswith(buf, "[") == 0 && strendwith(buf, "]") == 0)
|
||||
{
|
||||
|
||||
cur_group_node = append_group(parse, strndup(&buf[1], strlen(buf) - 2));
|
||||
tmp_buf = strndup(&buf[1], strlen(buf) - 2);
|
||||
cur_group_node = append_group(parse, tmp_buf);
|
||||
if (!cur_group_node)
|
||||
{
|
||||
// err output
|
||||
fclose(cfp);
|
||||
free(tmp_buf);
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
|
@ -163,12 +164,23 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
{
|
||||
// OOM
|
||||
fclose(cfp);
|
||||
free(cur_group_node);
|
||||
free(tmp_buf);
|
||||
return -1;
|
||||
}
|
||||
strcpy(defaultnode, "KDK_DefaultGroup");
|
||||
|
||||
cur_group_node = append_group(parse, defaultnode);
|
||||
groupnode = cur_group_node;
|
||||
if(!cur_group_node)
|
||||
{
|
||||
fclose(cfp);
|
||||
free(tmp_buf);
|
||||
free(defaultnode);
|
||||
return -1;
|
||||
}
|
||||
else{
|
||||
groupnode = cur_group_node;
|
||||
}
|
||||
}
|
||||
|
||||
// 多重赋值的情况
|
||||
|
@ -181,6 +193,8 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
{
|
||||
// OOM
|
||||
fclose(cfp);
|
||||
free(cur_group_node);
|
||||
free(tmp_buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -191,12 +205,23 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
// OOM
|
||||
free(keylist);
|
||||
fclose(cfp);
|
||||
free(cur_group_node);
|
||||
free(tmp_buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < multikeys; i ++)
|
||||
{
|
||||
append_key(groupnode, strdup(strskipspace(keylist[i])), strdup(i >= multivals ? "" : strskipspace(vallist[i])));
|
||||
char *strkey = strdup(strskipspace(keylist[i]));
|
||||
char *val = i >= multivals ? "" : strdup(strskipspace(vallist[i]));
|
||||
|
||||
if (strkey != NULL && val != NULL) {
|
||||
append_key(groupnode, strkey, val);
|
||||
} else {
|
||||
if (strkey != NULL) free(strkey);
|
||||
if (val != NULL) free(val);
|
||||
}
|
||||
// append_key(groupnode, strdup(strskipspace(keylist[i])), strdup(i >= multivals ? "" : strskipspace(vallist[i])));
|
||||
}
|
||||
|
||||
free(keylist);
|
||||
|
@ -204,7 +229,16 @@ static int parseFile(structParse *parse, const char *filepath)
|
|||
}
|
||||
else
|
||||
{
|
||||
append_key(groupnode, strdup(keyStr), strdup(valStr));
|
||||
char *strkey = strdup(keyStr);
|
||||
char *val = strdup(valStr);
|
||||
|
||||
if (strkey != NULL && val != NULL) {
|
||||
append_key(groupnode, strkey, val);
|
||||
} else {
|
||||
if (strkey != NULL) free(strkey);
|
||||
if (val != NULL) free(val);
|
||||
}
|
||||
// append_key(groupnode, strdup(keyStr), strdup(valStr));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
char **keylist = NULL;
|
||||
int id = kdk_conf_init("struct.conf");
|
||||
ASSERT_NOT_NULL(id, -1);
|
||||
|
||||
|
@ -15,7 +16,7 @@ int main()
|
|||
while ((tmpgroup = grouplist[index]))
|
||||
{
|
||||
printf("Group: %s\n", tmpgroup);
|
||||
char **keylist = kdk_conf_list_key(id, tmpgroup);
|
||||
keylist = kdk_conf_list_key(id, tmpgroup);
|
||||
ASSERT_NOT_NULL(keylist, -1);
|
||||
char *tmpkey;
|
||||
int k_index = 0;
|
||||
|
@ -25,11 +26,13 @@ int main()
|
|||
printf("%s = %s\n", tmpkey , tmpval);
|
||||
k_index ++;
|
||||
}
|
||||
kdk_config_freeall(keylist);
|
||||
|
||||
index ++;
|
||||
}
|
||||
|
||||
kdk_conf_destroy(id);
|
||||
kdk_config_freeall(grouplist);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
aux_source_directory(. SOURCESCODE)
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(GTK3 REQUIRED gtk+-3.0 glib-2.0)
|
||||
include_directories(${GTK3_INCLUDE_DIRS})
|
||||
|
||||
link_directories(${GTK3_LIBRARY_DIRS})
|
||||
add_definitions(${GTK3_CFLAGS_OTHER})
|
||||
|
||||
add_library(kygsetting SHARED ${SOURCESCODE})
|
||||
set_target_properties(kygsetting PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
|
||||
add_executable(test-kygsetting test/test-gsetting.c)
|
||||
target_link_libraries(kygsetting ${GTK3_LIBRARIES})
|
||||
target_link_libraries(test-kygsetting kygsetting)
|
||||
|
||||
install(TARGETS kygsetting
|
||||
DESTINATION lib/kysdk/kysdk-base)
|
||||
|
||||
install(FILES libkygsetting.h
|
||||
DESTINATION include/kysdk/kysdk-base)
|
|
@ -0,0 +1,249 @@
|
|||
#include "libkygsetting.h"
|
||||
#include <stdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gsettings.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib-object.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
gboolean schema_key_is_exist(char *schema_id, char *name)
|
||||
{
|
||||
gboolean ret;
|
||||
GSettingsSchema *schema;
|
||||
|
||||
if(schema_id == NULL || name == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
schema = g_settings_schema_source_lookup(g_settings_schema_source_get_default(),schema_id, FALSE);
|
||||
if (schema == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ret = g_settings_schema_has_key (schema, name);
|
||||
if(!ret) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
int kdk_gsettings_set(const char *schema_id, const char *key, const char *format, ...)
|
||||
{
|
||||
int ret;
|
||||
GSettings *settings;
|
||||
GVariant *value;
|
||||
va_list ap;
|
||||
if(schema_id == NULL || key == NULL || format == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
va_start(ap, format);
|
||||
|
||||
if (strstr(format, "as"))
|
||||
{
|
||||
char **variant;
|
||||
GArray *as;
|
||||
|
||||
variant = va_arg(ap, char **);
|
||||
va_end(ap);
|
||||
|
||||
as = g_array_new(TRUE, TRUE, sizeof(char **));
|
||||
int i = 0;
|
||||
for (i; variant[i]; i++)
|
||||
{
|
||||
}
|
||||
variant[i - 1] = NULL;
|
||||
for (int j = 0; variant[j]; j++)
|
||||
{
|
||||
g_array_append_val(as, variant[j]);
|
||||
}
|
||||
|
||||
ret = g_settings_set_strv(settings, key, (const char **)as->data);
|
||||
g_array_free(as, TRUE);
|
||||
}
|
||||
else if (strstr(format, "ai"))
|
||||
{
|
||||
GVariantBuilder *builder = NULL;
|
||||
GVariant *variant;
|
||||
|
||||
int *res;
|
||||
res = va_arg(ap, int *);
|
||||
size_t size = va_arg(ap, size_t);
|
||||
|
||||
variant = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, res, size, sizeof(res[0]));
|
||||
va_end(ap);
|
||||
|
||||
ret = g_settings_set_value(settings, key, variant);
|
||||
}
|
||||
else if (strstr(format, "ad"))
|
||||
{
|
||||
GVariant *variant;
|
||||
|
||||
double *res;
|
||||
res = va_arg(ap, double*);
|
||||
|
||||
int size = va_arg(ap, int);
|
||||
variant = g_variant_new_fixed_array(G_VARIANT_TYPE_DOUBLE, res, size, sizeof(res[0]));
|
||||
va_end(ap);
|
||||
|
||||
ret = g_settings_set_value(settings, key, variant);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = g_variant_new_va(format, NULL, &ap);
|
||||
va_end(ap);
|
||||
|
||||
ret = g_settings_set_value(settings, key, g_steal_pointer(&value));
|
||||
}
|
||||
|
||||
g_settings_sync();
|
||||
g_object_unref(settings);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int kdk_settings_reset(const char *schema_id, const char *key)
|
||||
{
|
||||
GSettings *settings;
|
||||
if(schema_id == NULL || key == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
g_settings_reset(settings, key);
|
||||
g_settings_sync();
|
||||
g_object_unref(settings);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int kdk_settings_set_string(const char *schema_id, const char *key, const char *value)
|
||||
{
|
||||
GSettings *settings;
|
||||
if(schema_id == NULL || key == NULL || value == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
g_settings_set_string(settings, key, value);
|
||||
g_settings_sync();
|
||||
g_object_unref(settings);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kdk_settings_set_int(const char *schema_id, const char *key, int value)
|
||||
{
|
||||
GSettings *settings;
|
||||
if(schema_id == NULL || key == NULL || value == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
g_settings_set_int(settings, key, value);
|
||||
g_settings_sync();
|
||||
g_object_unref(settings);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *kdk_gsettings_get(const char *schema_id, const char *key, const char *format, ...)
|
||||
{
|
||||
GSettings *settings;
|
||||
GVariant *value;
|
||||
va_list ap;
|
||||
|
||||
if(schema_id == NULL || key == NULL || format == NULL) {
|
||||
printf("incorrect input");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
|
||||
value = g_settings_get_value(settings, key);
|
||||
|
||||
va_start(ap, format);
|
||||
g_variant_get_va(value, format, NULL, &ap);
|
||||
va_end(ap);
|
||||
|
||||
g_variant_unref(value);
|
||||
}
|
||||
|
||||
char *kdk_settings_get_string(const char *schema_id, const char *key)
|
||||
{
|
||||
GSettings *settings;
|
||||
char *current_setting;
|
||||
if(schema_id == NULL || key == NULL) {
|
||||
printf("incorrect input");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return NULL;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
current_setting = g_settings_get_string(settings, key);
|
||||
return current_setting;
|
||||
}
|
||||
|
||||
int kdk_settings_get_int(const char *schema_id, const char *key)
|
||||
{
|
||||
GSettings *settings;
|
||||
int current_setting;
|
||||
if(schema_id == NULL || key == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
current_setting = g_settings_get_int(settings, key);
|
||||
return current_setting;
|
||||
}
|
||||
|
||||
double kdk_settings_get_double(const char *schema_id, const char *key)
|
||||
{
|
||||
GSettings *settings;
|
||||
double current_setting;
|
||||
if(schema_id == NULL || key == NULL) {
|
||||
printf("incorrect input");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!schema_key_is_exist(schema_id,key)) {
|
||||
printf("%s does not have a key named %s exist", schema_id, key);
|
||||
return 0;
|
||||
}
|
||||
settings = g_settings_new(schema_id);
|
||||
current_setting = g_settings_get_double(settings, key);
|
||||
return current_setting;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#ifndef KYSDK_BASE_GSETTINGS_H__
|
||||
#define KYSDK_BASE_GSETTINGS_H__
|
||||
|
||||
|
||||
/** @defgroup Gsettings
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file libkygseetings.h
|
||||
* @author zhouhuazhi (zhouhuazhi@kylinos.cn)
|
||||
* @brief KYSDK C语言Gsettings模块
|
||||
* @version 0.1
|
||||
* @date 2022-10-18
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @brief 设置gesettings指定key值
|
||||
*
|
||||
* @return int 成功返回1
|
||||
*/
|
||||
extern int kdk_gsettings_set(const char *schema_id, const char *key, const char *format, ...);
|
||||
|
||||
/**
|
||||
* @brief 重置gesettings指定key值
|
||||
*
|
||||
* @return int 成功返回0
|
||||
*/
|
||||
extern int kdk_settings_reset(const char *schema_id, const char *key);
|
||||
|
||||
/**
|
||||
* @brief 设置gesettings指定string类型key值
|
||||
*
|
||||
* @return int 成功返回0
|
||||
*/
|
||||
extern int kdk_settings_set_string(const char *schema_id, const char *key, const char *value);
|
||||
|
||||
/**
|
||||
* @brief 设置gesettings指定int类型key值
|
||||
*
|
||||
* @return int 成功返回0
|
||||
*/
|
||||
extern int kdk_settings_set_int(const char *schema_id, const char *key, int value);
|
||||
|
||||
/**
|
||||
* @brief 获取gesettings指定key值
|
||||
*
|
||||
* @return GVariant key的值
|
||||
*/
|
||||
void* kdk_gsettings_get(const char *schema_id, const char *key, const char *format, ...);
|
||||
|
||||
/**
|
||||
* @brief 获取gesettings指定string类型key值
|
||||
*
|
||||
* @return char* key的值
|
||||
*/
|
||||
extern char* kdk_settings_get_string(const char *schema_id, const char *key);
|
||||
|
||||
/**
|
||||
* @brief 获取gesettings指定int类型key值
|
||||
*
|
||||
* @return int key的值
|
||||
*/
|
||||
extern int kdk_settings_get_int(const char *schema_id, const char *key);
|
||||
|
||||
/**
|
||||
* @brief 获取gesettings指定double类型key值
|
||||
*
|
||||
* @return int key的值
|
||||
*/
|
||||
extern double kdk_settings_get_double(const char *schema_id, const char *key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //KYSDK_BASE_GSETTINGS_H__
|
|
@ -0,0 +1,5 @@
|
|||
all:
|
||||
gcc -g -O0 -o test-gsetting test-gsetting.c
|
||||
|
||||
clean:
|
||||
rm demo
|
|
@ -0,0 +1,39 @@
|
|||
#include "../libkygsetting.h"
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int ret = kdk_settings_reset("org.gnome.evolution-data-server.calendar", "notify-custom-snooze-minutes");
|
||||
|
||||
double a[] = {0.0,2.0};
|
||||
size_t s = 2;
|
||||
// double **s = a;
|
||||
|
||||
ret = kdk_gsettings_set("org.onboard.window", "docking-aspect-change-range", "ad", a, s); //当类型为数组时,请输入数组大小,size_t
|
||||
printf("%d\n", ret);
|
||||
ret = kdk_settings_set_string("org.gnome.evolution", "version", "3.36.1");
|
||||
ret = kdk_settings_set_int("org.ukui.audio", "output-volume", 67);
|
||||
char* res = kdk_settings_get_string("org.gnome.evolution", "version");
|
||||
printf("res = %s\n", res);
|
||||
|
||||
int key = kdk_settings_get_int("org.ukui.audio", "output-volume");
|
||||
printf("key = %d\n", key);
|
||||
bool enabled;
|
||||
GVariantIter iter;
|
||||
kdk_gsettings_get("org.ukui.control-center.notice", "blacklist", "as", &iter);
|
||||
printf("enable = %d\n", enabled);
|
||||
// printf("value = %d\n", value);
|
||||
// for (int i = 0; value[i]; i++)
|
||||
// {
|
||||
// printf("[%d]Get disk info error.\n", value[i]);
|
||||
// }
|
||||
|
||||
double dde = kdk_settings_get_double("org.ukui.SettingsDaemon.plugins.xsettings", "scaling-factor");
|
||||
printf("dde = %0.1f\n", dde);
|
||||
return 0;
|
||||
}
|
|
@ -1,12 +1,18 @@
|
|||
aux_source_directory(. SOURCESCODE)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(DBus REQUIRED
|
||||
dbus-1)
|
||||
include_directories(${DBus_INCLUDE_DIRS})
|
||||
add_library(kylog SHARED ${SOURCESCODE})
|
||||
set_target_properties(kylog PROPERTIES VERSION 1.2.0 SOVERSION 1)
|
||||
set_target_properties(kylog PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
add_executable(kylog-testlog test/test-log.c)
|
||||
add_executable(kylog-testsetdir test/test-setdir.c)
|
||||
add_executable(kylog-testpressure test/test-pressure.c)
|
||||
add_executable(kylog-testautowrap test/test-autowrap.c)
|
||||
find_library(SYSTEMD_LIB systemd)
|
||||
target_link_libraries(kylog kyconf pthread ${SYSTEMD_LIB})
|
||||
find_library(DBUS_LIB dbus-1)
|
||||
target_link_libraries(kylog kyconf pthread ${SYSTEMD_LIB} ${DBUS_LIB})
|
||||
target_link_libraries(kylog-testlog kylog)
|
||||
target_link_libraries(kylog-testsetdir kylog)
|
||||
target_link_libraries(kylog-testautowrap kylog)
|
||||
|
|
|
@ -7,11 +7,98 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "dbus/dbus.h"
|
||||
|
||||
KLogger* logger;
|
||||
const char* stringLevel[8] = {"EMERG", "ALERT", "CRIT", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
|
||||
const char* stringLType[LTENUMMAX] = {"user." , "local3." , "syslog."};
|
||||
|
||||
static int _call_method(const char *path)
|
||||
{
|
||||
DBusError err;
|
||||
DBusConnection *conn;
|
||||
int ret;
|
||||
// initialise the errors
|
||||
dbus_error_init(&err);
|
||||
|
||||
// connect to the bus
|
||||
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
|
||||
if (dbus_error_is_set(&err))
|
||||
{
|
||||
// fprintf(stderr, "Connection Error (%s)\n", err.message);
|
||||
dbus_error_free(&err);
|
||||
return -1;
|
||||
}
|
||||
if (NULL == conn)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DBusMessage *msg;
|
||||
DBusMessageIter args;
|
||||
DBusPendingCall *pending;
|
||||
int result = 0;
|
||||
|
||||
msg = dbus_message_new_method_call("com.kysdk.base", // target for the method call
|
||||
"/com/kysdk/base/logrotate", // object to call on
|
||||
"com.kysdk.base.logrotate", // interface to call on
|
||||
"setConfig"); // method name
|
||||
if (NULL == msg)
|
||||
{
|
||||
// fprintf(stderr, "Message Null\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// append arguments
|
||||
dbus_message_iter_init_append(msg, &args);
|
||||
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &path))
|
||||
{
|
||||
// fprintf(stderr, "Out Of Memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// send message and get a handle for a reply
|
||||
if (!dbus_connection_send_with_reply(conn, msg, &pending, -1))
|
||||
{ // -1 is default timeout
|
||||
// fprintf(stderr, "Out Of Memory!\n");
|
||||
return -1;
|
||||
}
|
||||
if (NULL == pending)
|
||||
{
|
||||
// fprintf(stderr, "Pending Call Null\n");
|
||||
return -1;
|
||||
}
|
||||
dbus_connection_flush(conn);
|
||||
|
||||
// free message
|
||||
dbus_message_unref(msg);
|
||||
|
||||
// block until we recieve a reply
|
||||
dbus_pending_call_block(pending);
|
||||
// get the reply message
|
||||
msg = dbus_pending_call_steal_reply(pending);
|
||||
if (NULL == msg)
|
||||
{
|
||||
// fprintf(stderr, "Reply Null\n");
|
||||
return -1;
|
||||
}
|
||||
// free the pending message handle
|
||||
dbus_pending_call_unref(pending);
|
||||
// read the parameters
|
||||
if (!dbus_message_iter_init(msg, &args))
|
||||
{
|
||||
// fprintf(stderr, "Message has no arguments!\n");
|
||||
return -1;
|
||||
}
|
||||
else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args))
|
||||
{
|
||||
// fprintf(stderr, "Argument is not boolean!\n");
|
||||
return -1;
|
||||
}
|
||||
dbus_message_iter_get_basic(&args, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int _dir_exist(const char *dpath)
|
||||
{
|
||||
struct stat st;
|
||||
|
@ -29,7 +116,9 @@ static int _create_dir(const char *dpath)
|
|||
if (!command)
|
||||
return -1;
|
||||
sprintf(command, "mkdir -p %s", dpath);
|
||||
return system(command);
|
||||
int ret = system(command);
|
||||
free(command);
|
||||
return ret;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
|
@ -224,6 +313,9 @@ int initKLogger(int cid)
|
|||
printf("无法打开日志文件%s:%s\n" , logPath, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (-1 == _call_method(logPath))
|
||||
;
|
||||
// printf("Create %s Rotate Config Failed", logPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -237,6 +329,9 @@ int initKLogger(int cid)
|
|||
return errno;
|
||||
}
|
||||
printf("日志记录文件:%s\n" , logPath);
|
||||
if (-1 == _call_method(logPath))
|
||||
;
|
||||
// printf("Create %s Rotate Config Failed", logPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
aux_source_directory(. SOURCESCODE)
|
||||
add_library(kytimer SHARED ${SOURCESCODE})
|
||||
set_target_properties(kytimer PROPERTIES VERSION 1.2.0 SOVERSION 1)
|
||||
set_target_properties(kytimer PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
add_executable(test-kytimer test/test-kytimer.c)
|
||||
target_link_libraries(kytimer pthread)
|
||||
target_link_libraries(test-kytimer kytimer)
|
||||
|
|
|
@ -164,7 +164,7 @@ static void* timerCoreThread(void* data)
|
|||
read_fds = epoll_wait(epollfd , activeEvs , KTIMER_MAXTIMERFD , -1);
|
||||
if (read_fds < 0)
|
||||
{
|
||||
printf("epoll wait error , %s\n" , strerror(errno));
|
||||
//printf("epoll wait error , %s\n" , strerror(errno));
|
||||
continue;
|
||||
}
|
||||
for (int i = 0 ; i < read_fds ; i ++)
|
||||
|
|
|
@ -31,14 +31,14 @@ int main()
|
|||
|
||||
//测试1 -- 基本功能
|
||||
size_t fdpoll[10] = {0};
|
||||
for (int i = 1 ; i <= 10 ; i ++)
|
||||
{
|
||||
char* data = (char*)malloc(10);
|
||||
assert(data);
|
||||
sprintf(data , "%d号" , i);
|
||||
fdpoll[i - 1] = kdk_timer_start(i * 1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, (void*)data , 1);
|
||||
assert(fdpoll[i - 1]);
|
||||
}
|
||||
// for (int i = 1 ; i <= 10 ; i ++)
|
||||
// {
|
||||
// char* data = (char*)malloc(10);
|
||||
// assert(data);
|
||||
// sprintf(data , "%d号" , i);
|
||||
// fdpoll[i - 1] = kdk_timer_start(i * 1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, (void*)data , 1);
|
||||
// assert(fdpoll[i - 1]);
|
||||
// }
|
||||
kdk_timer_start(10000 , (time_handler)stop , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, (void*)fdpoll , 0);
|
||||
sleep(11);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
aux_source_directory(. SOURCESCODE)
|
||||
add_library(kyutils SHARED ${SOURCESCODE})
|
||||
set_target_properties(kyutils PROPERTIES VERSION 1.2.0 SOVERSION 1)
|
||||
set_target_properties(kyutils PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
include_directories(.)
|
||||
install(TARGETS kyutils
|
||||
DESTINATION lib/kysdk/kysdk-base)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
aux_source_directory(linklist/skip_linklist SOURCESCODESTRUCT)
|
||||
add_library(kydatastruct SHARED ${SOURCESCODESTRUCT})
|
||||
set_target_properties(kydatastruct PROPERTIES VERSION 1.2.0 SOVERSION 1)
|
||||
set_target_properties(kydatastruct PROPERTIES VERSION 2.0.0 SOVERSION 1)
|
||||
add_subdirectory(linklist)
|
||||
|
||||
include_directories(linklist)
|
||||
|
|
|
@ -59,11 +59,19 @@ static int do_scale_by_power (uintmax_t *x, int base, int power)
|
|||
static int get_exp2(uint64_t n, KDKVolumeBaseType base)
|
||||
{
|
||||
int shft;
|
||||
int num;
|
||||
|
||||
if((base == KDK_KILO) || (base == KDK_MEGA) ||
|
||||
(base == KDK_GIGA) || (base == KDK_TERA)||
|
||||
(base == KDK_PETA) || (base == KDK_EXA)){
|
||||
base -= 6;
|
||||
}
|
||||
|
||||
for (shft = 10; shft <= base * 10; shft += 10) {
|
||||
if (n < (1ULL << shft))
|
||||
break;
|
||||
}
|
||||
|
||||
return shft - 10;
|
||||
}
|
||||
|
||||
|
@ -226,13 +234,18 @@ char *size_to_human_string(int options, uint64_t bytes, int base)
|
|||
c = *(letters + (exp ? exp / 10 : 0));
|
||||
dec = exp ? bytes / (1ULL << exp) : bytes;
|
||||
frac = exp ? bytes % (1ULL << exp) : 0;
|
||||
|
||||
*psuf++ = c;
|
||||
|
||||
if ((options & SIZE_SUFFIX_3LETTER) && (c != 'B')) {
|
||||
*psuf++ = 'i';
|
||||
*psuf++ = 'B';
|
||||
}
|
||||
else if (((base == KDK_KILOBYTE) || (base == KDK_MEGABYTE) ||
|
||||
(base == KDK_MEGABYTE) || (base == KDK_GIGABYTE)||
|
||||
(base == KDK_TERABYTE) || (base == KDK_PETABYTE) ||
|
||||
(base == KDK_EXABYTE)) && (c != 'B')) {
|
||||
*psuf++ = 'B';
|
||||
}
|
||||
|
||||
*psuf = '\0';
|
||||
|
||||
|
@ -287,7 +300,7 @@ int kdkVolumeBaseCharacterConvert(const char* origin_data, KDKVolumeBaseType res
|
|||
syslog(LOG_ERR, "[KYSDK:utils:%s] parse origin data failed, please contact developer, origin data = %s, errcode = %d\n", __FUNCTION__, origin_data ,ret);
|
||||
return KDK_INVAILD_DATA_FORMAT;
|
||||
}
|
||||
printf("%lu\n", basic_data);
|
||||
// printf("%lu\n", basic_data);
|
||||
char *temp;
|
||||
temp = size_to_human_string(SIZE_SUFFIX_1LETTER | SIZE_DECIMAL_2DIGITS, basic_data, result_base);
|
||||
strcpy(result_data, temp);
|
||||
|
|
|
@ -49,6 +49,12 @@ typedef enum{
|
|||
KDK_TERABYTE, /**< TB */
|
||||
KDK_PETABYTE, /**< PB */
|
||||
KDK_EXABYTE, /**< EB */
|
||||
KDK_KILO, /**< K */
|
||||
KDK_MEGA, /**< M */
|
||||
KDK_GIGA, /**< G */
|
||||
KDK_TERA, /**< T */
|
||||
KDK_PETA, /**< P */
|
||||
KDK_EXA, /**< E */
|
||||
}KDKVolumeBaseType;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue