### Initialize and Start Timers Source: https://context7.com/openkylin/libkysdk-base/llms.txt Demonstrates initializing the timer core and starting both periodic and single-shot timers using absolute time. ```c #include #include #include #include #include // 定时器回调函数 void *timer_callback(void *user_data) { char *msg = (char *)user_data; time_t now; time(&now); char date[32] = {0}; ctime_r(&now, date); date[strlen(date) - 1] = '\0'; printf("[%s] 触发: %s\n", date, msg); return NULL; } int main() { // 初始化定时器核心 if (kdk_timer_init() != 0) { printf("定时器初始化失败\n"); return -1; } // 启动周期性定时器(每2秒触发) size_t timer1 = kdk_timer_start( 2000, // 间隔2000毫秒 (time_handler)timer_callback, KTIMER_PERIODIC, // 周期触发 KTIMER_ABSOLUTE, // 绝对时间(不受系统时间修改影响) "周期任务", 0 ); // 启动单次定时器(5秒后触发一次) size_t timer2 = kdk_timer_start( 5000, (time_handler)timer_callback, KTIMER_SINGLESHOT, // 单次触发 KTIMER_ABSOLUTE, "单次任务", 0 ); sleep(10); // 停止定时器 kdk_timer_stop(timer1); // 销毁定时器核心 kdk_timer_destroy(); return 0; } ``` -------------------------------- ### Initialize and Get Configuration Value Source: https://context7.com/openkylin/libkysdk-base/llms.txt Initializes and parses an INI-format configuration file, returning a handle. Retrieves specific values using group and key names. The configuration file example shows a simple structure with a 'System' group. ```c #include #include int main() { // 初始化配置文件,返回句柄 int id = kdk_conf_init("./app.conf"); if (id < 0) { printf("配置文件加载失败,错误码: %d\n", id); return -1; } // 获取配置值 const char *os = kdk_conf_get_value(id, "System", "OS"); const char *version = kdk_conf_get_value(id, "System", "Version"); printf("操作系统: %s, 版本: %s\n", os, version); // 销毁句柄 kdk_conf_destroy(id); return 0; } // 配置文件示例 (app.conf): // [System] // OS = KylinOS // Version = v10sp1 ``` -------------------------------- ### List Configuration Groups and Keys Source: https://context7.com/openkylin/libkysdk-base/llms.txt Lists all group names and keys within a configuration file, returning them as NULL-terminated string arrays. Includes an example of iterating through groups and their respective keys, retrieving values, and freeing allocated memory. ```c #include #include int main() { int id = kdk_conf_init("struct.conf"); if (id < 0) return -1; // 获取所有组名 char **grouplist = kdk_conf_list_group(id); if (!grouplist) return -1; int index = 0; char *tmpgroup; while ((tmpgroup = grouplist[index])) { printf("组: %s\n", tmpgroup); // 获取该组下的所有键 char **keylist = kdk_conf_list_key(id, tmpgroup); if (keylist) { int k_index = 0; char *tmpkey; while ((tmpkey = keylist[k_index])) { const char *value = kdk_conf_get_value(id, tmpgroup, tmpkey); printf(" %s = %s\n", tmpkey, value); k_index++; } kdk_config_freeall(keylist); // 释放键列表 } index++; } kdk_config_freeall(grouplist); // 释放组列表 kdk_conf_destroy(id); return 0; } // 输出: // 组: Testmode // key1 = value1 // key2 = value2 // 组: System // OS = KylinOS // Version = v10sp1 ``` -------------------------------- ### Timer Initialization and Management Source: https://context7.com/openkylin/libkysdk-base/llms.txt APIs for initializing, starting, stopping, and destroying timers. Supports periodic and one-shot timers with absolute or relative time settings. ```APIDOC ## kdk_timer_init / kdk_timer_start - 创建定时器 ### Description 初始化定时器核心并启动定时任务。支持单次触发和周期触发,支持绝对时间和相对时间。 ### Method `kdk_timer_init`, `kdk_timer_start`, `kdk_timer_stop`, `kdk_timer_destroy` ### Endpoint N/A (Library functions) ### Parameters #### `kdk_timer_start` Parameters - **interval_ms** (size_t) - Required - The interval in milliseconds for the timer. - **handler** (time_handler) - Required - The callback function to execute. - **mode** (KTIMER_MODE) - Required - Timer mode (KTIMER_PERIODIC or KTIMER_SINGLESHOT). - **time_type** (KTIMER_TIME_TYPE) - Required - Time type (KTIMER_ABSOLUTE or KTIMER_RELATIVE). - **user_data** (void *) - Optional - User-defined data passed to the callback. - **priority** (int) - Optional - Priority of the timer task. ### Request Example ```c #include #include #include #include #include // 定时器回调函数 void *timer_callback(void *user_data) { char *msg = (char *)user_data; time_t now; time(&now); char date[32] = {0}; ctime_r(&now, date); date[strlen(date) - 1] = '\0'; printf("[%s] 触发: %s\n", date, msg); return NULL; } int main() { // 初始化定时器核心 if (kdk_timer_init() != 0) { printf("定时器初始化失败\n"); return -1; } // 启动周期性定时器(每2秒触发) size_t timer1 = kdk_timer_start( 2000, // 间隔2000毫秒 (time_handler)timer_callback, KTIMER_PERIODIC, // 周期触发 KTIMER_ABSOLUTE, // 绝对时间(不受系统时间修改影响) "周期任务", 0 ); // 启动单次定时器(5秒后触发一次) size_t timer2 = kdk_timer_start( 5000, (time_handler)timer_callback, KTIMER_SINGLESHOT, // 单次触发 KTIMER_ABSOLUTE, "单次任务", 0 ); sleep(10); // 停止定时器 kdk_timer_stop(timer1); // 销毁定时器核心 kdk_timer_destroy(); return 0; } ``` ### Response N/A (Library functions) ### Error Handling `kdk_timer_init` returns -1 on failure. ``` -------------------------------- ### Match string prefixes and suffixes Source: https://context7.com/openkylin/libkysdk-base/llms.txt Checks if a string starts or ends with a specific substring, with optional case-insensitive matching. ```c #include "cstring-extension.h" #include int main() { const char *filename = "document.pdf"; // 检查前缀(返回0表示匹配) if (strstartswith(filename, "doc") == 0) { printf("文件名以doc开头\n"); } // 检查后缀 if (strendwith(filename, ".pdf") == 0) { printf("这是PDF文件\n"); } // 不区分大小写的前缀检查 if (strstartswith_nocase("Document.PDF", "doc") == 0) { printf("匹配成功(忽略大小写)\n"); } return 0; } ``` -------------------------------- ### Reload Configuration File Source: https://context7.com/openkylin/libkysdk-base/llms.txt Reloads a configuration file during runtime, enabling hot-swapping of configuration settings. The example shows initial value retrieval, a delay for potential file modification, and then re-reading the configuration. ```c #include #include int main() { int id = kdk_conf_init("./app.conf"); // 初始读取 printf("初始值: %s\n", kdk_conf_get_value(id, "System", "Version")); // 等待配置文件可能被修改 sleep(10); // 重新加载配置 int ret = kdk_conf_reload(id); if (ret == 0) { printf("重载后: %s\n", kdk_conf_get_value(id, "System", "Version")); } kdk_conf_destroy(id); return 0; } ``` -------------------------------- ### Initialize and Use Kylog Logger Source: https://context7.com/openkylin/libkysdk-base/llms.txt Initializes the logging system with an optional custom configuration file. If NULL is passed, default configurations are used. Logs are stored in `~/.log` for non-root and `/var/log` for root programs by default. Demonstrates logging at various levels and call trace functionality. ```c #include #include int main(int argc, char **argv) { // 使用自定义配置文件初始化日志系统 int ret = kdk_logger_init("./mylog.conf"); assert(ret == 0); // 或使用默认配置 // kdk_logger_init(NULL); // 输出不同级别的日志 klog_debug("调试信息: 变量值 = %d\n", 42); klog_info("程序启动完成\n"); klog_notice("注意: 配置已加载\n"); klog_warning("警告: 内存使用率较高\n"); klog_err("错误: 文件打开失败\n"); klog_crit("严重: 数据库连接断开\n"); klog_alert("警报: 系统资源耗尽\n"); klog_emerg("紧急: 系统即将崩溃\n"); // 函数调用追踪 klog_calltrace(); return 0; } // 输出: [时间戳] [进程ID] [日志级别] 日志内容 ``` -------------------------------- ### Configuration Module (libkyconf) Source: https://context7.com/openkylin/libkysdk-base/llms.txt APIs for initializing, reading, and managing configuration files in INI format. Supports listing groups and keys, and reloading configurations. ```APIDOC ## kdk_conf_init - Initialize Configuration ### Description Opens and parses a configuration file, returning a configuration handle. Supports standard INI format files with groups and key-value pairs. ### Method `kdk_conf_init(const char *file_path)` ### Parameters #### Path Parameters - `file_path` (string) - Required - Path to the configuration file. ### Request Example ```c #include #include int main() { // Initialize configuration, returns a handle int id = kdk_conf_init("./app.conf"); if (id < 0) { printf("Failed to load configuration file, error code: %d\n", id); return -1; } // Get configuration values const char *os = kdk_conf_get_value(id, "System", "OS"); const char *version = kdk_conf_get_value(id, "System", "Version"); printf("Operating System: %s, Version: %s\n", os, version); // Destroy the handle kdk_conf_destroy(id); return 0; } // Example configuration file (app.conf): // [System] // OS = KylinOS // Version = v10sp1 ``` ## kdk_conf_list_group / kdk_conf_list_key - List Configuration Items ### Description Lists all groups and keys within a configuration file, returning NULL-terminated string arrays. ### Method `char **kdk_conf_list_group(int conf_id)` `char **kdk_conf_list_key(int conf_id, const char *group_name)` ### Parameters #### Path Parameters - `conf_id` (integer) - Required - The configuration handle returned by `kdk_conf_init`. - `group_name` (string) - Required - The name of the group to list keys from. ### Request Example ```c #include #include int main() { int id = kdk_conf_init("struct.conf"); if (id < 0) return -1; // Get all group names char **grouplist = kdk_conf_list_group(id); if (!grouplist) return -1; int index = 0; char *tmpgroup; while ((tmpgroup = grouplist[index])) { printf("Group: %s\n", tmpgroup); // Get all keys within this group char **keylist = kdk_conf_list_key(id, tmpgroup); if (keylist) { int k_index = 0; char *tmpkey; while ((tmpkey = keylist[k_index])) { const char *value = kdk_conf_get_value(id, tmpgroup, tmpkey); printf(" %s = %s\n", tmpkey, value); k_index++; } kdk_config_freeall(keylist); // Free key list } index++; } kdk_config_freeall(grouplist); // Free group list kdk_conf_destroy(id); return 0; } // Example Output: // Group: Testmode // key1 = value1 // key2 = value2 // Group: System // OS = KylinOS // Version = v10sp1 ``` ## kdk_conf_reload - Reload Configuration ### Description Reloads the configuration file at runtime, useful for configuration hot-update scenarios. ### Method `kdk_conf_reload(int conf_id)` ### Parameters #### Path Parameters - `conf_id` (integer) - Required - The configuration handle returned by `kdk_conf_init`. ### Request Example ```c #include #include int main() { int id = kdk_conf_init("./app.conf"); // Initial read printf("Initial value: %s\n", kdk_conf_get_value(id, "System", "Version")); // Wait for the configuration file to potentially be modified sleep(10); // Reload configuration int ret = kdk_conf_reload(id); if (ret == 0) { printf("After reload: %s\n", kdk_conf_get_value(id, "System", "Version")); } kdk_conf_destroy(id); return 0; } ``` ``` -------------------------------- ### Log Module (libkylog) Source: https://context7.com/openkylin/libkysdk-base/llms.txt APIs for initializing, configuring, and using the logging system. Supports various log levels, custom directories, and asynchronous operations. ```APIDOC ## kdk_logger_init - Initialize Logging System ### Description Initializes the logger, optionally accepting a custom configuration file path. If NULL is passed, default configurations are used. By default, non-root programs store logs in `~/.log`, and root programs store them in `/var/log`. ### Method `kdk_logger_init(const char *conf_path)` ### Parameters #### Path Parameters - `conf_path` (string) - Optional - Path to a custom log configuration file. If NULL, default configuration is used. ### Request Example ```c #include #include int main(int argc, char **argv) { // Initialize logging system with a custom configuration file int ret = kdk_logger_init("./mylog.conf"); assert(ret == 0); // Or use default configuration // kdk_logger_init(NULL); // Output logs at different levels klog_debug("Debug message: variable value = %d\n", 42); klog_info("Program startup complete\n"); klog_notice("Notice: Configuration loaded\n"); klog_warning("Warning: High memory usage\n"); klog_err("Error: Failed to open file\n"); klog_crit("Critical: Database connection lost\n"); klog_alert("Alert: System resources exhausted\n"); klog_emerg("Emergency: System about to crash\n"); // Function call tracing klog_calltrace(); return 0; } // Output format: [Timestamp] [Process ID] [Log Level] Log Message ``` ## kdk_logger_setdir - Set Log Storage Directory ### Description Specifies the directory where log files will be stored. If this function is not called, non-root programs use `~/.log`, and root programs use `/var/log`. ### Method `kdk_logger_setdir(const char *dir_path)` ### Parameters #### Path Parameters - `dir_path` (string) - Required - The directory path for storing log files. ### Request Example ```c #include int main() { // Set a custom log directory int ret = kdk_logger_setdir("/var/log/myapp"); if (ret != 0) { printf("Failed to set log directory\n"); return -1; } // Enable automatic newline kdk_logger_set_autowrap(1); // Logs will now automatically have newline characters appended klog_info("This log will automatically wrap"); klog_info("Next log message"); // Manually flush the buffer (use in asynchronous mode) kdk_logger_flush(); return 0; } ``` ### Log Configuration File Format The logging system supports detailed configuration through a file, including output location, format, and rotation rules. ```ini [TYPE] # Log identifier, e.g., user, Local3 identifier=user # Write type: SYNC (synchronous) or ASYNC (asynchronous) synctype=sync # Output location: syslog, specfile, stdout output=specfile [CUSTOM] # Log level: 0-8, higher values mean more detailed logging logLevel=7 # Specify log file name, empty uses "process_name.log" specName=myapp.log # Store logs categorized by level levelBasedStorage=0 [FORMAT] # Include log type in output f_identifier=1 # Include PID in output f_pid=1 # Include filename in output f_filename=0 # Include function and line information in output f_funcline=0 [DUMP] # Rotation rules: daily, weekly, size, none rules=daily # Threshold for size-based rotation thresholdAsSizeRules=1GB # Compress after rotation compress=1 ``` ``` -------------------------------- ### Set Log Directory and Auto-wrap Source: https://context7.com/openkylin/libkysdk-base/llms.txt Sets a custom directory for log file storage. If not called, defaults are used (`~/.log` for non-root, `/var/log` for root). Enables automatic newline characters for log messages and demonstrates manual buffer flushing for asynchronous logging. ```c #include int main() { // 设置自定义日志目录 int ret = kdk_logger_setdir("/var/log/myapp"); if (ret != 0) { printf("设置日志目录失败\n"); return -1; } // 启用自动换行 kdk_logger_set_autowrap(1); // 现在日志会自动添加换行符 klog_info("这条日志会自动换行"); klog_info("下一条日志"); // 手动刷新缓存(异步模式下使用) kdk_logger_flush(); return 0; } ``` -------------------------------- ### Read and Write GSettings Integers Source: https://context7.com/openkylin/libkysdk-base/llms.txt Performs read, write, and reset operations on integer-type configuration keys, including reading floating-point values. ```c #include "libkygsetting.h" #include int main() { // 设置整数值 int ret = kdk_settings_set_int( "org.ukui.audio", // schema_id "output-volume", // key 67 // value ); // 获取整数值 int volume = kdk_settings_get_int("org.ukui.audio", "output-volume"); printf("音量: %d\n", volume); // 获取浮点数值 double scale = kdk_settings_get_double( "org.ukui.SettingsDaemon.plugins.xsettings", "scaling-factor" ); printf("缩放因子: %.1f\n", scale); // 重置为默认值 kdk_settings_reset("org.ukui.audio", "output-volume"); return 0; } ``` -------------------------------- ### Read and Write GSettings Strings Source: https://context7.com/openkylin/libkysdk-base/llms.txt Performs read and write operations on string-type configuration keys in GSettings. ```c #include "libkygsetting.h" #include int main() { // 设置字符串值 int ret = kdk_settings_set_string( "org.gnome.evolution", // schema_id "version", // key "3.36.1" // value ); printf("设置结果: %d\n", ret); // 获取字符串值 char *version = kdk_settings_get_string("org.gnome.evolution", "version"); printf("版本号: %s\n", version); return 0; } ``` -------------------------------- ### GSettings String Operations Source: https://context7.com/openkylin/libkysdk-base/llms.txt Read and write string type configuration items in GSettings, used for integration with GNOME/UKUI desktop environments. ```APIDOC ## kdk_settings_set_string / kdk_settings_get_string - 字符串设置操作 ### Description 读写GSettings中的字符串类型配置项,用于与GNOME/UKUI桌面环境集成。 ### Method `kdk_settings_set_string`, `kdk_settings_get_string` ### Endpoint N/A (Library functions) ### Parameters #### `kdk_settings_set_string` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. - **value** (const char *) - Required - The string value to set. #### `kdk_settings_get_string` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. ### Request Example ```c #include "libkygsetting.h" #include int main() { // 设置字符串值 int ret = kdk_settings_set_string( "org.gnome.evolution", // schema_id "version", // key "3.36.1" // value ); printf("设置结果: %d\n", ret); // 获取字符串值 char *version = kdk_settings_get_string("org.gnome.evolution", "version"); printf("版本号: %s\n", version); return 0; } ``` ### Response #### Success Response (0) Indicates the operation was successful. #### Error Response (-1) Indicates the operation failed. ### Return Value - 0: Success - -1: Failure ``` -------------------------------- ### Kylog Configuration File Format Source: https://context7.com/openkylin/libkysdk-base/llms.txt Defines the format for the Kylog configuration file, specifying options for log identifier, synchronization type, output destination, log level, file naming, log classification, and rotation rules (daily, weekly, size-based) with optional compression. ```ini [TYPE] # 日志标识,有user、Local3等类型 identifier=user # 写入方式:SYNC(同步)或ASYNC(异步) synctype=sync # 输出位置:syslog、specfile、stdout output=specfile [CUSTOM] # 日志级别:0-8,数值越大记录越详细 logLevel=7 # 指定日志文件名称,为空则使用"进程名.log" specName=myapp.log # 按日志等级分类存储 levelBasedStorage=0 [FORMAT] # 输出中包含日志类型 f_identifier=1 # 输出中包含PID f_pid=1 # 输出中包含文件名 f_filename=0 # 输出中包含函数与行信息 f_funcline=0 [DUMP] # 转储规则:daily、weekly、size、none rules=daily # 按大小转储时的阈值 thresholdAsSizeRules=1GB # 转储后是否压缩 compress=1 ``` -------------------------------- ### GSettings Integer and Double Operations Source: https://context7.com/openkylin/libkysdk-base/llms.txt Read and write integer and double type configuration items in GSettings. ```APIDOC ## kdk_settings_set_int / kdk_settings_get_int - 整数设置操作 ### Description 读写GSettings中的整数类型配置项。 ### Method `kdk_settings_set_int`, `kdk_settings_get_int`, `kdk_settings_get_double`, `kdk_settings_reset` ### Endpoint N/A (Library functions) ### Parameters #### `kdk_settings_set_int` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. - **value** (int) - Required - The integer value to set. #### `kdk_settings_get_int` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. #### `kdk_settings_get_double` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. #### `kdk_settings_reset` Parameters - **schema_id** (const char *) - Required - The schema ID of the GSettings key. - **key** (const char *) - Required - The key of the GSettings item. ### Request Example ```c #include "libkygsetting.h" #include int main() { // 设置整数值 int ret = kdk_settings_set_int( "org.ukui.audio", // schema_id "output-volume", // key 67 // value ); // 获取整数值 int volume = kdk_settings_get_int("org.ukui.audio", "output-volume"); printf("音量: %d\n", volume); // 获取浮点数值 double scale = kdk_settings_get_double( "org.ukui.SettingsDaemon.plugins.xsettings", "scaling-factor" ); printf("缩放因子: %.1f\n", scale); // 重置为默认值 kdk_settings_reset("org.ukui.audio", "output-volume"); return 0; } ``` ### Response N/A (Library functions) ``` -------------------------------- ### Convert storage units with kdkVolumeBaseNumericalConvert Source: https://context7.com/openkylin/libkysdk-base/llms.txt Converts numerical storage values between different units such as MB, GB, and TB. Ensure kyutils.h is included. ```c #include "kyutils.h" #include int main() { double origin = 1024.0; double result; // MB转GB int ret = kdkVolumeBaseNumericalConvert( origin, // 原始值 KDK_MEGABYTE, // 原始单位:MB KDK_GIGABYTE, // 目标单位:GB &result // 结果指针 ); if (ret == KDK_NOERR) { printf("%.2f MB = %.2f GB\n", origin, result); // 1024.00 MB = 1.00 GB } // 支持的单位类型: // KDK_KILOBYTE (KB), KDK_MEGABYTE (MB), KDK_GIGABYTE (GB) // 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) return 0; } ``` -------------------------------- ### Trim strings with strstrip and variants Source: https://context7.com/openkylin/libkysdk-base/llms.txt Removes specified characters or whitespace from the beginning and end of strings. ```c #include "cstring-extension.h" #include int main() { char str1[] = "###hello world###"; strstrip(str1, '#'); printf("strstrip: |%s|\n", str1); // |hello world| char str2[] = " hello world \n"; strstripspace(str2); printf("strstripspace: |%s|\n", str2); // |hello world| char str3[] = "\t hello \t"; strstripblank(str3); printf("strstripblank: |%s|\n", str3); // |hello| return 0; } ``` -------------------------------- ### Reset Timer Interval Source: https://context7.com/openkylin/libkysdk-base/llms.txt Shows how to dynamically update the trigger interval of an existing timer. ```c #include #include #include void *my_task(void *data) { printf("任务执行: %s\n", (char *)data); return NULL; } int main() { kdk_timer_init(); // 启动一个3秒后触发的单次定时器 size_t timer_id = kdk_timer_start( 3000, (time_handler)my_task, KTIMER_SINGLESHOT, KTIMER_ABSOLUTE, "延迟任务", 0 ); sleep(1); printf("重置定时器为6秒\n"); // 重置为6秒后触发 kdk_timer_reset(timer_id, 6000); sleep(8); kdk_timer_destroy(); return 0; } ``` -------------------------------- ### Upload Diagnostic Buried Point Data Source: https://context7.com/openkylin/libkysdk-base/llms.txt Uploads application behavior data for analysis using the diagnostics module. ```c #include #include "libkydiagnostics.h" int main(void) { // 应用包名 char appName[] = "com.example.myapp"; // 消息类型 char messageType[] = "UserAction"; // 构建埋点数据数组 KBuriedPoint data[3]; data[0].key = "action"; data[0].value = "click_button"; data[1].key = "page"; data[1].value = "home"; data[2].key = "timestamp"; data[2].value = "1702345678"; // 上传埋点数据 int ret = kdk_buried_point(appName, messageType, data, 3); if (ret == 0) { printf("埋点上传成功\n"); } else { printf("埋点上传失败,错误码: %d\n", ret); } return 0; } ``` -------------------------------- ### Convert string case with str2upper and str2lower Source: https://context7.com/openkylin/libkysdk-base/llms.txt Transforms all alphabetic characters in a string to uppercase or lowercase. ```c #include "cstring-extension.h" #include int main() { char str1[] = "Hello World"; str2upper(str1); printf("大写: %s\n", str1); // HELLO WORLD char str2[] = "Hello World"; str2lower(str2); printf("小写: %s\n", str2); // hello world return 0; } ``` -------------------------------- ### Convert Storage Capacity Units Source: https://context7.com/openkylin/libkysdk-base/llms.txt Converts a string-formatted storage capacity value into a specified unit. ```c #include "kyutils.h" #include int main() { char origin_data[] = "10000.24MB"; char result_data[50] = {0}; // 将MB转换为GB int ret = kdkVolumeBaseCharacterConvert( origin_data, // 原始数据 KDK_GIGABYTE, // 目标单位:GB result_data // 结果缓冲区 ); if (ret == KDK_NOERR) { printf("转换结果: %s\n", result_data); // 输出: 9.77GB } return 0; } ``` -------------------------------- ### Split strings with strsplit Source: https://context7.com/openkylin/libkysdk-base/llms.txt Splits a string into an array of strings based on a delimiter. The returned array must be freed by the caller. ```c #include "cstring-extension.h" #include #include int main() { char path[] = "/usr/local/bin"; char **parts = strsplit(path, '/'); // 遍历分割结果 for (int i = 0; parts[i] != NULL; i++) { printf("[%d]: %s\n", i, parts[i]); } // 释放字符串列表(注意:各字符串本身不需要释放) free(parts); return 0; } // 输出: // [0]: // [1]: usr // [2]: local // [3]: bin ``` -------------------------------- ### Volume Base Character Convert Source: https://context7.com/openkylin/libkysdk-base/llms.txt Converts string formatted storage capacity values to a specified unit. ```APIDOC ## kdkVolumeBaseCharacterConvert - 字符型容量单位转换 ### Description 将字符串格式的存储容量值转换为指定单位。 ### Method `kdkVolumeBaseCharacterConvert` ### Endpoint N/A (Library function) ### Parameters - **origin_data** (char *) - Required - The original string data representing storage capacity. - **target_unit** (KDK_VOLUME_UNIT) - Required - The target unit for conversion (e.g., KDK_GIGABYTE). - **result_data** (char *) - Required - A buffer to store the converted string. ### Request Example ```c #include "kyutils.h" #include int main() { char origin_data[] = "10000.24MB"; char result_data[50] = {0}; // 将MB转换为GB int ret = kdkVolumeBaseCharacterConvert( origin_data, // 原始数据 KDK_GIGABYTE, // 目标单位:GB result_data // 结果缓冲区 ); if (ret == KDK_NOERR) { printf("转换结果: %s\n", result_data); // 输出: 9.77GB } return 0; } ``` ### Response N/A (Library function) ### Return Value - KDK_NOERR: Success - Other values indicate specific errors. ``` -------------------------------- ### Find character positions with strfirstof and strlastof Source: https://context7.com/openkylin/libkysdk-base/llms.txt Locates the first or last occurrence of a character in a string and counts total occurrences. ```c #include "cstring-extension.h" #include int main() { const char *path = "/home/user/documents/file.txt"; int first_slash = strfirstof(path, '/'); int last_slash = strlastof(path, '/'); printf("第一个/位置: %d\n", first_slash); // 0 printf("最后一个/位置: %d\n", last_slash); // 21 // 统计字符出现次数 size_t count = strcounts(path, '/'); printf("斜杠出现次数: %zu\n", count); // 4 return 0; } ``` -------------------------------- ### Diagnostic Buried Point Source: https://context7.com/openkylin/libkysdk-base/llms.txt Sends application behavior buried point data to the system for analysis and diagnostics. ```APIDOC ## kdk_buried_point - 上传埋点数据 ### Description 向系统发送应用程序行为埋点数据,用于应用使用情况分析和诊断。 ### Method `kdk_buried_point` ### Endpoint N/A (Library function) ### Parameters - **appName** (char *) - Required - The package name of the application. - **messageType** (char *) - Required - The type of the message. - **data** (KBuriedPoint *) - Required - An array of key-value pairs representing the buried point data. - **data_count** (int) - Required - The number of elements in the data array. ### Request Body ```c typedef struct { const char *key; const char *value; } KBuriedPoint; ``` ### Request Example ```c #include #include "libkydiagnostics.h" int main(void) { // 应用包名 char appName[] = "com.example.myapp"; // 消息类型 char messageType[] = "UserAction"; // 构建埋点数据数组 KBuriedPoint data[3]; data[0].key = "action"; data[0].value = "click_button"; data[1].key = "page"; data[1].value = "home"; data[2].key = "timestamp"; data[2].value = "1702345678"; // 上传埋点数据 int ret = kdk_buried_point(appName, messageType, data, 3); if (ret == 0) { printf("埋点上传成功\n"); } else { printf("埋点上传失败,错误码: %d\n", ret); } return 0; } ``` ### Response #### Success Response (0) Indicates successful upload. #### Error Response (-1) Indicates failure. ### Return Value - 0: Success - -1: Failure ``` -------------------------------- ### Timer Reset Source: https://context7.com/openkylin/libkysdk-base/llms.txt Dynamically modifies the trigger interval of an existing timer. ```APIDOC ## kdk_timer_reset - 重置定时器 ### Description 动态修改定时器的触发间隔时间。 ### Method `kdk_timer_reset` ### Endpoint N/A (Library function) ### Parameters - **timer_id** (size_t) - Required - The ID of the timer to reset. - **new_interval_ms** (size_t) - Required - The new interval in milliseconds. ### Request Example ```c #include #include #include void *my_task(void *data) { printf("任务执行: %s\n", (char *)data); return NULL; } int main() { kdk_timer_init(); // 启动一个3秒后触发的单次定时器 size_t timer_id = kdk_timer_start( 3000, (time_handler)my_task, KTIMER_SINGLESHOT, KTIMER_ABSOLUTE, "延迟任务", 0 ); sleep(1); printf("重置定时器为6秒\n"); // 重置为6秒后触发 kdk_timer_reset(timer_id, 6000); sleep(8); kdk_timer_destroy(); return 0; } ``` ### Response N/A (Library function) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.