bool STT_Basic_Moudle::finish(int test_id) const
{
std::string error_str;
CMU_INFO ci = CMU_Table[test_id];
if( ci.anonymous_commu != NULL )
{
ci.anonymous_commu->fnClose(error_str);
}
std::map<std::string, CCommunication*>::iterator it = ci.name_commu.begin();
while(it != ci.name_commu.end())
{
it->second->fnClose(error_str);
it++;
}
ci.name_commu.clear();
return true;
}
std::string STT_Basic_Moudle::get_moudle_version() const
{
return std::string("Version: V1.0.0 \r\n" ) + STT_BUILD_TIME ;
}
std::string STT_Basic_Moudle::get_moudle_describe() const
{
return "基本功能模块";
}
void STT_Basic_Moudle::reg_ui_fun(REG_UI_FUN reg_ui_f) const
{
}
void STT_Basic_Moudle::reg_fun(int test_id,QScriptEngine *eng) const
{
CMU * cmu = new CMU();
QScriptValue qcmu = eng->newQObject(cmu);
eng->globalObject().setProperty(this->get_moudle_name().c_str(), qcmu);
add_fun(this->get_moudle_name().c_str(), "connect", D_CONNECT );
add_fun(this->get_moudle_name().c_str(), "close", D_CLOSE );
add_fun( this->get_moudle_name().c_str(), "send", D_SEND );
add_fun(this->get_moudle_name().c_str(), "receive", D_RECEIVE );
add_fun(this->get_moudle_name().c_str(), "ping", D_PING );
add_fun(this->get_moudle_name().c_str(), "sleep", D_SLEEP );
add_fun( this->get_moudle_name().c_str(), "find", D_FIND );
add_fun(this->get_moudle_name().c_str(), "loopchk", D_LOOPCHK );
add_fun( this->get_moudle_name().c_str(), "check", D_CHECK );
add_fun( this->get_moudle_name().c_str(), "set", D_SET );
add_fun(this->get_moudle_name().c_str(), "stringAdd", D_STRINGADD );
add_fun( this->get_moudle_name().c_str(), "compare", D_COMPARE );
add_fun( this->get_moudle_name().c_str(), "add", D_ADD );
add_fun(this->get_moudle_name().c_str(), "loopfind", D_LOOPFIND );
add_fun( this->get_moudle_name().c_str(), "change", D_CHANGE );
}
string STT_Basic_Moudle::get_moudle_name() const
{
return "STT_Basic_Moudle";
}
string get_stt_variable(int test_id, string key)
{
return (*STT_Basic_Moudle::STT_G_Test_Info)[test_id].variable_map[key];
}
void set_stt_variable(int test_id, string key, string value)
{
(*STT_Basic_Moudle::STT_G_Test_Info)[test_id].variable_map.insert(std::pair<std::string,std::string>(key,value));
}
void add_fun(const char *moudle_name, const char *fun_name, const char *fun_describe)
{
if((*STT_Basic_Moudle::STT_G_Test_Fun_Info).find(fun_name)==(*STT_Basic_Moudle::STT_G_Test_Fun_Info).end())
{
TEST_FUN_INFO tfi={moudle_name,fun_name,fun_describe};
(*STT_Basic_Moudle::STT_G_Test_Fun_Info).insert(std::pair<std::string,TEST_FUN_INFO>(fun_name,tfi));
}
}
3、使用
我的注册时在插件里实现的,调用在主程序里,这样可以n个插件向同一个javascript解释器里注册不同的对象
执行完一次可以判断是否有异常,打印异常信息等
///
/// \brief G_STT_Interpreter [STT解释器]
///
std::map<int,QScriptEngine *> G_STT_Interpreter;
/* ############################################################################################################# */