|
在取得資料數值的情況
[MCM_DTYPE_FLAG_TD data_access] 要取出哪邊的資料.
使用 MCM_DACCESS_SYS 或 MCM_DACCESS_NEW 取得資料時, 對應的區域不一定有資料. 各種資料狀態下要注意的 :
|
|||||||||||||||||||||||||||||
|
在修改資料數值的情況
[MCM_DTYPE_FLAG_TD data_access] 要如何修改資料數值.
MCM_DACCESS_SYS
MCM_DACCESS_NEW
在 mcm_daemon 處理資料的流程中 [詳細][B], 在 [B03] 的處理方式 :
在 mcm_daemon 處理資料的流程中 [詳細][B], 在 [B06] 的處理方式 :
在各種情況下使用上的注意事項和限制 :
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
mcm_config_get_max_count_by_path 取得資料筆數上限, 也就是資料模型中的 $(max) 值.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RO;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_max_count_test_01";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_max_count_test_01(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
MCM_DTYPE_EK_TD max_count;
// 範例 : 取得 device.system 的資料筆數上限.
path1 = "device.system";
if(mcm_config_get_max_count_by_path(this_session, path1, &max_count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_max_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, max_count);
// 範例 : 取得 device.vap.* 的資料筆數上限.
path1 = "device.vap.*";
if(mcm_config_get_max_count_by_path(this_session, path1, &max_count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_max_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, max_count);
// 範例 : 取得 device.vap.*.station.* 的資料筆數上限.
path1 = "device.vap.*.station.*";
if(mcm_config_get_max_count_by_path(this_session, path1, &max_count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_max_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, max_count);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
除了上述方式外, 可以使用另一種方式取得 group 的資料筆數上限. [詳細] 範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RO;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_max_count_test_02";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_max_count_test_02(
struct mcm_service_session_t *this_session)
{
char *path1;
// 範例 : 取得 device.system 的資料筆數上限.
path1 = "device.system";
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, MCM_MCOUNT_DEVICE_SYSTEM_MAX_COUNT);
// 範例 : 取得 device.vap.* 的資料筆數上限.
path1 = "device.vap.*";
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, MCM_MCOUNT_DEVICE_VAP_MAX_COUNT);
// 範例 : 取得 device.vap.*.station.* 的資料筆數上限.
path1 = "device.vap.*.station.*";
DMSG("[max-count] %s = " MCM_DTYPE_EK_PF, path1, MCM_MCOUNT_DEVICE_VAP_STATION_MAX_COUNT);
return MCM_RCODE_PASS;
}
|
|
mcm_config_get_count_by_path 取得目前的資料筆數.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RO;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_count_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_count_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
MCM_DTYPE_EK_TD count;
// 範例 : 取得 device.system 的資料筆數.
path1 = "device.system";
if(mcm_config_get_count_by_path(this_session, path1, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 範例 : 取得 device.vap.* 的資料筆數.
path1 = "device.vap.*";
if(mcm_config_get_count_by_path(this_session, path1, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 範例 : 取得 device.vap.@1.station.* 的資料筆數.
path1 = "device.vap.@1.station.*";
if(mcm_config_get_count_by_path(this_session, path1, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 範例 : 取得 device.vap.#23.station.* 的資料筆數.
path1 = "device.vap.#23.station.*";
if(mcm_config_get_count_by_path(this_session, path1, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_count_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_get_alone_by_path 讀出 member 的資料.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
MCM_DTYPE_S_TD date[MCM_BSIZE_DEVICE_SYSTEM_DATE];
MCM_DTYPE_RK_TD rule;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-02 : 設定 device.system.date
path1 = "device.system.date";
snprintf(date, sizeof(date), "2013/05/%02u", rand() % 30);
DMSG("[set-alone] %s = " MCM_DTYPE_S_PF, path1, date);
if(mcm_lulib_set_alone(&self_lulib, path1, date, strlen(date)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_alone(%s) fail", path1);
goto FREE_02;
}
// 範例-03 : 設定 device.vap.#15.station.@1.rule
path1 = "device.vap.#15.station.@1.rule";
rule = rand() % 50;
DMSG("[set-alone] %s = " MCM_DTYPE_RK_PF, path1, rule);
if(mcm_lulib_set_alone(&self_lulib, path1, &rule, sizeof(rule)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_alone(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_get_alone_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_alone_value_test(
struct mcm_service_session_t *this_session)
{
int fret;
char *path1;
MCM_DTYPE_S_TD descript[MCM_BSIZE_DEVICE_DESCRIPT];
MCM_DTYPE_B_TD serial_number[MCM_BSIZE_DEVICE_SERIAL_NUMBER];
MCM_DTYPE_S_TD date[MCM_BSIZE_DEVICE_SYSTEM_DATE];
MCM_DTYPE_RK_TD rule;
path1 = "device.descript";
// 範例-01a : 取得 device.descript (SYS 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_SYS, descript);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][SYS ] %s = " MCM_DTYPE_S_PF, path1, descript);
// 範例-01b : 取得 device.descript (AUTO 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_AUTO, descript);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][AUTO] %s = " MCM_DTYPE_S_PF " [%s]",
path1, descript, fret == MCM_DACCESS_SYS ? "SYS" : "NEW");
path1 = "device.serial_number";
// 範例-01c : 取得 device.serial_number (SYS 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_SYS, serial_number);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][SYS ] %s = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF,
path1,
serial_number[0], serial_number[1], serial_number[2], serial_number[3],
serial_number[4], serial_number[5], serial_number[6], serial_number[7],
serial_number[8], serial_number[9]);
// 範例-01d : 取得 device.serial_number (AUTO 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_AUTO, serial_number);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][AUTO] %s = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF " [%s]",
path1,
serial_number[0], serial_number[1], serial_number[2], serial_number[3],
serial_number[4], serial_number[5], serial_number[6], serial_number[7],
serial_number[8], serial_number[9], fret == MCM_DACCESS_SYS ? "SYS" : "NEW");
path1 = "device.system.date";
// 範例-02a : 取得 device.system.date (SYS 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_SYS, date);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][SYS ] %s = " MCM_DTYPE_S_PF, path1, date);
// 範例-02b : 取得 device.system.date (NEW 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_NEW, date);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][NEW ] %s = " MCM_DTYPE_S_PF, path1, date);
// 範例-02c : 取得 device.system.date (AUTO 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_AUTO, date);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][AUTO] %s = " MCM_DTYPE_S_PF " [%s]",
path1, date, fret == MCM_DACCESS_SYS ? "SYS" : "NEW");
path1 = "device.vap.#15.station.@1.rule";
// 範例-03a : 取得 device.vap.#15.station.@1.rule (SYS 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_SYS, &rule);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][SYS ] %s = " MCM_DTYPE_RK_PF, path1, rule);
// 範例-03b : 取得 device.vap.#15.station.@1.rule (NEW 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_NEW, &rule);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][NEW ] %s = " MCM_DTYPE_RK_PF, path1, rule);
// 範例-03c : 取得 device.vap.#15.station.@1.rule (AUTO 模式)
fret = mcm_config_get_alone_by_path(this_session, path1, MCM_DACCESS_AUTO, &rule);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-alone][AUTO] %s = " MCM_DTYPE_RK_PF " [%s]",
path1, rule, fret == MCM_DACCESS_SYS ? "SYS" : "NEW");
FREE_01:
return fret;
}
|
|
mcm_config_set_alone_by_path 將資料寫入 member.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
MCM_DTYPE_IUI_TD channel;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-03 : 設定 device.vap.#8.channel
path1 = "device.vap.#8.channel";
channel = rand() % 200;
DMSG("[set-alone] %s = " MCM_DTYPE_IUI_PF, path1, channel);
if(mcm_lulib_set_alone(&self_lulib, path1, &channel, sizeof(channel)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_alone(%s) fail", path1);
goto FREE_02;
}
// 範例-04 : 增加 device.vap.@3.station.#1
path1 = "device.vap.@3.station.#1";
DMSG("[add-entry] %s", path1);
if(mcm_lulib_add_entry(&self_lulib, path1, NULL, NULL, 0) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_add_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_set_alone_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_set_alone_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
MCM_DTYPE_S_TD descript[MCM_BSIZE_DEVICE_DESCRIPT];
MCM_DTYPE_B_TD serial_number[MCM_BSIZE_DEVICE_SERIAL_NUMBER];
MCM_DTYPE_IULL_TD uptime;
MCM_DTYPE_IUI_TD channel;
MCM_DTYPE_RK_TD rule;
MCM_DTYPE_USIZE_TD i;
srand(time(NULL));
// 範例-01a : 設定 device.descript (SYS 模式)
path1 = "device.descript";
snprintf(descript, sizeof(descript), "network-device-%02u", rand() % 100);
DMSG("[set-alone][SYS] %s = " MCM_DTYPE_S_PF, path1, descript);
if(mcm_config_set_alone_by_path(this_session, path1, MCM_DACCESS_SYS, descript,
strlen(descript)) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_alone_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-01b : 設定 device.serial_number (SYS 模式)
path1 = "device.serial_number";
for(i = 0; i < sizeof(serial_number); i++)
serial_number[i] = rand() % 256;
DMSG("[set-alone][SYS] %s = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF,
path1,
serial_number[0], serial_number[1], serial_number[2], serial_number[3],
serial_number[4], serial_number[5], serial_number[6], serial_number[7],
serial_number[8], serial_number[9]);
if(mcm_config_set_alone_by_path(this_session, path1, MCM_DACCESS_SYS, serial_number,
sizeof(serial_number)) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_alone_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-02 : 設定 device.system.uptime (NEW 模式)
path1 = "device.system.uptime";
uptime = rand();
DMSG("[set-alone][NEW] %s = " MCM_DTYPE_IULL_PF, path1, uptime);
if(mcm_config_set_alone_by_path(this_session, path1, MCM_DACCESS_NEW, &uptime, sizeof(uptime))
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_alone_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-03 : 設定 device.vap.#8.channel (NEW 模式)
path1 = "device.vap.#8.channel";
channel = rand() % 200;
DMSG("[set-alone][NEW] %s = " MCM_DTYPE_IUI_PF, path1, channel);
if(mcm_config_set_alone_by_path(this_session, path1, MCM_DACCESS_NEW, &channel,
sizeof(channel)) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_alone_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-04 : 設定 device.vap.@3.station.#1.rule (NEW 模式)
path1 = "device.vap.@3.station.#1.rule";
rule = rand() % 50;
DMSG("[set-alone][NEW] %s = " MCM_DTYPE_RK_PF, path1, rule);
if(mcm_config_set_alone_by_path(this_session, path1, MCM_DACCESS_NEW, &rule, sizeof(rule))
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_alone_by_path(%s) fail", path1);
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_get_entry_by_path 讀出 entry 的資料.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
struct mcm_dv_device_system_t system_v;
struct mcm_dv_device_vap_station_t station_v;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-02 : 設定 device.system
path1 = "device.system";
memset(&system_v, 0, sizeof(system_v));
snprintf(system_v.date, sizeof(system_v.date), "2010/11/%u", rand() % 30);
snprintf(system_v.ip_addr, sizeof(system_v.ip_addr), "192.168.11.%u", rand() % 250);
system_v.uptime = rand();
system_v.loading = ((MCM_DTYPE_FD_TD) 25000) / ((rand() % 100) + 1);
DMSG("[set-entry] %s.date = " MCM_DTYPE_S_PF, path1, system_v.date);
DMSG("[set-entry] %s.ip_addr = " MCM_DTYPE_S_PF, path1, system_v.ip_addr);
DMSG("[set-entry] %s.uptime = " MCM_DTYPE_IULL_PF, path1, system_v.uptime);
DMSG("[set-entry] %s.loading = " MCM_DTYPE_FD_PF, path1, system_v.loading);
if(mcm_lulib_set_entry(&self_lulib, path1, &system_v, sizeof(system_v)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_entry(%s) fail", path1);
goto FREE_02;
}
// 範例-03 : 設定 device.vap.@2.station.@1
path1 = "device.vap.@2.station.@1";
memset(&station_v, 0, sizeof(station_v));
snprintf(station_v.mac_addr, sizeof(station_v.mac_addr), "00:22:44:66:BB:%02X", rand() % 255);
station_v.rule = rand() % 50;
DMSG("[set-entry] %s.mac_addr = " MCM_DTYPE_S_PF, path1, station_v.mac_addr);
DMSG("[set-entry] %s.rule = " MCM_DTYPE_RK_PF, path1, station_v.rule);
if(mcm_lulib_set_entry(&self_lulib, path1, &station_v, sizeof(station_v)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_get_entry_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_entry_value_test(
struct mcm_service_session_t *this_session)
{
int fret;
char *path1, *source;
struct mcm_dv_device_t device_v;
struct mcm_dv_device_system_t system_v;
struct mcm_dv_device_vap_station_t station_v;
path1 = "device";
// 範例-01a : 取得 device (SYS 模式).
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_SYS, &device_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-entry][SYS ] %s.descript = " MCM_DTYPE_S_PF, path1, device_v.descript);
DMSG("[get-entry][SYS ] %s.serial_number = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF,
path1,
device_v.serial_number[0], device_v.serial_number[1], device_v.serial_number[2],
device_v.serial_number[3], device_v.serial_number[4], device_v.serial_number[5],
device_v.serial_number[6], device_v.serial_number[7], device_v.serial_number[8],
device_v.serial_number[9]);
// 範例-01b : 取得 device (AUTO 模式).
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_AUTO, &device_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.descript = " MCM_DTYPE_S_PF " [%s]",
path1, device_v.descript, source);
DMSG("[get-entry][AUTO] %s.serial_number = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF " [%s]",
path1,
device_v.serial_number[0], device_v.serial_number[1], device_v.serial_number[2],
device_v.serial_number[3], device_v.serial_number[4], device_v.serial_number[5],
device_v.serial_number[6], device_v.serial_number[7], device_v.serial_number[8],
device_v.serial_number[9], source);
path1 = "device.system";
// 範例-02a : 取得 device.system (SYS 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_SYS, &system_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-entry][SYS ] %s.date = " MCM_DTYPE_S_PF, path1, system_v.date);
DMSG("[get-entry][SYS ] %s.ip_addr = " MCM_DTYPE_S_PF, path1, system_v.ip_addr);
DMSG("[get-entry][SYS ] %s.uptime = " MCM_DTYPE_IULL_PF, path1, system_v.uptime);
DMSG("[get-entry][SYS ] %s.loading = " MCM_DTYPE_FD_PF, path1, system_v.loading);
// 範例-02b : 取得 device.system (NEW 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_NEW, &system_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-entry][NEW ] %s.date = " MCM_DTYPE_S_PF, path1, system_v.date);
DMSG("[get-entry][NEW ] %s.ip_addr = " MCM_DTYPE_S_PF, path1, system_v.ip_addr);
DMSG("[get-entry][NEW ] %s.uptime = " MCM_DTYPE_IULL_PF, path1, system_v.uptime);
DMSG("[get-entry][NEW ] %s.loading = " MCM_DTYPE_FD_PF, path1, system_v.loading);
// 範例-02c : 取得 device.system (AUTO 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_AUTO, &system_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.date = " MCM_DTYPE_S_PF " [%s]",
path1, system_v.date, source);
DMSG("[get-entry][AUTO] %s.ip_addr = " MCM_DTYPE_S_PF " [%s]",
path1, system_v.ip_addr, source);
DMSG("[get-entry][AUTO] %s.uptime = " MCM_DTYPE_IULL_PF " [%s]",
path1, system_v.uptime, source);
DMSG("[get-entry][AUTO] %s.loading = " MCM_DTYPE_FD_PF " [%s]",
path1, system_v.loading, source);
path1 = "device.vap.@2.station.@1";
// 範例-03a : 取得 device.vap.#15.station.@1 (SYS 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_SYS, &station_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-entry][SYS ] %s.ekey = " MCM_DTYPE_EK_PF, path1, station_v.ekey);
DMSG("[get-entry][SYS ] %s.mac_addr = " MCM_DTYPE_S_PF, path1, station_v.mac_addr);
DMSG("[get-entry][SYS ] %s.rule = " MCM_DTYPE_RK_PF, path1, station_v.rule);
// 範例-03b : 取得 device.vap.#15.station.@1 (NEW 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_NEW, &station_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[get-entry][NEW ] %s.ekey = " MCM_DTYPE_EK_PF, path1, station_v.ekey);
DMSG("[get-entry][NEW ] %s.mac_addr = " MCM_DTYPE_S_PF, path1, station_v.mac_addr);
DMSG("[get-entry][NEW ] %s.rule = " MCM_DTYPE_RK_PF, path1, station_v.rule);
// 範例-03c : 取得 device.vap.#15.station.@1 (AUTO 模式)
fret = mcm_config_get_entry_by_path(this_session, path1, MCM_DACCESS_AUTO, &station_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_alone_by_path(%s) fail", path1);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path1, station_v.ekey, source);
DMSG("[get-entry][AUTO] %s.mac_addr = " MCM_DTYPE_S_PF " [%s]",
path1, station_v.mac_addr, source);
DMSG("[get-entry][AUTO] %s.rule = " MCM_DTYPE_RK_PF " [%s]",
path1, station_v.rule, source);
FREE_01:
return fret;
}
|
|
mcm_config_set_entry_by_path 將資料寫入 entry.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
struct mcm_dv_device_vap_t vap_v;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-03 : 設定 device.vap.@1
path1 = "device.vap.@1";
memset(&vap_v, 0, sizeof(vap_v));
snprintf(vap_v.ssid, sizeof(vap_v.ssid), "ssid-%u", rand() % 100);
vap_v.channel = rand() % 150;
DMSG("[set-entry] %s.ssid = " MCM_DTYPE_S_PF, path1, vap_v.ssid);
DMSG("[set-entry] %s.channel = " MCM_DTYPE_IUI_PF, path1, vap_v.channel);
if(mcm_lulib_set_entry(&self_lulib, path1, &vap_v, sizeof(vap_v)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_entry(%s) fail", path1);
goto FREE_02;
}
// 範例-04 : 增加 device.vap.#23.station.#1
path1 = "device.vap.#23.station.#1";
DMSG("[add-entry] %s", path1);
if(mcm_lulib_add_entry(&self_lulib, path1, NULL, NULL, 0) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_add_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_set_entry_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_set_entry_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
struct mcm_dv_device_t device_v;
struct mcm_dv_device_system_t system_v;
struct mcm_dv_device_vap_t vap_v;
struct mcm_dv_device_vap_station_t station_v;
MCM_DTYPE_USIZE_TD i;
srand(time(NULL));
// 範例-01 : 設定 device (SYS 模式)
path1 = "device";
memset(&device_v, 0, sizeof(device_v));
snprintf(device_v.descript, sizeof(device_v.descript), "network-device-%02u", rand() % 100);
for(i = 0; i < sizeof(device_v.serial_number); i++)
device_v.serial_number[i] = rand() % 256;
DMSG("[set-entry][SYS] %s.descript = " MCM_DTYPE_S_PF, path1, device_v.descript);
DMSG("[set-entry][SYS] %s.serial_number = "
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF
MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF MCM_DTYPE_B_PF,
path1,
device_v.serial_number[0], device_v.serial_number[1], device_v.serial_number[2],
device_v.serial_number[3], device_v.serial_number[4], device_v.serial_number[5],
device_v.serial_number[6], device_v.serial_number[7], device_v.serial_number[8],
device_v.serial_number[9]);
if(mcm_config_set_entry_by_path(this_session, path1, MCM_DACCESS_SYS, &device_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-02 : 設定 device.system (NEW 模式)
path1 = "device.system";
memset(&system_v, 0, sizeof(system_v));
snprintf(system_v.date, sizeof(system_v.date), "2008/01/%02u", rand() % 30);
snprintf(system_v.ip_addr, sizeof(system_v.ip_addr), "192.168.20.%u", rand() % 250);
system_v.uptime = rand();
system_v.loading = ((MCM_DTYPE_FD_TD) 25000) / ((rand() % 100) + 1);
DMSG("[set-entry][NEW] %s.date = " MCM_DTYPE_S_PF, path1, system_v.date);
DMSG("[set-entry][NEW] %s.ip_addr = " MCM_DTYPE_S_PF, path1, system_v.ip_addr);
DMSG("[set-entry][NEW] %s.uptime = " MCM_DTYPE_IULL_PF, path1, system_v.uptime);
DMSG("[set-entry][NEW] %s.loading = " MCM_DTYPE_FD_PF, path1, system_v.loading);
if(mcm_config_set_entry_by_path(this_session, path1, MCM_DACCESS_NEW, &system_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-03 : 設定 device.vap.@1 (NEW 模式)
path1 = "device.vap.@1";
memset(&vap_v, 0, sizeof(vap_v));
snprintf(vap_v.ssid, sizeof(vap_v.ssid), "ssid-%u", rand() % 100);
vap_v.channel = rand() % 200;
DMSG("[set-entry][NEW] %s.ssid = " MCM_DTYPE_S_PF, path1, vap_v.ssid);
DMSG("[set-entry][NEW] %s.channel = " MCM_DTYPE_IUI_PF, path1, vap_v.channel);
if(mcm_config_set_entry_by_path(this_session, path1, MCM_DACCESS_NEW, &vap_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-04 : 設定 device.vap.#23.station.#1 (NEW 模式)
path1 = "device.vap.#23.station.#1";
memset(&station_v, 0, sizeof(station_v));
snprintf(station_v.mac_addr, sizeof(station_v.mac_addr), "00:AA:CC:22:44:%02X", rand() % 255);
station_v.rule = rand() % 50;
DMSG("[set-entry][NEW] %s.mac_addr = " MCM_DTYPE_S_PF, path1, station_v.mac_addr);
DMSG("[set-entry][NEW] %s.rule = " MCM_DTYPE_RK_PF, path1, station_v.rule);
if(mcm_config_set_entry_by_path(this_session, path1, MCM_DACCESS_NEW, &station_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_set_entry_by_path(%s) fail", path1);
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_add_entry_by_path 增加一筆 entry.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-03 : 增加 device.vap.#200
path1 = "device.vap.#200";
DMSG("[add-entry] %s", path1);
if(mcm_lulib_add_entry(&self_lulib, path1, NULL, NULL, 0) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_add_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_add_entry_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_add_entry_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
struct mcm_dv_device_vap_station_t station_v;
struct mcm_dv_device_limit_t limit_v;
srand(time(NULL));
// 範例-01 : 增加 device.vap.#100, 插入到第 1 筆 entry 之前 (@1), (SYS 模式)
path1 = "device.vap.#100";
DMSG("[add-entry][SYS] %s", path1);
if(mcm_config_add_entry_by_path(this_session, path1, "@1", MCM_DACCESS_SYS, NULL)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-02 : 增加 device.vap.@1.station.#10, 放在串列尾端 (NULL), (SYS 模式)
path1 = "device.vap.@1.station.#10";
DMSG("[add-entry][SYS] %s", path1);
if(mcm_config_add_entry_by_path(this_session, path1, NULL, MCM_DACCESS_SYS, NULL)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-04 : 增加 device.vap.#200.station.#10, 放在串列尾端 (""), (NEW 模式)
path1 = "device.vap.#200.station.#10";
memset(&station_v, 0, sizeof(station_v));
snprintf(station_v.mac_addr, sizeof(station_v.mac_addr), "00:1a:2b:c3:4d:%02X", rand() % 255);
station_v.rule = rand() % 50;
DMSG("[add-entry][NEW] %s.mac_addr = " MCM_DTYPE_S_PF, path1, station_v.mac_addr);
DMSG("[add-entry][NEW] %s.rule = " MCM_DTYPE_RK_PF, path1, station_v.rule);
if(mcm_config_add_entry_by_path(this_session, path1, "", MCM_DACCESS_NEW, &station_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-05 : 增加 device.limit.#50, 插入到 key 為 6 的 entry 之前 (#6), (NEW 模式)
path1 = "device.limit.#50";
memset(&limit_v, 0, sizeof(limit_v));
snprintf(limit_v.name, sizeof(limit_v.name), "rule-%u", rand() % 100);
limit_v.priority = rand() % 100;
DMSG("[add-entry][NEW] %s.name = " MCM_DTYPE_S_PF, path1, limit_v.name);
DMSG("[add-entry][NEW] %s.priority = " MCM_DTYPE_ISI_PF, path1, limit_v.priority);
if(mcm_config_add_entry_by_path(this_session, path1, "#6", MCM_DACCESS_NEW, &limit_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_del_entry_by_path 刪除一筆 entry.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_del_entry_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_del_entry_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
srand(time(NULL));
// 範例-01 : 刪除 device.vap.@1 (SYS 模式)
path1 = "device.vap.@1";
DMSG("[del-entry][SYS] %s", path1);
if(mcm_config_del_entry_by_path(this_session, path1, MCM_DACCESS_SYS) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_del_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-02 : 刪除 device.vap.#15.station.#33 (NEW 模式)
path1 = "device.vap.#15.station.#33";
DMSG("[del-entry][NEW] %s", path1);
if(mcm_config_del_entry_by_path(this_session, path1, MCM_DACCESS_NEW) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_del_entry_by_path(%s) fail", path1);
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_get_all_key_by_path 讀出所有 entry 的 key 值.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_all_key_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_all_key_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1, path2[MCM_PATH_MAX_LENGTH], *source;
struct mcm_dv_device_vap_t vap_v;
struct mcm_dv_device_vap_station_t station_v;
MCM_DTYPE_EK_TD i, count, *key_array;
// 範例-01 : 取得 device.vap.* 的所有 key.
path1 = "device.vap.*";
if(mcm_config_get_all_key_by_path(this_session, path1, (MCM_DTYPE_EK_TD **) &key_array,
&count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 接著使用 key 值取得所有的 device.vap.*
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.vap.#%u", key_array[i]);
fret = mcm_config_get_entry_by_path(this_session, path2, MCM_DACCESS_AUTO, &vap_v);
if(fret < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_entry_by_path(%s) fail", path2);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.ssid = " MCM_DTYPE_S_PF " [%s]", path2, vap_v.ssid, source);
DMSG("[get-entry][AUTO] %s.channel = " MCM_DTYPE_IUI_PF " [%s]",
path2, vap_v.channel, source);
}
free(key_array);
// 範例-02 : 取得 device.vap.@1.station.* 所有的 key.
path1 = "device.vap.@1.station.*";
if(mcm_config_get_all_key_by_path(this_session, path1, (MCM_DTYPE_EK_TD **) &key_array,
&count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 接著使用 key 值取得所有的 device.vap.@1.station.*
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.vap.@1.station.#%u", key_array[i]);
if(mcm_config_get_entry_by_path(this_session, path2, MCM_DACCESS_AUTO, &station_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_entry_by_path(%s) fail", path2);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path2, station_v.ekey, source);
DMSG("[get-entry][AUTO] %s.mac_addr = " MCM_DTYPE_S_PF " [%s]",
path2, station_v.mac_addr, source);
DMSG("[get-entry][AUTO] %s.rule = " MCM_DTYPE_RK_PF " [%s]",
path2, station_v.rule, source);
}
free(key_array);
// 範例-03 : 取得 device.vap.#2.station.* 所有的 key.
path1 = "device.vap.#2.station.*";
if(mcm_config_get_all_key_by_path(this_session, path1, (MCM_DTYPE_EK_TD **) &key_array,
&count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_add_entry_by_path(%s) fail", path1);
goto FREE_01;
}
DMSG("[count] %s = " MCM_DTYPE_EK_PF, path1, count);
// 接著使用 key 值取得所有的 device.vap.@1.station.*
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.vap.#2.station.#%u", key_array[i]);
if(mcm_config_get_entry_by_path(this_session, path2, MCM_DACCESS_AUTO, &station_v)
< MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_entry_by_path(%s) fail", path2);
goto FREE_01;
}
source = fret == MCM_DACCESS_SYS ? "SYS" : "NEW";
DMSG("[get-entry][AUTO] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path2, station_v.ekey, source);
DMSG("[get-entry][AUTO] %s.mac_addr = " MCM_DTYPE_S_PF " [%s]",
path2, station_v.mac_addr, source);
DMSG("[get-entry][AUTO] %s.rule = " MCM_DTYPE_RK_PF " [%s]",
path2, station_v.rule, source);
}
free(key_array);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_get_all_entry_by_path 讀出所有 entry 的資料.
注意事項 :
範例-01 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
struct mcm_dv_device_vap_t vap_v;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-01 : 設定 device.vap.@1
path1 = "device.vap.@1";
memset(&vap_v, 0, sizeof(vap_v));
snprintf(vap_v.ssid, sizeof(vap_v.ssid), "ssid-%u", rand() % 100);
vap_v.channel = rand() % 150;
DMSG("[set-entry] %s.ssid = " MCM_DTYPE_S_PF, path1, vap_v.ssid);
DMSG("[set-entry] %s.channel = " MCM_DTYPE_IUI_PF, path1, vap_v.channel);
if(mcm_lulib_set_entry(&self_lulib, path1, &vap_v, sizeof(vap_v)) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_set_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_get_all_entry_value_test_01";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_all_entry_value_test_01(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1, path2[MCM_PATH_MAX_LENGTH], *source;
struct mcm_dv_device_vap_t *vap_v;
struct mcm_dv_device_vap_station_t *station_v;
MCM_DTYPE_FLAG_TD *from;
MCM_DTYPE_EK_TD i, count;
// 範例-01 : 取得 device.vap.* 的所有 entry 資料 (AUTO 模式).
path1 = "device.vap.*";
if(mcm_config_get_all_entry_by_path(this_session, path1, MCM_DACCESS_AUTO, (void **) &vap_v,
(MCM_DTYPE_FLAG_TD **) &from, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.vap.@%u", i + 1);
source = from[i] == MCM_DACCESS_NEW ? "NEW" : "SYS";
DMSG("[get-all-entry][AUTO] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path2, vap_v[i].ekey, source);
DMSG("[get-all-entry][AUTO] %s.ssid = " MCM_DTYPE_S_PF " [%s]",
path2, vap_v[i].ssid, source);
DMSG("[get-all-entry][AUTO] %s.channel = " MCM_DTYPE_IUI_PF " [%s]",
path2, vap_v[i].channel, source);
}
free(vap_v);
free(from);
// 範例-02 : 取得 device.vap.#15.station.* 的所有 entry 資料 (SYS 模式).
path1 = "device.vap.#15.station.*";
if(mcm_config_get_all_entry_by_path(this_session, path1, MCM_DACCESS_SYS,
(void **) &station_v, (MCM_DTYPE_FLAG_TD **) &from,
&count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.vap.#15.station.@%u", i + 1);
source = from[i] == MCM_DACCESS_NEW ? "NWE" : "SYS";
DMSG("[get-all-entry][SYS ] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path1, station_v[i].ekey, source);
DMSG("[get-all-entry][SYS ] %s.mac_addr = " MCM_DTYPE_S_PF " [%s]",
path1, station_v[i].mac_addr, source);
DMSG("[get-all-entry][SYS ] %s.rule = " MCM_DTYPE_RK_PF " [%s]",
path1, station_v[i].rule, source);
}
free(station_v);
free(from);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
範例-02 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 範例-01 : 增加 device.limit.#65
path1 = "device.limit.#65";
DMSG("[add-entry] %s", path1);
if(mcm_lulib_add_entry(&self_lulib, path1, NULL, NULL, 0) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_add_entry(%s) fail", path1);
goto FREE_02;
}
// 呼叫內部模組.
path1 = "mcm_module_get_all_entry_value_test_02";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_all_entry_value_test_02(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1, path2[MCM_PATH_MAX_LENGTH], *source;
struct mcm_dv_device_limit_t *limit_v;
MCM_DTYPE_FLAG_TD *from;
MCM_DTYPE_EK_TD i, count;
// 範例-01 : 取得 device.limit.* 的所有 entry 資料 (SYS 模式).
// 因為最後一筆 device.limit 是新加入的, 系統資料區並沒有資料所以會找不到,
// 而只要有一筆資料不符合 (使用 SYS 模式但是系統資料區沒有資料) 就會回傳錯誤.
path1 = "device.limit.*";
if(mcm_config_get_all_entry_by_path(this_session, path1, MCM_DACCESS_SYS, (void **) &limit_v,
(MCM_DTYPE_FLAG_TD **) &from, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.limit.@%u", i + 1);
source = from[i] == MCM_DACCESS_NEW ? "NEW" : "SYS";
DMSG("[get-all-entry][SYS ] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path2, limit_v[i].ekey, source);
DMSG("[get-all-entry][SYS ] %s.name = " MCM_DTYPE_S_PF " [%s]",
path2, limit_v[i].name, source);
DMSG("[get-all-entry][SYS ] %s.priority = " MCM_DTYPE_ISI_PF " [%s]",
path2, limit_v[i].priority, source);
}
free(limit_v);
free(from);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
範例-03 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RO;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_all_entry_value_test_03";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_all_entry_value_test_03(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1, path2[MCM_PATH_MAX_LENGTH], *source;
struct mcm_dv_device_limit_t *limit_v;
MCM_DTYPE_FLAG_TD *from;
MCM_DTYPE_EK_TD i, count;
// 範例-01 : 取得 device.limit.* 的所有 entry 資料 (NEW 模式).
// 因為外部程式沒有做修改 (設定/增加/刪除) 的動作, 所以新進資料區沒有資料,
// 而只要有一筆資料不符合 (使用 NEW 模式但是新進資料區沒有資料) 就會回傳錯誤.
path1 = "device.limit.*";
if(mcm_config_get_all_entry_by_path(this_session, path1, MCM_DACCESS_NEW, (void **) &limit_v,
(MCM_DTYPE_FLAG_TD **) &from, &count) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
for(i = 0; i < count; i++)
{
snprintf(path2, sizeof(path2), "device.limit.@%u", i + 1);
source = from[i] == MCM_DACCESS_NEW ? "NEW" : "SYS";
DMSG("[get-all-entry][SYS ] %s.ekey = " MCM_DTYPE_EK_PF " [%s]",
path2, limit_v[i].ekey, source);
DMSG("[get-all-entry][SYS ] %s.name = " MCM_DTYPE_S_PF " [%s]",
path2, limit_v[i].name, source);
DMSG("[get-all-entry][SYS ] %s.priority = " MCM_DTYPE_ISI_PF " [%s]",
path2, limit_v[i].priority, source);
}
free(limit_v);
free(from);
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_del_all_entry_by_path 刪除所有 entry.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RW;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_del_all_entry_value_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_del_all_entry_value_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
srand(time(NULL));
// 範例-01 : 刪除 device.vap.@1.* (SYS 模式)
path1 = "device.vap.@1.station.*";
DMSG("[del-all-entry][SYS] %s", path1);
if(mcm_config_del_all_entry_by_path(this_session, path1, MCM_DACCESS_SYS) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_del_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-02 : 刪除 device.vap.#15.* (NEW 模式)
path1 = "device.vap.#15.station.*";
DMSG("[del-all-entry][NEW] %s", path1);
if(mcm_config_del_all_entry_by_path(this_session, path1, MCM_DACCESS_NEW) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_del_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
// 範例-03 : 刪除 device.limit.* (NEW 模式)
path1 = "device.limit.*";
DMSG("[del-all-entry][NEW] %s", path1);
if(mcm_config_del_all_entry_by_path(this_session, path1, MCM_DACCESS_NEW) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_del_all_entry_by_path(%s) fail", path1);
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_get_usable_key_by_path 取得可用的 key.
注意事項 :
範例 :
外部程式部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "mcm_lib/mcm_lulib/mcm_lulib_api.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int main(
int argc,
char **argv)
{
char *path1;
struct mcm_lulib_lib_t self_lulib;
srand(time(NULL));
self_lulib.socket_path = "@mintcm";
self_lulib.call_from = MCM_CFROM_USER;
self_lulib.session_permission = MCM_SPERMISSION_RO;
self_lulib.session_stack_size = 0;
if(mcm_lulib_init(&self_lulib) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_init() fail");
goto FREE_01;
}
// 呼叫內部模組.
path1 = "mcm_module_get_usable_key_test";
DMSG("[run] %s", path1);
if(mcm_lulib_run(&self_lulib, path1, NULL, 0, NULL, NULL) < MCM_RCODE_PASS)
{
DMSG("call mcm_lulib_run(%s) fail", path1);
goto FREE_02;
}
FREE_02:
mcm_lulib_exit(&self_lulib);
FREE_01:
return 0;
}
內部模組部分
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mcm_lib/mcm_lheader/mcm_type.h"
#include "mcm_lib/mcm_lheader/mcm_size.h"
#include "mcm_lib/mcm_lheader/mcm_control.h"
#include "mcm_lib/mcm_lheader/mcm_connect.h"
#include "mcm_lib/mcm_lheader/mcm_return.h"
#include "mcm_lib/mcm_lheader/mcm_debug.h"
#include "mcm_lib/mcm_lheader/mcm_data_exinfo_auto.h"
#include "../mcm_service_handle_define.h"
#include "../mcm_config_handle_extern.h"
#define DMSG(msg_fmt, msgs...) printf("%s(%04u): " msg_fmt "\n", __FILE__, __LINE__, ##msgs)
int mcm_module_get_usable_key_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
char *path1;
MCM_DTYPE_EK_TD key;
// 範例-01 : 取得 device.vap.* 可用的 key
path1 = "device.vap.*";
if(mcm_config_get_usable_key_by_path(this_session, path1, &key) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_usable_key_by_path(%s) fail", path1);
goto FREE_01;
}
if(key == 0)
{
DMSG("[usable-key] %s = entry is full", path1, key);
}
else
{
DMSG("[usable-key] %s = " MCM_DTYPE_EK_PF, path1, key);
}
// 範例-02 : 取得 device.vap.#15.station.* 可用的 key
path1 = "device.vap.#15.station.*";
if(mcm_config_get_usable_key_by_path(this_session, path1, &key) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_get_usable_key_by_path(%s) fail", path1);
goto FREE_01;
}
if(key == 0)
{
DMSG("[usable-key] %s = entry is full", path1, key);
}
else
{
DMSG("[usable-key] %s = " MCM_DTYPE_EK_PF, path1, key);
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
| 01. | 範例程式目錄在 mint_cm/usage/example/0403. |
| 02. | 下面關於 make 的操作沒有特別註明的話都是在 mint_cm 目錄. |
| 03. | 第一次使用, 使用 make example_add KEY=0403 載入範例並編譯. |
| 04. |
web_app 是範例程式. 範例項目 :
|
| 05. | 先執行 mcm_daemon 和 mini_httpd 才可測試. |
| 06. | 瀏覽器連至 http://<server-address>/web_app_0403_index.html 就可以看到範例頁面. |
| 07. | 測試完畢不使用後, 使用 make example_del KEY=0403 將範例移除. |
| 08. |
範例程式目錄下的檔案在做完 make example_add
後會複製到真正使用的位置, 要修改做測試的話要改在複製後的.
|