瀏覽代碼

!1 终端快速启动支持
(1)合并模块初始化过程
(2)优化框架启动添加防火墙过程

80374463 6 年之前
父節點
當前提交
07fe4799d9
共有 8 個文件被更改,包括 182 次插入52 次删除
  1. 2 0
      spbase/SpBase.vcxproj
  2. 44 0
      spbase/sp_exlock.cpp
  3. 6 0
      spbase/sp_exlock.h
  4. 1 1
      spbase/sp_iom.c
  5. 44 43
      spbase/sp_mod.c
  6. 22 8
      spshell/spshell.cpp
  7. 61 0
      spshell/svc.cpp
  8. 2 0
      spshell/svc.h

+ 2 - 0
spbase/SpBase.vcxproj

@@ -135,6 +135,7 @@
     <ClCompile Include="sp_dbg.cpp" />
     <ClCompile Include="sp_dir.c" />
     <ClCompile Include="sp_env.c" />
+    <ClCompile Include="sp_exlock.cpp" />
     <ClCompile Include="sp_groupProcess.cpp" />
     <ClCompile Include="sp_gui.cpp" />
     <ClCompile Include="sp_hcc.c" />
@@ -197,6 +198,7 @@
     <ClInclude Include="sp_def.h" />
     <ClInclude Include="sp_dir.h" />
     <ClInclude Include="sp_env.h" />
+    <ClInclude Include="sp_exlock.h" />
     <ClInclude Include="sp_groupProcess.h" />
     <ClInclude Include="sp_gui.h" />
     <ClInclude Include="sp_hcc.h" />

+ 44 - 0
spbase/sp_exlock.cpp

@@ -0,0 +1,44 @@
+#include "sp_exlock.h"
+#include<iostream>
+#include<memory>
+#include<map>
+#include<windows.h>
+using namespace std;
+
+map<int, CRITICAL_SECTION*> g_modLockArr;
+
+void sp_mod_mgr_lockEx(int EntityId)
+{
+	auto lock = g_modLockArr.find(EntityId);
+	if (lock != g_modLockArr.end())
+	{
+		//can find it
+		EnterCriticalSection(lock->second);
+	}
+	else
+	{
+		CRITICAL_SECTION* cs = new CRITICAL_SECTION();
+		InitializeCriticalSection(cs);
+		EnterCriticalSection(cs);
+		g_modLockArr.insert(std::make_pair(EntityId, cs));
+	}
+}
+
+void sp_mod_mgr_unlockEx(int EntityId)
+{
+	auto lock = g_modLockArr.find(EntityId);
+	if (lock != g_modLockArr.end())
+		LeaveCriticalSection(lock->second);
+}
+
+void sp_mod_mgr_lockArrClean()
+{
+	for each (auto it in g_modLockArr)
+	{
+		DeleteCriticalSection(it.second);
+		delete it.second;
+		it.second = NULL;
+	}
+
+	g_modLockArr.clear();
+}

+ 6 - 0
spbase/sp_exlock.h

@@ -0,0 +1,6 @@
+#pragma once
+
+
+extern "C" void sp_mod_mgr_lockEx(int EntityId);
+extern "C" void sp_mod_mgr_unlockEx(int EntityId);
+extern "C" void sp_mod_mgr_lockArrClean();

+ 1 - 1
spbase/sp_iom.c

@@ -190,7 +190,7 @@ static void on_msg(bus_endpt_t *endpt, int msg, int nparam, int params[], int *r
 			bus_endpt_send_info(endpt, epid, pkt_type, pkt);
 			iobuffer_dec_ref(pkt);
 		}
