long __Call_tg( CDSR_VMEval& /*vm*/, MMD_Address& addr, UniWord *arg ) { #if _DEBUG if( addr.param2 < 0 ) throw _T("__Call_(fun) : internal error, out of range"); #endif if( addr.param2 == 0 ) // DSRDATA_TYPE_REAL *(arg - 1) = CDSRReal( tg( (arg - 1)->getReal() ) ); else // DSRDATA_TYPE_COMPLEX *(arg - 1) = CDSRComplex( tg( (arg - 1)->getComplex() ) ); return 1 - addr.param3; }
void DebugHelper::critical_msg(const char * str, ...) { if(str == NULL) return; KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else va_list ap; va_start(ap, str); #if KBE_PLATFORM == PLATFORM_WIN32 uint32 size = _vsnprintf(_g_buf, DBG_PT_SIZE, str, ap); #else uint32 size = vsnprintf(_g_buf, DBG_PT_SIZE, str, ap); #endif va_end(ap); char buf[DBG_PT_SIZE]; kbe_snprintf(buf, DBG_PT_SIZE, "%s(%d) -> %s\n\t%s\n", _currFile.c_str(), _currLine, _currFuncName.c_str(), _g_buf); LOG4CXX_FATAL(g_logger, buf); #endif setFile("", "", 0); onMessage(LOG_CRITICAL, _g_buf, size); }
ERR_Code aCatGroup::SetParent( aCatGroup * parent ) { aSQLTable * t = table(); if ( !t ) return err_notable; qulonglong idp = 0, uid = getUid(); if ( parent ) idp = parent->getUid(); if ( idp == uid ) return err_cyclereparent; qulonglong level, tmpid = idp; aCatGroup tg( obj, db ); while ( tmpid ) { tg.select(tmpid); tmpid = tg.parentUid(); if ( tmpid == uid ) return err_cyclereparent; } QString query; query = QString("UPDATE %1 SET idp=%2 WHERE id=%3").arg(t->tableName).arg(idp).arg(uid); level = parent->Value("Level").toULongLong(); // printf("%s\n",(const char*)query); QSqlDatabase tdb = *db->db(); tdb.exec(query); if ( !tdb.lastError().type() ) { if (idp) setLevel(level+1); else setLevel(0); return err_noerror; } else return err_execerror; }
//------------------------------------------------------------------------------------- void DebugHelper::script_msg(const std::string& s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); if(s.size() > 33 /* strlen("Traceback (most recent call last)" */) { if(s[0] == 'T' && s[10] == '(') { if(s.substr(0, 33) == "Traceback (most recent call last)") setScriptMsgType(log4cxx::ScriptLevel::SCRIPT_ERR); } } #ifdef NO_USE_LOG4CXX #else if(canLogFile_) LOG4CXX_LOG(g_logger, log4cxx::ScriptLevel::toLevel(scriptMsgType_), s); #endif onMessage(KBELOG_SCRIPT, s.c_str(), s.size()); #if KBE_PLATFORM == PLATFORM_WIN32 if(log4cxx::ScriptLevel::SCRIPT_ERR == scriptMsgType_) printf("[S_ERROR]: %s", s.c_str()); #endif }
//------------------------------------------------------------------------------------- NavigationHandlePtr Navigation::findNavigation(std::string resPath) { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.find(resPath); if(navhandles_.find(resPath) != navhandles_.end()) { if(iter->second == NULL) return NULL; if(iter->second->type() == NavigationHandle::NAV_MESH) { return iter->second; } else if (iter->second->type() == NavigationHandle::NAV_TILE) { // 由于tile需要做碰撞, 每一个space都需要一份新的数据, 我们这里采用拷贝的方式来增加构造速度 NavTileHandle* pNavTileHandle = new NavTileHandle(*(KBEngine::NavTileHandle*)iter->second.get()); DEBUG_MSG(fmt::format("Navigation::findNavigation: copy NavTileHandle({:p})!\n", (void*)pNavTileHandle)); return NavigationHandlePtr(pNavTileHandle); } return iter->second; } return NULL; }
Ptr<Packet> OvnisPacket::BuildPacket(double timeStamp, string senderId, double x, double y, int type, string objectId, double objectValue) { int senderIdSize = senderId.size(); int objectIdSize = objectId.size(); int headerSize = sizeof (int) + sizeof (double) + sizeof (double) + sizeof (double) + sizeof (int) + senderIdSize * sizeof (char) + sizeof (int); int messageSize = sizeof (int) + objectIdSize * sizeof(char) + sizeof(double); int totalSize = headerSize + messageSize; try { uint8_t * t = (uint8_t*) malloc(totalSize); TagBuffer tg(t, t + totalSize); // write header tg.WriteU32(totalSize); tg.WriteDouble(timeStamp); tg.WriteDouble(x); tg.WriteDouble(y); tg.WriteU32(senderIdSize); tg.Write((uint8_t*) senderId.c_str(), senderIdSize); tg.WriteU32(type); // write message tg.WriteU32(objectIdSize); tg.Write((uint8_t*) objectId.c_str(), objectIdSize); tg.WriteDouble(objectValue); Ptr<Packet> p = Create<Packet>(t, totalSize); free(t); return p; } catch (exception & e) { return NULL; } }
Ptr<Packet> OvnisPacket::BuildChangedEdgePacket(double timeStamp, string senderId, double x, double y, int type, string lastEdgeId, double travelTime, string currentEdgeId) { int senderIdSize = senderId.size(); int lastEdgeIdSize = lastEdgeId.size(); int currentEdgeIdSize = currentEdgeId.size(); int headerSize = sizeof (int) + sizeof (double) + sizeof (double) + sizeof (double) + sizeof (int) + senderIdSize * sizeof (char) + sizeof (int) ; int messageSize = sizeof (int) + lastEdgeIdSize * sizeof (char) + sizeof (double) + sizeof (int) + currentEdgeIdSize * sizeof (char) ; int totalSize = headerSize + messageSize; try { uint8_t * t = (uint8_t*) malloc(totalSize); TagBuffer tg(t, t + totalSize); // write header tg.WriteU32(totalSize); tg.WriteDouble(timeStamp); tg.WriteDouble(x); tg.WriteDouble(y); tg.WriteU32(senderIdSize); tg.Write((uint8_t*) senderId.c_str(), senderIdSize); tg.WriteU32(type); // write message tg.WriteU32(lastEdgeIdSize); tg.Write((uint8_t*) lastEdgeId.c_str(), lastEdgeIdSize); tg.WriteDouble(travelTime); tg.WriteU32(currentEdgeIdSize); tg.Write((uint8_t*) currentEdgeId.c_str(), currentEdgeIdSize); Ptr<Packet> p = Create<Packet>(t, totalSize); //cout << "create cep " << totalSize << endl; free(t); return p; } catch (exception & e) { return NULL; } }
static bool cps_api_clean_db_instance(const char *group) { cps_api_transaction_params_t tr; if (cps_api_transaction_init(&tr)!=cps_api_ret_code_OK) { return false; } cps_api_transaction_guard tg(&tr); cps_api_object_t db_obj = cps_api_object_create(); if(db_obj == nullptr ) return false; cps_api_key_from_attr_with_qual(cps_api_object_key(db_obj),CPS_DB_INSTANCE_OBJ, cps_api_qualifier_TARGET); cps_api_object_attr_add(db_obj,CPS_DB_INSTANCE_GROUP,group,strlen(group)+1); if(cps_api_delete(&tr,db_obj) != cps_api_ret_code_OK ) { return false; } if(cps_api_commit(&tr) != cps_api_ret_code_OK ) { EV_LOGGING(DSAPI,ERR,"CPS-DB","Failed to delete db instance for group %s",group); return false; } return true; }
/** * @brief Starts all sub threads for the data aquisiton * * @return void */ void Pi::CarPi::run() { try { CallbackAsyncSerial* shield = new CallbackAsyncSerial("/dev/ttyAMA0", 115200); // Create the Logger Class Pi::GPS::GPSLogger gps; // set the Callback form the logger class shield->setCallback(boost::bind(&Pi::GPS::GPSLogger::recievedDataCallback, gps, _1, _2)); // final class set up and go gps.setDevice(boost::ref(shield)); gps.startPolling(5); // remove callback since gps will be destroyed shield->clearCallback(); } catch(std::exception& e) { std::cerr<<"Exception: "<<e.what()<<std::endl; } // shield->setCallback(&CarPi::CarPi::test_callback); // Connection to the car // CallbackAsyncSerial car("/dev/ttyODB2", 38400); // car->setCallback(ODB2Logger::recievedDataCallback); boost::thread_group tg(); // Start adding threads // ODB2Logger odb2_logger(car); // tg.create_thread<ODB2Logger>(&odb2_logger.startPolling, 5000); }
el_bool ccover_get_embedded(ccover_t cc, const char* filename, const char* target) { CCover* c = (CCover*) cc; std::string tg(target); //return el_false; TagLib::FileRef ref(filename); return c->GetEmbedded(ref, tg); }
el_bool ccover_get_local(ccover_t cc, const char* filename, const char* folder, const char* target) { CCover* c = (CCover*) cc; std::string fn(filename); std::string fd(folder); std::string tg(target); return c->GetLocal(fn, fd, tg); }
int main() { ParseTree * t; TraGenMain tg(t, NULL, fopen("test", "w")); tg.run(); return 0; }
TEST(TimeGovernor, step) { TimeGovernor::marks().reinit(); string tg_in="{time = { start_time = 0.0, end_time = 10.0 } }"; TimeGovernor tg( read_input(tg_in)); tg.marks().add_time_marks(0.0, 1.0, 10.0, tg.equation_fixed_mark_type()); EXPECT_EQ(0, tg.step().index()); EXPECT_EQ(0, tg.step(-1).index()); EXPECT_EQ(0, tg.step(0).index()); EXPECT_THROW( {tg.step(1);}, TimeGovernor::ExcMissingTimeStep);
bool test() { std::unique_ptr<TGood> tg(new TGood); std::unique_ptr<TBad> tb(new TBad); std::unique_ptr<int> i(new int); std::unique_ptr<X> x(new X); return f(tg) && !f(tb) && !f(i) && !f(x); }
//------------------------------------------------------------------------------------- void DebugHelper::warning_msg(std::string s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else LOG4CXX_WARN(g_logger, s); #endif onMessage(KBELOG_WARNING, s.c_str(), s.size()); }
//------------------------------------------------------------------------------------- void DebugHelper::print_msg(std::string s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else LOG4CXX_INFO(g_logger, s); #endif onMessage(KBELOG_PRINT, s.c_str(), s.size()); }
inline void expose_type_generator(const std::string &name) { // We do not want to have duplicate instances on the Python side. if (tg_names.find(name) != tg_names.end()) { ::PyErr_SetString(PyExc_RuntimeError,(std::string("a type generator called '") + name + "' has already been instantiated").c_str()); bp::throw_error_already_set(); } tg_names.insert(name); type_generator tg(std::type_index(typeid(T))); bp::scope().attr("types").attr(name.c_str()) = tg; }
//------------------------------------------------------------------------------------- Navigation::~Navigation() { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.begin(); for(; iter != navhandles_.end(); ++iter) { iter->second->decRef(); } navhandles_.clear(); }
//------------------------------------------------------------------------------------- NavMeshHandle* NavMeshEx::findNavmesh(std::string name) { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map<std::string, NavMeshHandle*>::iterator iter = navmeshs_.find(name); if(navmeshs_.find(name) != navmeshs_.end()) { return iter->second; } return NULL; }
//------------------------------------------------------------------------------------- void DebugHelper::debug_msg(const std::string& s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else if(canLogFile_) LOG4CXX_DEBUG(g_logger, s); #endif onMessage(KBELOG_DEBUG, s.c_str(), s.size()); }
uint32 watcher_query(std::string cmd) { KBEngine::thread::ThreadGuard tg(&logMutex); KBEUnordered_map< std::string, uint32 >::iterator iter = g_querystatistics.find(cmd); if(iter != g_querystatistics.end()) { return iter->second; } return 0; }
int sc_main(int argc, char* argv[]) { sc_signal<bool> s_sig; sc_signal<bool> q_sig, qn_sig; sc_clock clk_sig("TestClock", 10, SC_NS, 0.5); TestGenerator tg("test_generator"); tg.s_out(s_sig); tg.clk(clk_sig); //#define TEST_S_LATCH_V0 //#define TEST_S_LATCH_V1 #define TEST_S_LATCH_WITH_TWO_OUT #ifdef TEST_S_LATCH_V0 SLatchV0 DUT("SLatchV0"); #endif #ifdef TEST_S_LATCH_V1 SLatchV1 DUT("SLatchV1"); #endif #ifdef TEST_S_LATCH_WITH_TWO_OUT SLatchWithTwoOut DUT("SLatchWithTwoOut"); #endif DUT.clk_in(clk_sig); DUT.set_in(s_sig); #ifndef TEST_S_LATCH_V0 DUT.q_out(q_sig); DUT.qn_out(qn_sig); #endif sc_trace_file* p_trace_file; p_trace_file = sc_create_vcd_trace_file("traces"); sc_trace(p_trace_file, s_sig , "set" ); sc_trace(p_trace_file, DUT.reset_sig , "reset" ); sc_trace(p_trace_file, clk_sig , "clk" ); sc_trace(p_trace_file, DUT.a_sig , "a" ); sc_trace(p_trace_file, DUT.b_sig , "b" ); sc_trace(p_trace_file, DUT.q_internal_sig , "q_internal_sig" ); sc_trace(p_trace_file, DUT.qn_internal_sig , "qn_internal_sig" ); #ifndef TEST_S_LATCH_V0 sc_trace(p_trace_file, q_sig , "q_sig" ); sc_trace(p_trace_file, qn_sig , "qn_sig" ); #endif cout << "start simulation for " << DUT.name() << endl; sc_start(70, SC_NS); sc_close_vcd_trace_file(p_trace_file); return 0; }
//------------------------------------------------------------------------------------- void DebugHelper::critical_msg(std::string s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); char buf[DBG_PT_SIZE]; kbe_snprintf(buf, DBG_PT_SIZE, "%s(%d) -> %s\n\t%s\n", _currFile.c_str(), _currLine, _currFuncName.c_str(), s.c_str()); #ifdef NO_USE_LOG4CXX #else LOG4CXX_FATAL(g_logger, buf); #endif onMessage(KBELOG_CRITICAL, buf, strlen(buf)); backtrace_msg(); }
//------------------------------------------------------------------------------------- void DebugHelper::error_msg(const std::string& s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else LOG4CXX_ERROR(g_logger, s); #endif onMessage(KBELOG_ERROR, s.c_str(), s.size()); #if KBE_PLATFORM == PLATFORM_WIN32 printf("[ERROR]: %s", s.c_str()); #endif }
//------------------------------------------------------------------------------------- bool Navigation::removeNavigation(std::string resPath) { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.find(resPath); if(navhandles_.find(resPath) != navhandles_.end()) { iter->second->decRef(); navhandles_.erase(iter); DEBUG_MSG(fmt::format("Navigation::removeNavigation: ({}) is destroyed!\n", resPath)); return true; } return false; }
//------------------------------------------------------------------------------------- void Resmgr::update() { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map< std::string, ResourceObjectPtr >::iterator iter = respool_.begin(); for(; iter != respool_.end();) { if(!iter->second->valid()) { respool_.erase(iter++); } else { iter++; } } }
//------------------------------------------------------------------------------------- void DebugHelper::script_msg(std::string s) { KBEngine::thread::ThreadGuard tg(&this->logMutex); #ifdef NO_USE_LOG4CXX #else LOG4CXX_LOG(g_logger, log4cxx::ScriptLevel::toLevel(scriptMsgType_), s); #endif onMessage(KBELOG_SCRIPT, s.c_str(), s.size()); #if KBE_PLATFORM == PLATFORM_WIN32 if(log4cxx::ScriptLevel::SCRIPT_ERR == scriptMsgType_) printf("[S_ERROR]: %s", s.c_str()); #endif }
//------------------------------------------------------------------------------------- NavMeshEx::~NavMeshEx() { KBEngine::thread::ThreadGuard tg(&mutex_); KBEUnordered_map<std::string, NavMeshHandle*>::iterator iter = navmeshs_.begin(); for(; iter != navmeshs_.end(); iter++) { NavMeshHandle* pNavMeshHandle = (NavMeshHandle*)iter->second; dtFreeNavMeshQuery(pNavMeshHandle->navmeshQuery); dtFreeNavMesh(pNavMeshHandle->navmesh); delete pNavMeshHandle; DEBUG_MSG(boost::format("NavMeshEx::~NavMeshEx(): (%1%) is destroyed!\n") % iter->first); } navmeshs_.clear(); }
//------------------------------------------------------------------------------------- NavigationHandlePtr Navigation::loadNavigation(std::string resPath, const std::map< int, std::string >& params) { KBEngine::thread::ThreadGuard tg(&mutex_); if(resPath == "") return NULL; KBEUnordered_map<std::string, NavigationHandlePtr>::iterator iter = navhandles_.find(resPath); if(iter != navhandles_.end()) { return iter->second; } NavigationHandle* pNavigationHandle_ = NULL; std::string path = resPath; path = Resmgr::getSingleton().matchPath(path); if(path.size() == 0) return NULL; wchar_t* wpath = strutil::char2wchar(path.c_str()); std::wstring wspath = wpath; free(wpath); std::vector<std::wstring> results; Resmgr::getSingleton().listPathRes(wspath, L"tmx", results); if(results.size() > 0) { pNavigationHandle_ = NavTileHandle::create(resPath, params); } else { results.clear(); Resmgr::getSingleton().listPathRes(wspath, L"navmesh", results); if(results.size() == 0) { return NULL; } pNavigationHandle_ = NavMeshHandle::create(resPath, params); } navhandles_[resPath] = NavigationHandlePtr(pNavigationHandle_); return pNavigationHandle_; }
inline std::shared_ptr<std::vector<target> > lua_object< std::vector<target> >::to_type(lua_State *L, int n) { std::shared_ptr<std::vector<target> > targets = std::shared_ptr<std::vector<target> >(new std::vector<target>()); std::back_insert_iterator< std::vector<target> > tg(*targets); int l = lua_rawlen(L, n); for (int i = 1; i <= l; ++i) { lua_rawgeti(L, n, i); // st n + 1 TABLE @ N table @ n + 1 lua_pushstring(L, "loc"); // st n + 2 lua_rawget(L, -2); // st n + 2 lua_pushstring(L, "x"); // st n + 3 lua_rawget(L, -2); // st n + 3 int x = lua_tointeger(L, -1); // st n + 3 lua_pop(L, 1); // st n + 2 lua_pushstring(L, "y"); // st n + 3 lua_rawget(L, -2); // st n + 3 int y = lua_tointeger(L, -1); // st n + 3 lua_pop(L, 2); // st n + 1 lua_pushstring(L, "type"); // st n + 2 lua_rawget(L, -2); // st n + 2 target::TYPE type = target::TYPE::EXPLICIT; if(lua_isnumber(L, -1)) { type = target::TYPE::from_int(lua_tointeger(L, -1)); // st n + 2 } else if(lua_isstring(L, -1)) { type = target::TYPE::string_to_enum(lua_tostring(L, -1)); // st n + 2 } lua_pop(L, 1); // st n + 1 lua_pushstring(L, "value"); lua_rawget(L, -2); int value = lua_tointeger(L, -1); map_location ml(x - 1, y - 1); *tg = target(ml, value, type); } lua_settop(L, n); return targets; }