// This will return as soon as a message is posted S32 work(Thread::MessageQueue& messageQueue) { U32 start = GetPlatform()->getRealMilliseconds(); Thread::MessageRef msg; messageQueue.waitOnMessageToThread(msg, true); return GetPlatform()->getRealMilliseconds() - start; }
void LogMessageFile(my::LogLevel level, my::SrcPoint const & srcPoint, string const & msg) { static mutex mtx; static unique_ptr<FileWriter> file; string recordType; switch (level) { case LINFO: recordType.assign("INFO "); break; case LDEBUG: recordType.assign("DEBUG "); break; case LWARNING: recordType.assign("WARN "); break; case LERROR: recordType.assign("ERROR "); break; case LCRITICAL: recordType.assign("FATAL "); break; } lock_guard<mutex> lock(mtx); if (file == nullptr) { if (GetPlatform().WritableDir().empty()) return; tm * curTimeTM = GetLocalTime(); stringstream fileName; fileName << "logging_" << curTimeTM->tm_year + 1900 << "_" << curTimeTM->tm_mon + 1 << "_" << curTimeTM->tm_mday << "_" << curTimeTM->tm_hour << "_" << curTimeTM->tm_min << "_" << curTimeTM->tm_sec << ".log"; file.reset(new FileWriter(GetPlatform().WritablePathForFile(fileName.str()))); } string srcString = recordType + DebugPrint(srcPoint) + " " + msg + "\n"; file->Write(srcString.c_str(), srcString.size()); file->Flush(); }
Rect HierarchyTreeScreenNode::GetRect() const { Rect rect(0, 0, GetPlatform()->GetWidth(), GetPlatform()->GetHeight()); CombineRectWithChild(rect); return rect; }
TEST(Thread, DeleteTermination) { AutoPtr<Thread> t(new Thread(MakeDelegate(&work))); U32 time = GetPlatform()->getRealMilliseconds(); t->start(); t = NULL; time = GetPlatform()->getRealMilliseconds() - time; //, "Thread deletion did not immediately terminate the thread"); EXPECT_TRUE(time < 1000); }
WritableDirChanger::WritableDirChanger(string const & testDir) : m_writableDirBeforeTest(GetPlatform().WritableDir()) , m_testDirFullPath(m_writableDirBeforeTest + testDir) { Platform & platform = GetPlatform(); platform.RmDirRecursively(m_testDirFullPath); TEST(!platform.IsFileExistsByFullPath(m_testDirFullPath), ()); TEST_EQUAL(Platform::ERR_OK, platform.MkDir(m_testDirFullPath), ()); platform.SetWritableDirForTests(m_testDirFullPath); settings::Clear(); }
int main(int argc, char * argv[]) { // Our double parsing code (base/string_utils.hpp) needs dots as a floating point delimiters, not commas. // TODO: Refactor our doubles parsing code to use locale-independent delimiters. // For example, https://github.com/google/double-conversion can be used. // See http://dbaron.org/log/20121222-locale for more details. (void)::setenv("LC_NUMERIC", "C", 1); InitializeFinalize mainGuard; UNUSED_VALUE(mainGuard); QApplication a(argc, argv); #ifdef DEBUG alohalytics::Stats::Instance().SetDebugMode(true); #endif GetPlatform().SetupMeasurementSystem(); // display EULA if needed char const * settingsEULA = "EulaAccepted"; bool eulaAccepted = false; if (!Settings::Get(settingsEULA, eulaAccepted) || !eulaAccepted) { QStringList buttons; buttons << "Accept" << "Decline"; string buffer; { ReaderPtr<Reader> reader = GetPlatform().GetReader("eula.html"); reader.ReadAsString(buffer); } qt::InfoDialog eulaDialog("MAPS.ME End User Licensing Agreement", buffer.c_str(), NULL, buttons); eulaAccepted = (eulaDialog.exec() == 1); Settings::Set(settingsEULA, eulaAccepted); } int returnCode = -1; if (eulaAccepted) // User has accepted EULA { qt::MainWindow w; w.show(); returnCode = a.exec(); } dbg::ObjectTracker::PrintLeaks(); LOG_SHORT(LINFO, ("MapsWithMe finished with code", returnCode)); return returnCode; }
const wxString wxProcessKiller::Name(int pid) { wxString str; str.Printf(_T("id=%d"),pid); #ifdef _DEBUG #ifdef _WIN32 if(VER_PLATFORM_WIN32_NT==GetPlatform() && hInstLib1){ static BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *, DWORD, LPDWORD ) = (BOOL(WINAPI *)(HANDLE, HMODULE *, DWORD, LPDWORD)) GetProcAddress( (HINSTANCE) hInstLib1,"EnumProcessModules" ) ; static DWORD (WINAPI *lpfGetModuleFileNameEx)( HANDLE, HMODULE, LPTSTR, DWORD )= (DWORD (WINAPI *)(HANDLE, HMODULE,LPTSTR, DWORD )) GetProcAddress( (HINSTANCE) hInstLib1,"GetModuleFileNameExA" ) ; if( lpfEnumProcessModules && lpfGetModuleFileNameEx ) { HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,false,pid); if(hProcess) { HMODULE hMod; DWORD dwSize; if(lpfEnumProcessModules( hProcess, &hMod, sizeof(HMODULE), &dwSize ) ){ // Get Full pathname: TCHAR buf[1+MAX_PATH]; lpfGetModuleFileNameEx( hProcess, hMod, buf, MAX_PATH); str+=_TCHAR(' '); str+=buf; } CloseHandle(hProcess); } } } #endif #endif return str; }
TestSearchEngine::TestSearchEngine(unique_ptr<::search::SearchQueryFactory> factory, Engine::Params const & params) : m_platform(GetPlatform()) , m_infoGetter(storage::CountryInfoReader::CreateCountryInfoReader(m_platform)) , m_engine(*this, GetDefaultCategories(), *m_infoGetter, move(factory), params) { }
TestSearchEngine::TestSearchEngine(std::string const & locale) : m_platform(GetPlatform()), m_engine(this, m_platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), m_platform.GetReader(PACKED_POLYGONS_FILE), m_platform.GetReader(COUNTRIES_FILE), locale, make_unique<TestSearchQueryFactory>()) { }
void Load() { LOG(LDEBUG, ("Reading of classificator started")); Platform & p = GetPlatform(); MapStyle const originMapStyle = GetStyleReader().GetCurrentStyle(); for (size_t i = 0; i < MapStyleCount; ++i) { MapStyle const mapStyle = static_cast<MapStyle>(i); // Read the merged style only if it was requested. if (mapStyle != MapStyleMerged || originMapStyle == MapStyleMerged) { GetStyleReader().SetCurrentStyle(mapStyle); ReadCommon(p.GetReader("classificator.txt"), p.GetReader("types.txt")); drule::LoadRules(); } } GetStyleReader().SetCurrentStyle(originMapStyle); LOG(LDEBUG, ("Reading of classificator finished")); }
void Framework::InitRenderPolicy(bool needApiPin, m2::PointD const & apiPinPoint, bool needMyLoc, m2::PointD const & myLocPoint) { shared_ptr<RenderContext> primaryRC(new RenderContext()); graphics::ResourceManager::Params rmParams; rmParams.m_texFormat = graphics::Data4Bpp; rmParams.m_texRtFormat = graphics::Data4Bpp; rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit(); RenderPolicy::Params rpParams; rpParams.m_videoTimer = &m_timer; rpParams.m_useDefaultFB = true; rpParams.m_rmParams = rmParams; rpParams.m_primaryRC = primaryRC; rpParams.m_density = graphics::EDensityMDPI; rpParams.m_skinName = "basic.skn"; rpParams.m_screenWidth = m_width; rpParams.m_screenHeight = m_height; YopmeRP * rp = new YopmeRP(rpParams); m_framework.SetRenderPolicy(rp); m_framework.InitGuiSubsystem(); rp->SetDrawingApiPin(needApiPin, m_framework.GtoP(apiPinPoint)); rp->SetDrawingMyLocation(needMyLoc, m_framework.GtoP(myLocPoint)); }
JNIEXPORT void JNICALL Java_com_mapswithme_maps_uber_Uber_nativeRequestUberProducts( JNIEnv * env, jclass clazz, jdouble srcLat, jdouble srcLon, jdouble dstLat, jdouble dstLon) { PrepareClassRefs(env); ms::LatLon const from(srcLat, srcLon); ms::LatLon const to(dstLat, dstLon); g_lastRequestId = g_framework->RequestUberProducts( from, to, [](vector<uber::Product> const & products, uint64_t const requestId) { GetPlatform().RunOnGuiThread([=]() { if (g_lastRequestId != requestId) return; JNIEnv * env = jni::GetEnv(); auto uberProducts = jni::ToJavaArray( env, g_productClass, products, [](JNIEnv * env, uber::Product const & item) { return env->NewObject( g_productClass, g_productConstructor, jni::ToJavaString(env, item.m_productId), jni::ToJavaString(env, item.m_name), jni::ToJavaString(env, item.m_time), jni::ToJavaString(env, item.m_price)); }); jobject const routingControllerInstance = env->CallStaticObjectMethod(g_routingControllerClass, g_routingControllerGetMethod); env->CallVoidMethod(routingControllerInstance, g_uberInfoCallbackMethod, env->NewObject(g_uberInfoClass, g_uberInfoConstructor, uberProducts)); }); }); }
S32 watch(Thread::MessageQueue& messageQueue) { worker = new Thread(MakeDelegate(&work)); worker->start(); while(worker->isRunning()) GetPlatform()->sleep(1); return 0; }
GMPErr OpenRecord(const char* aName, uint32_t aNameLength, GMPRecord** aOutRecord, GMPRecordClient* aClient) { return GetPlatform()->createrecord(aName, aNameLength, aOutRecord, aClient); }
WritableDirChanger::~WritableDirChanger() { settings::Clear(); Platform & platform = GetPlatform(); string const writableDirForTest = platform.WritableDir(); platform.SetWritableDirForTests(m_writableDirBeforeTest); platform.RmDirRecursively(writableDirForTest); }
CCpuUsage::CCpuUsage() { m_bFirstTime = true; m_lnOldValue = 0; memset(&m_OldPerfTime100nSec, 0, sizeof(m_OldPerfTime100nSec)); m_nPlatform = GetPlatform(); }
bool IsScaleAllowableIn3d(int scale) { int minScale = scales::GetMinAllowableIn3dScale(); if (df::VisualParams::Instance().GetVisualScale() <= 1.0) --minScale; if (GetPlatform().IsTablet()) ++minScale; return scale >= minScale; }
TEST(Thread,BasicUsage) { didWork = false; Thread t(MakeDelegate(&work)); t.start(); t.finish(); GetPlatform()->sleep(10); // Give the OS a moment to start/end the tread. We shouldn't assume this is sync. EXPECT_FALSE(t.isRunning()); //"Thread in a running state after finish()"); EXPECT_TRUE(didWork); //"Thread not executed"); EXPECT_TRUE(t.getReturnCode() == _magicNumber);//, "Thread did not return magic number"); }
int PlatformMain( void ){ pPlatform = GetPlatform(); pPlatform->ShowDebugConsole(); pPlatform->Create(L"Hello", 4, 2, 640, 640, 24, 8, 24, 8, CPlatform::MS_0); Setup(pPlatform); while(!pPlatform->IsQuitting()) MainLoop(pPlatform); CleanUp(); return 0; }
void BackendRenderer::InitGLDependentResource() { dp::TextureManager::Params params; params.m_resPrefix = VisualParams::Instance().GetResourcePostfix(); params.m_glyphMngParams.m_uniBlocks = "unicode_blocks.txt"; params.m_glyphMngParams.m_whitelist = "fonts_whitelist.txt"; params.m_glyphMngParams.m_blacklist = "fonts_blacklist.txt"; GetPlatform().GetFontNames(params.m_glyphMngParams.m_fonts); m_textures->Init(params); }
int PlatformMain( void ){ pPlatform = GetPlatform(); pPlatform->ShowDebugConsole(); pPlatform->Create(L"transform example, phasersonkill.com", 4, 2, 640, 640, 24, 8, 24, 8, CPlatform::MS_0); Setup(pPlatform); while(!pPlatform->IsQuitting()) MainLoop(pPlatform); CleanUp(); return 0; }
void UserStatsLoader::Update(string const & userName, TOnUpdateCallback fn) { auto nothingToUpdate = false; { lock_guard<mutex> g(m_mutex); nothingToUpdate = m_userStats && m_userName == userName && m_userStats && difftime(m_lastUpdate, time(nullptr)) < kSecondsInHour; } if (nothingToUpdate) { GetPlatform().RunOnGuiThread(fn); return; } thread([this, userName, fn] { if (Update(userName)) GetPlatform().RunOnGuiThread(fn); }).detach(); }
HttpThread::HttpThread(string const & url, downloader::IHttpThreadCallback & cb, int64_t beg, int64_t end, int64_t size, string const & pb) : m_callback(cb), m_begRange(beg), m_endRange(end), m_downloadedBytes(0), m_expectedSize(size) { QUrl const qUrl(url.c_str()); QNetworkRequest request(qUrl); // use Range header only if we don't download whole file from start if (!(beg == 0 && end < 0)) { if (end > 0) { LOG(LDEBUG, (url, "downloading range [", beg, ",", end, "]")); QString const range = QString("bytes=") + QString::number(beg) + '-' + QString::number(end); request.setRawHeader("Range", range.toUtf8()); } else { LOG(LDEBUG, (url, "resuming download from position", beg)); QString const range = QString("bytes=") + QString::number(beg) + '-'; request.setRawHeader("Range", range.toUtf8()); } } // set user-agent with unique client id only for mapswithme requests if (url.find("mapswithme.com") != string::npos) { static string const uid = GetPlatform().UniqueClientId(); request.setRawHeader("User-Agent", uid.c_str()); } /// Use single instance for whole app static QNetworkAccessManager netManager; if (pb.empty()) m_reply = netManager.get(request); else { request.setRawHeader("Content-Type", "application/json"); request.setRawHeader("Content-Length", QString::number(pb.size()).toLocal8Bit()); m_reply = netManager.post(request, pb.c_str()); } connect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(OnHeadersReceived())); connect(m_reply, SIGNAL(readyRead()), this, SLOT(OnChunkDownloaded())); connect(m_reply, SIGNAL(finished()), this, SLOT(OnDownloadFinished())); LOG(LDEBUG, ("Connecting to", url, "[", beg, ",", end, "]", "size=", size)); }
TEST(Thread, PostMessage) { Thread t(MakeDelegate(&work)); t.start(); GetPlatform()->sleep(100); // We don't care about the type of the message Thread::Message* msg = new Thread::TerminateMessage; t.getMessageQueue().postToThread(msg); t.finish(); //, "Thread terminated early, didn't wait on message"); EXPECT_TRUE(t.getReturnCode() >= 90); }
void BookmarkManager::LoadBookmarks() { ClearItems(); string const dir = GetPlatform().SettingsDir(); Platform::FilesList files; Platform::GetFilesByExt(dir, BOOKMARKS_FILE_EXTENSION, files); for (size_t i = 0; i < files.size(); ++i) LoadBookmark(dir + files[i]); LoadState(); }
void LogMemoryInfo() { static unsigned long counter = 0; const unsigned short writeLogEveryNthCall = 3; if (counter++ % writeLogEveryNthCall == 0) { tm * curTimeTM = GetLocalTime(); stringstream timeDate; timeDate << " " << curTimeTM->tm_year + 1900 << "." << curTimeTM->tm_mon + 1 << "." << curTimeTM->tm_mday << " " << curTimeTM->tm_hour << ":" << curTimeTM->tm_min << ":" << curTimeTM->tm_sec << " "; LOG(LINFO, (timeDate.str(), GetPlatform().GetMemoryInfo())); } }
TEST(Thread, IsRunning) { watchdog = new Thread(MakeDelegate(&watch)); passed = true; watchdog->start(); GetPlatform()->sleep(200); //, "Thread polled never finished"); EXPECT_FALSE(watchdog->isRunning()); watchdog = NULL; worker = NULL; }
String SystemLinux::GetOS() const { // Get system info if (m_bSysInfoInit) { String sVersion = m_sName.sysname; sVersion += ' '; sVersion += m_sName.machine; sVersion += ' '; sVersion += m_sName.release; return sVersion; } else { return GetPlatform() + " unknown"; } }
void OnlineAbsentCountriesFetcher::GenerateRequest(const m2::PointD & startPoint, const m2::PointD & finalPoint) { // Single mwm case. if (m_countryFileFn(startPoint) == m_countryFileFn(finalPoint) || GetPlatform().ConnectionStatus() == Platform::EConnectionType::CONNECTION_NONE) return; unique_ptr<OnlineCrossFetcher> fetcher = make_unique<OnlineCrossFetcher>(OSRM_ONLINE_SERVER_URL, MercatorBounds::ToLatLon(startPoint), MercatorBounds::ToLatLon(finalPoint)); // iOS can't reuse threads. So we need to recreate the thread. m_fetcherThread.reset(new threads::Thread()); m_fetcherThread->Create(move(fetcher)); }
void BannerSet::LoadBanners() { try { auto reader = GetPlatform().GetReader(BANNERS_FILE); ReaderStreamBuf buffer(move(reader)); istream s(&buffer); ReadBanners(s); } catch (FileAbsentException const &) { LOG(LWARNING, ("No", BANNERS_FILE, "found")); return; } }