-		sp_dbg_debug("on_msg send_info end, %d, %d, %d, %d", this_svc_id, epid, svc_id, pkt_id);
+		//sp_dbg_debug("on_msg send_info end, %d, %d, %d, %d", this_svc_id, epid, svc_id, pkt_id);
 	} else if (msg == IOM_T_GET_STATE) {
 		int epid = params[0];
 		int *state = (int*)params[1];

+ 44 - 43
spbase/sp_mod.c

@@ -56,6 +56,10 @@
 #define PROCESS_EXIT_TIMEOUT	4000
 #define ENTITY_TEST_TIMEOUT 30000
 
+extern  void sp_mod_mgr_lockEx(int EntityId);
+extern  void sp_mod_mgr_unlockEx(int EntityId);
+extern  void sp_mod_mgr_lockArrClean();
+
 struct sp_mod_stub_t
 {
 	sp_mod_stub_cb cb;
@@ -765,7 +769,6 @@ static HANDLE create_module_process(const char *mod_name, int epid, int range, i
 			}
 
 			WaitForSingleObject(hMutex, 5000);
-			Sleep(100);
 			CloseHandle(hMutex);
 			
 
@@ -922,12 +925,10 @@ static int on_detect_process_end(process_monitor_t *monitor, HANDLE hproc, void
 	sp_mod_mgr_t *mgr = (sp_mod_mgr_t*)user_data;
 	sp_mod_t *mod;
 
-	sp_mod_mgr_lock(mgr);
 	list_for_each_entry(mod, &mgr->mod_list, sp_mod_t, entry) {
 		if (mod->state && mod->process_handle == hproc) {
 			sp_entity_t *ent;
-// 			DWORD dwExitCode = -1;
-// 			GetExitCodeProcess(hproc, &dwExitCode);
+			sp_mod_mgr_lockEx(mod->cfg->idx);
 			sp_dbg_info("detect process [mod=%s] exit", mod->cfg->name);	//no exit code
 			CloseHandle(mod->process_handle);
 			mod->process_handle = NULL;
@@ -942,10 +943,10 @@ static int on_detect_process_end(process_monitor_t *monitor, HANDLE hproc, void
 				}
 			}
 			SetEvent(mod->evt_app_exit);
+			sp_mod_mgr_unlockEx(mod->cfg->idx);
 			break;
 		}
 	}
-	sp_mod_mgr_unlock(mgr);
 
 	return TRUE; // delete process handle
 }
@@ -1128,7 +1129,7 @@ static int mgr_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int pkt_
 			sp_entity_t *ent = sp_mod_mgr_find_entity_by_idx(mgr, svc_id);
 			int state = pkt_id;
 			if ((ent->state == EntityState_Idle || ent->state == EntityState_Busy) && state != ent->state) {
-				sp_mod_mgr_lock(mgr);
+				sp_mod_mgr_lockEx(ent->cfg->idx);
 				if (ent->state == EntityState_Idle || ent->state == EntityState_Busy) {
 					if (ent->state != state) {
 						int old_state = ent->state;
@@ -1136,7 +1137,7 @@ static int mgr_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int pkt_
 						mgr_on_entity_state(mgr, ent, ent->cfg->idx, old_state, state);
 					}
 				}
-				sp_mod_mgr_unlock(mgr);
+				sp_mod_mgr_unlockEx(ent->cfg->idx);
 			}
 		} else if (cmd_type == MOD_CMD_SUBSCRIBE_STATE_LISTENER) {
 			subscribe_entity_state(mgr, epid, svc_id, pkt_id);
@@ -1371,13 +1372,13 @@ void sp_mod_mgr_bind_bcm_daemon(sp_mod_mgr_t *mgr, sp_bcm_daemon_t *daemon)
 void sp_mod_mgr_lock(sp_mod_mgr_t *mgr)
 {
 	EnterCriticalSection(&mgr->lock);
-	//sp_dbg_debug("lock mgr %d", GetCurrentThreadId());
+	//sp_dbg_info("lock mgr %d, lock %d",mgr, &(mgr->lock));
 }
 
 void sp_mod_mgr_unlock(sp_mod_mgr_t *mgr)
 {
 	LeaveCriticalSection(&mgr->lock);
-	//sp_dbg_debug("unlock mgr %d", GetCurrentThreadId());
+	//sp_dbg_info("unlock mgr %d, lock %d", mgr, &(mgr->lock));
 }
 
 sp_mod_t *sp_mod_mgr_find_module_by_name(sp_mod_mgr_t *mgr, const char *mod_name)
@@ -1513,20 +1514,20 @@ int sp_mod_mgr_get_entity_array_nelts(sp_mod_mgr_t *mgr)
 static int try_lock_doing(sp_mod_mgr_t *mgr, sp_mod_t *mod)
 {
 	int ok = FALSE;
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (!mod->doing) {
 		mod->doing = 1;
 		ok = TRUE;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 	return ok;
 }
 
 static void unlock_doing(sp_mod_mgr_t *mgr, sp_mod_t *mod)
 {
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	mod->doing = 0;
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 }
 
 static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
@@ -1536,7 +1537,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
 
 	sp_dbg_debug("begin load module %s", mod->cfg->name);
 
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (!mod->state) {
 		ResetEvent(mod->evt_app_exit);
 		mod->process_handle = create_module_process(mod->cfg->name, mod->cfg->idx, env->shm_range, &mod->process_id, mod->cfg->group);
@@ -1547,7 +1548,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
 	} else {
 		rc = Error_Duplication;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		const int interval = 50;
@@ -1602,7 +1603,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
 		}
 	}
 
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (rc == 0) {
 		mod->state = SP_MODULE_STATE_LOAD;
 		mod->start_time = y2k_time_now();
@@ -1617,7 +1618,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
 		mod->process_id = 0;
 		sp_dbg_info("load module failed!");
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	return rc;
 }
@@ -1627,7 +1628,7 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
 	int rc = 0;
 	sp_entity_t *pos;
 
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		list_for_each_entry(pos, &mod->entity_list, sp_entity_t, entry) {
 			if (pos->state != EntityState_Killed && 
@@ -1648,7 +1649,7 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
 		sp_dbg_debug("module %s already unloaded!", mod->cfg->name);
 		rc = Error_NotInit;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		int removed = 0;
@@ -1703,12 +1704,12 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
 			}
 		}
 
-		sp_mod_mgr_lock(mgr);
+		sp_mod_mgr_lockEx(mod->cfg->idx);
 		if (removed) {
 			mod->state = SP_MODULE_STATE_UNLOAD;
 			SetEvent(mod->evt_app_exit);
 		}
-		sp_mod_mgr_unlock(mgr);
+		sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	}
 
