|
mcm_config_save 要求 mcm_daemon 儲存資料到資料現在值檔案.
注意事項 :
範例 :
外部程式部分
#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_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_save_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_save_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
MCM_DTYPE_BOOL_TD force_save = 1;
DMSG("[save] %s", force_save == 0 ? "check" : "force");
if(mcm_config_save(this_session, MCM_DUPDATE_SYNC, 0, force_save) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_save() fail");
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_shutdown 關閉 mcm_daemon, 當系統需要關機或重開機時先讓 mcm_daemon 正常關閉.
注意事項 :
範例 :
外部程式部分
#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_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_shutdown_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_shutdown_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
DMSG("[shutdown]");
if(mcm_config_shutdown(this_session) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_shutdown() fail");
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
mcm_config_remove_store_current_profile 如果需要做還原到預設值操作, 方法是先移除資料現在值檔案, 之後重新啟動 mcm_daemon, mcm_daemon 發現資料現在值檔案不存在就會讀取資料預設值檔案. 使用此函式移除移除資料現在值檔案.
注意事項 :
範例 :
外部程式部分
#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_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_remove_store_current_profile_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_remove_store_current_profile_test(
struct mcm_service_session_t *this_session)
{
int fret = MCM_RCODE_MODULE_INTERNAL_ERROR;
DMSG("[remove_store_current_profile]");
if(mcm_config_remove_store_current_profile(this_session) < MCM_RCODE_PASS)
{
DMSG("call mcm_config_remove_store_current_profile() fail");
goto FREE_01;
}
fret = MCM_RCODE_PASS;
FREE_01:
return fret;
}
|
|
MCM_STORE_SAVE_MODE (mint_cm/mcm_lib/mcm_lheader/mcm_control.h) |
|
| MCM_SSAVE_AUTO | 自動儲存 |
| MCM_SSAVE_MANUAL | 手動儲存 |
|
在網頁端使用 mcm_jslib_obtain_config() 的注意事項
CGI 端在處理 [get] 時, 會檢查 [get] 之前是否有做資料設定 (也就是 [set] [add] [del] [delall] [run]), 有的話會先進行資料同步的處理 (mcm_lulib_update()), 之後才處理 [get]. 資料被同步後, 所有的資料狀態都會清除, 再使用 [run] 執行內部模組時會抓不到資料狀態. 所以如果在指令序列中 [run] 在 [get] 之後, 執行內部模組時會抓不到資料狀態. 範例 :
req_cmd = "&set.device.system.ip_addr=192.168.0.1" +
"&add.device.vap.#30=" +
"&run.module1" +
"&get.device.system" +
"&get.device.vap.*" +
"&run.module2" +
"&get.device.client.*";
CGI 處理流程 :
01. 處理 [set.device.system.ip_addr=192.168.0.1].
02. 處理 [add.device.vap.#30].
03. 處理 [run.module1], 這時資料還沒被同步, 內部模組抓的到在 [01] [02] 的資料狀態.
04. 處理 [get.device.system], 發現在 [01] [02] [03] 有修改資料, 先做資料同步在抓資料.
05. 處理 [get.device.vap.*], 在 [04] 做過資料同步, 不需要再同步直接抓資料.
06. 處理 [run.module2], 在 [04] 做過資料同步, 內部模組抓不到在 [01] [02] 的資料狀態.
07. 處理 [get.device.client.*], 發現在 [06] 有修改資料, 先做資料同步在抓資料.
|