@@ -1737,7 +1738,7 @@ static int terminate_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity
 	int rc = 0;
 	sp_entity_t *pos;
 
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (mod->process_handle) {
 			if (process_monitor_remove(mgr->process_monitor, mod->process_handle) == 0) {
@@ -1782,7 +1783,7 @@ static int terminate_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity
 			}
 		}
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	return rc;
 }
@@ -1794,7 +1795,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
 
 	sp_dbg_debug("begin start entity %s", ent->cfg->name);
 	
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (ent->state == EntityState_NoStart || ent->state == EntityState_Killed || ent->state == EntityState_Close) {
 			iobuffer_t *pkt = iobuffer_create(-1, -1);
@@ -1825,7 +1826,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
 		sp_dbg_debug("entity's %s 's module is not load or is pending!", ent->cfg->name);
 		rc = Error_Pending;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		int last_state = ent->state;
@@ -1842,7 +1843,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
 			rc = Error_TimeOut;
 		}
 
-		sp_mod_mgr_lock(mgr);
+		sp_mod_mgr_lockEx(mod->cfg->idx);
 		if (rc == 0) {
 			ent->state = EntityState_Idle;
 			ent->state_start_time = y2k_time_now();
@@ -1853,7 +1854,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
 			mgr_on_entity_exception(mgr, ent, trigger_entity_id, Error_Exception);
 		}
 		mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
-		sp_mod_mgr_unlock(mgr);
+		sp_mod_mgr_unlockEx(mod->cfg->idx);
 	}
 
 	return rc;
@@ -1864,7 +1865,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
 	int rc = 0;
 	sp_mod_t *mod = ent->mod;
 
-	sp_mod_mgr_lock(mgr);
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (ent->state == EntityState_Busy || ent->state == EntityState_Idle || ent->state == EntityState_Pause) {
 			iobuffer_t *body = iobuffer_create(-1, -1);
@@ -1891,7 +1892,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
 		sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
 		rc = Error_Pending;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		int last_state = ent->state;
@@ -1908,7 +1909,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
 			rc = Error_TimeOut;
 		}
 
-		sp_mod_mgr_lock(mgr);
+		sp_mod_mgr_lockEx(mod->cfg->idx);
 		if (rc == 0) {
 			ent->state = EntityState_Close;
 			ent->state_start_time = y2k_time_now();
@@ -1919,7 +1920,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
 			mgr_on_entity_exception(mgr, ent, trigger_entity_id, Error_Exception);
 		}
 		mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
-		sp_mod_mgr_unlock(mgr);
+		sp_mod_mgr_unlockEx(mod->cfg->idx);
 	}
 
 	return rc;
@@ -1930,8 +1931,8 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
 	int rc = 0;
 	sp_mod_t *mod;
 
-	sp_mod_mgr_lock(mgr);
 	mod = ent->mod;
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (ent->state == EntityState_Busy || ent->state == EntityState_Idle) {
 			iobuffer_t *body = iobuffer_create(-1, -1);
@@ -1953,7 +1954,7 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
 		sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
 		rc = Error_Unexpect;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
@@ -1969,14 +1970,14 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
 			rc = Error_TimeOut;
 		}
 
-		sp_mod_mgr_lock(mgr);
+		sp_mod_mgr_lockEx(mod->cfg->idx);
 		if (rc == 0) {
 			int last_state = ent->state;
 			ent->state = EntityState_Pause;
 			ent->state_start_time = y2k_time_now();
 			mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
 		}
-		sp_mod_mgr_unlock(mgr);
+		sp_mod_mgr_unlockEx(mod->cfg->idx);
 	}
 
 	return rc;
@@ -1987,8 +1988,8 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
 	int rc = 0;
 	sp_mod_t*mod;
 
-	sp_mod_mgr_lock(mgr);
 	mod = ent->mod;
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (ent->state == EntityState_Pause) {
 			iobuffer_t *body = iobuffer_create(-1, -1);
@@ -2010,7 +2011,7 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
 		sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
 		rc = Error_Unexpect;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
@@ -2026,13 +2027,13 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
 			rc = Error_TimeOut;
 		}
 
-		sp_mod_mgr_lock(mgr);
+		sp_mod_mgr_lockEx(mod->cfg->idx);
 		if (rc == 0) {
 			ent->state = EntityState_Idle;
 			ent->state_start_time = y2k_time_now();
 			mgr_on_entity_state(mgr, ent, trigger_entity_id, EntityState_Pause, ent->state);
 		}
-		sp_mod_mgr_unlock(mgr);
+		sp_mod_mgr_unlockEx(mod->cfg->idx);
 	}
 
 	return rc;
@@ -2043,8 +2044,8 @@ static int test_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int test_type, int t
 	int rc = 0;
 	sp_mod_t *mod;
 
-	sp_mod_mgr_lock(mgr);
 	mod = ent->mod;
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		if (ent->state == EntityState_Idle || ent->state == EntityState_Busy || ent->state == EntityState_Pause) {
 			iobuffer_t *body = iobuffer_create(-1, -1);
@@ -2067,7 +2068,7 @@ static int test_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int test_type, int t
 		sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
 		rc = Error_Unexpect;
 	}
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 
 	if (rc == 0) {
 		HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
@@ -2149,8 +2150,8 @@ int sp_mod_mgr_lost_entity(sp_mod_mgr_t *mgr, int entity_id, int trigger_entity_
 	if (!ent)
 		return Error_NotExist;
 
-	sp_mod_mgr_lock(mgr);
 	mod = ent->mod;
+	sp_mod_mgr_lockEx(mod->cfg->idx);
 	if (mod->state) {
 		int last_state = ent->state;
 		sp_dbg_debug("set entity %s lost ok!", ent->cfg->name);
@@ -2159,7 +2160,7 @@ int sp_mod_mgr_lost_entity(sp_mod_mgr_t *mgr, int entity_id, int trigger_entity_
 		mgr_on_entity_state(mgr, ent, ent->cfg->idx, last_state, ent->state);
 	}
 
-	sp_mod_mgr_unlock(mgr);
+	sp_mod_mgr_unlockEx(mod->cfg->idx);
 	return Error_Succeed;
 }
 

+ 22 - 8
spshell/spshell.cpp

@@ -216,6 +216,8 @@ static bool AddRegIntValue(HKEY hKey, const char *szSubKey, const char *szKeyNam
 }
 
 
+
+
 static bool AddFirewallRules()
 {
 	char szBinDir[MAX_PATH] = {};
@@ -240,6 +242,25 @@ static bool AddFirewallRules()
 	return nRet > 32;
 }
 
+int AddFireAddFirewallRulesThread(void* param)
+{
+	if (!AddFirewallRules())
+	{
+		sp_dbg_fatal("譜崔Windows契諮能貨待払移!!!");
+		Sleep(10000);
+		return -1;
+	}
+	else
+		sp_dbg_info("譜崔Windows契諮能貨待撹孔!!!");
+
+	return 0;
+}
+
+static void AddFirewallRulesEx()
+{
+	CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& AddFireAddFirewallRulesThread, NULL, 0, NULL));
+}
+
 static bool DisableWindowsCharmBar(bool bX64)
 {
 	if (!bX64)
@@ -749,14 +770,7 @@ int main(int argc, char **argv)
 	}*/
 
 	// 譜崔契諮能廣過燕塘崔
-	if (!AddFirewallRules())
-	{
-		sp_dbg_fatal("譜崔Windows契諮能貨待払移!!!");
-		Sleep(10000);
-		return -101;
-	}
-	else
-		sp_dbg_info("譜崔Windows契諮能貨待撹孔!!!");
+	AddFirewallRulesEx();
 
 	// 徭強咨茄彜蓑生
 	//AutoHideTaskBar(true);

+ 61 - 0
spshell/svc.cpp

@@ -14,6 +14,7 @@
 #include "sp_def.h"
 #include "sp_cfg.h"
 #include "sp_rpc.h"
+#include <memory>
 
 void on_bluesceen_display(sp_rpc_server_t *server, int epid, int svc_id, int call_type, iobuffer_t **info_pkt)
 {
@@ -222,6 +223,53 @@ void on_output_console_off(sp_rpc_server_t *server, int epid, int svc_id, int ca
 	sp_gui_undisplay(app->bsc_gui);
 }
 
+typedef struct
+{
+	sp_rpc_server_t* server;
+	int epid;
+	int rpc_id;
+	int svc_id;
+	int Entity_id;
+	char cmdline[1024];
+}EntityStartParam;
+
+static unsigned int __stdcall on_entity_startThread(void* param)
+{
+	EntityStartParam *dst = (EntityStartParam*)param;
+	auto ans_pkt = on_entity_start(dst->svc_id, dst->Entity_id, dst->cmdline);
+
+	//×Ô¼º·¢ËÍ
+	if (ans_pkt) {
+		int rc = sp_rpc_server_send_answer(dst->server, dst->epid, dst->svc_id, dst->rpc_id, &ans_pkt); 
+		if (rc != 0)
+			sp_dbg_warn("send answer failed!");
+		if (ans_pkt)
+				iobuffer_dec_ref(ans_pkt);
+	}  
+	//delete dst;
+	return 0;
+}
+
+iobuffer_t* on_entity_startEx(sp_rpc_server_t* server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t** req_pkt)
+{
+	int entity_id;
+	char* cmdline = NULL;
+	iobuffer_read(*req_pkt, IOBUF_T_I4, &entity_id, NULL);
+	sp_dbg_debug("handle start entityEx req: %d", entity_id);
+	iobuffer_format_read(*req_pkt, "s", &cmdline);
+
+	EntityStartParam *param = new EntityStartParam();
+	param->server = server;
+	param->epid = epid;
+	param->rpc_id = rpc_id;
+	param->svc_id = svc_id;
+	param->Entity_id = entity_id;
+	sprintf(param->cmdline, "%s", cmdline);
+	toolkit_free(cmdline);
+	CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&on_entity_startThread, param, 0, NULL));
+	return NULL;
+}
+
 iobuffer_t *on_entity_start(sp_rpc_server_t *server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t **req_pkt)
 {
 	sp_env_t *env = sp_get_env();
@@ -229,6 +277,7 @@ iobuffer_t *on_entity_start(sp_rpc_server_t *server, int epid, int svc_id, int r
 	int result;
 	char *cmdline = NULL;
 	iobuffer_t *ans_pkt = NULL;
+
 	iobuffer_read(*req_pkt, IOBUF_T_I4, &entity_id, NULL);
 	sp_dbg_debug("handle start entity req: %d", entity_id);
 
@@ -240,6 +289,18 @@ iobuffer_t *on_entity_start(sp_rpc_server_t *server, int epid, int svc_id, int r
 	return ans_pkt;
 }
 
+iobuffer_t* on_entity_start(int svc_id, int entity_id, const char* cmdline)
+{
+	sp_env_t* env = sp_get_env();
+	int result;
+	iobuffer_t* ans_pkt = NULL;
+
+	result = sp_mod_mgr_start_entity(env->mod_mgr, entity_id, cmdline, svc_id);
+	ans_pkt = iobuffer_create(-1, -1);
+	iobuffer_write(ans_pkt, IOBUF_T_I4, &result, 0);
+	return ans_pkt;
+}
+
 iobuffer_t *on_entity_stop(sp_rpc_server_t *server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t **req_pkt)
 {
 	sp_env_t *env = sp_get_env();

+ 2 - 0
spshell/svc.h

@@ -71,6 +71,8 @@ void on_output_console_off(sp_rpc_server_t *server, int epid, int svc_id, int ca
 //
 // req handlers
 //
+iobuffer_t* on_entity_start(int svc_id, int entity_id, const char* cmdline);
+iobuffer_t* on_entity_startEx(sp_rpc_server_t* server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t** req_pkt);
 iobuffer_t *on_entity_start(sp_rpc_server_t *server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t **req_pkt);
 iobuffer_t *on_entity_stop(sp_rpc_server_t *server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t **req_pkt);
 iobuffer_t *on_entity_continue(sp_rpc_server_t *server, int epid, int svc_id, int rpc_id, int call_type, iobuffer_t **req_pkt);