ssize_t tst::_com() { LogReport(); com::init(); disk::quota::Control quota(L"D:\\", true); LogReport(L"State: %s", quota.get_text(disk::quota::TextType::STATE).c_str()); LogReport(L"Default limit: %s", quota.get_text(disk::quota::TextType::LIMIT).c_str()); LogReport(L"Default threshold: %s", quota.get_text(disk::quota::TextType::THRESHOLD).c_str()); quota.set_control(disk::quota::ControlType::LIMIT_LOGGED, 1); quota.set_control(disk::quota::ControlType::THRESHOLD_LOGGED, 1); // quota.set_control(disk::quota::ControlType::THRESHOLD, int64_t(5) * 1024 * 1024 * 1024); // quota.set_control(disk::quota::ControlType::LIMIT, int64_t(6) * 1024 * 1024 * 1024); LogReport(L"Default limit: %s", quota.get_text(disk::quota::TextType::LIMIT).c_str()); LogReport(L"Default threshold: %s", quota.get_text(disk::quota::TextType::THRESHOLD).c_str()); for (auto it = quota.begin(), end = quota.end(); it != end; ++it) { LogReport(L"user: '******'", it->name().c_str()); LogReport(L"\tused: %s", it->get_text(disk::quota::TextType::USED).c_str()); LogReport(L"\tlimit: %s", it->get_text(disk::quota::TextType::LIMIT).c_str()); LogReport(L"\tthres: %s", it->get_text(disk::quota::TextType::THRESHOLD).c_str()); } // if (quota.empty()) // LogReport("No quota entries"); return 0; }
bool CKadOperation::AddNode(CKadNode* pNode, bool bStateless, const CVariant &InitParam, int Shares) { CComChannel* pChannel = GetChannel(pNode); if(!pChannel) return false; SOpProgress* pProgress = GetProgress(pNode); if(!pProgress || pProgress->OpState != eNoOp) // error or already used return false; ASSERT(pProgress->Shares == 0); if(bStateless) { if(!(CountCalls() || CountStores() || CountLoads())) { LogReport(LOG_WARNING, L"Can not add a node in stateles mode if no requests are queued"); return false; } RequestStateless(pNode, pChannel, pProgress); return true; } if(Shares != 0) return RequestProxying(pNode, pChannel, pProgress, Shares, InitParam); // Note: if we are in range we will act as one successfull share int UsedShares = m_InRange ? 1 : 0; int ShareHolders = 0; for(TNodeStatusMap::iterator I = m_Nodes.begin(); I != m_Nodes.end(); I++) { SOpProgress* pProgress = (SOpProgress*)I->second; if(pProgress->Shares == 0) continue; UsedShares += pProgress->Shares; ShareHolders++; } int FreeShares = GetSpreadShare() - UsedShares; ASSERT(FreeShares >= 0); if(FreeShares < 1) { LogReport(LOG_WARNING, L"Can not add a proxy node, no free shares available"); return false; } return RequestProxying(pNode, pChannel, pProgress, FreeShares, ShareHolders, InitParam); }
bool CKadOperation::ReadyToStop() { if(m_pOperator) { // we check if the script got terminated in the mean time if(!m_pOperator->IsValid()) { LogReport(LOG_ERROR, L"Script has been unexpectedly terminated", "Terminated"); return true; } } bool bFoundEnough = HasFoundEnough(); bool bTimedOut = HasTimedOut(); if(!bTimedOut && !bFoundEnough) return false; // If we have an operator we ask him if its ok to finish now if(m_pOperator && m_pOperator->IsValid()) { bool bForceFinish = GetDuration() > SEC2MS(GetParent<CKademlia>()->Cfg()->GetInt64("MaxLookupTimeout")); // if true than timeout can not be canceled if(!m_pOperator->OnFinish(bForceFinish, bTimedOut, bFoundEnough) && !bForceFinish) return false; } return true; }
void test_atomic() { std::atomic_uint_fast64_t a; int64_t b = a; LogReport(L"is_lock_free(): %d, %I64d\n", a.is_lock_free(), b); }
bool CKadScript::Process(UINT Tick) { time_t uIdleTime = GetTime() - m_LastUsed; bool bExpired = uIdleTime > GetParent<CKademlia>()->Cfg()->GetInt("MaxScriptExpiration"); if(m_pScript) { CJSKadScript* pJSKadScript = (CJSKadScript*)m_pScript->GetJSObject(this); // We take this cast on faith, the way object constructros are registered should ensure that we wil get the right object ASSERT(pJSKadScript); CDebugScope Debug(this); try { pJSKadScript->RunTimers(m_pScript); } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); } if(m_pRoute) // refresh the route as long as the script is alive m_pRoute->Refresh(); if(bExpired || uIdleTime > GetParent<CKademlia>()->Cfg()->GetInt("MaxScriptIdleTime")) Terminate(); } return !bExpired; }
CVariant CKadScript::Call(const string& Name, const CVariant& Arguments, const CUInt128& TargetID, const CVariant& XID) { CVariant Result; Result["XID"] = XID; CDebugScope Debug(this); try { CJSScript* pScript = GetJSScript(true); vector<CPointer<CObject> > Parameters; Parameters.push_back(new CVariantPrx(Arguments)); Parameters.push_back(new CKadIDObj(TargetID)); CPointer<CObject> Return; pScript->Call(string("remoteAPI"), Name, Parameters, Return); if(CVariantPrx* pVariant = Return->Cast<CVariantPrx>()) Result["RET"] = pVariant->GetCopy(); else throw CJSException("InvalidResult", L"Call returned an invalid result"); } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); Result["ERR"] = Exception.GetError(); } return Result; }
CVariant CLookupProxy::AddCallReq(const CVariant& Requests) { CVariant Results(CVariant::EList); for(uint32 i=0; i<Requests.Count(); i++) { const CVariant& Request = Requests[i]; if(!m_CallMap.insert(TCallOpMap::value_type(Request["XID"], SCallOp(Request))).second) continue; // we already got this request, ignore it if(m_pOperator && m_pOperator->IsValid()) { try { m_pOperator->AddCallReq(Request["FX"], Request["ARG"], Request["XID"]); } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); CKadOperation::SOpStatus &Progress = m_CallMap[Request["XID"]].Status; Progress.Done = true; // this one is finished CVariant Result; Result["XID"] = Request["XID"]; Result["ERR"] = Exception.GetError(); Results.Append(Result); } } } if(m_pOperator) Results.Merge(m_pOperator->GetResponses()); return Results; }
bool initialize(const std::string &modelname) { glClearColor (0.1, 0.1, 0.1, 0.0); glClearDepth(1.0f); glShadeModel (GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // initialize shaders const char *vertexShader = "../../media/shaders/vertex/point-light.glsl"; const char *fragmentShader = "../../media/shaders/fragment/simple-texture.glsl"; shaderProgram.load(vertexShader, fragmentShader); if (!shaderProgram.good()) { LogError() << "Failed to initialize shaders."; return false; } shaderProgram.bind(); shaderProgram.setUniform(shaderProgram.getUniformLocation("material_Ambient"), matrix4x1(0.1f,0.1f,0.1f,0.1f)); shaderProgram.setUniform(shaderProgram.getUniformLocation("light_Directional_dir"), matrix3x1(-0.5f, 0, 1).unit()); shaderProgram.setUniform(shaderProgram.getUniformLocation("light_Directional_col"), matrix4x1(1, 1, 1)); // load the model try { if (!rigidModel.load(textureLibrary, modelname.c_str())) { LogError() << "Failed to construct model"; return false; } LogReport() << "Constructed rigid model from '" << modelname << "'."; LogReport() << "Texture library contains:"; for (auto it = textureLibrary.textures.begin(); it != textureLibrary.textures.end(); ++it) { LogReport() << " " << it->first; } } catch (std::runtime_error &e) { std::cout << "Failed to initialize model '" << modelname << "' with exception: " << e.what() << std::endl; return false; } return true; }
void CKadOperation::Start() { LogReport(LOG_INFO, L"Starting Operation"); if(m_pOperator && m_pOperator->IsValid()) { try { m_InitParam = m_pOperator->Init(m_InitParam); // this could effectivly update spreading/branching options } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); } } CKadLookup::Start(); if(m_pOperator && m_pOperator->IsValid()) m_pOperator->OnStart(); }
ssize_t tst::_registry() { LogAlert(); astring welln[] = { astring(".DEFAULT"), // astring("S-1-5-18"), // astring("S-1-5-19"), // astring("S-1-5-20"), }; auto seq = registry::open(HKEY_USERS, ""); if (seq) { for (auto it = seq->begin(), end = seq->end(); it != end; ++it) { if (simstd::find(simstd::begin(welln), simstd::end(welln), it->name()) == simstd::end(welln)) { LogReport("found name: '%s'", it->name().c_str()); auto sid = windows::sid::open(it->name().c_str()); if (sid) { LogReport("\tgood sid: '%s', name: '%s'", sid->as_str().c_str(), sid->name().c_str()); } // try open network auto key = registry::open(seq->system(), (it->name() + "\\Network").c_str()); if (key) { LogReport("\texist!"); for (auto it = key->begin(), end = key->end(); it != end; ++it) { auto letter = registry::open(key->system(), it->name().c_str()); auto path = letter->get("RemotePath", ""); LogReport("letter: '%s' -> '%s'", it->name().c_str(), path.c_str()); } } } } } return 0; }
void test_crypt() { LogAtten(); auto prov = crypt::provider(); auto hash = crypt::hash(prov); for (int i = 0; i < 200 && hash->process(reinterpret_cast<const void*>(&i), sizeof(i)); ++i) { } char hashBuf[64]; hash->get_hash(hashBuf, sizeof(hashBuf)); LogReport("hash: %s", hashBuf); }
string CKadOperation::SetupScript(CKadScript* pKadScript) { m_CodeID = pKadScript->GetCodeID(); try { CJSScript* pJSScript = pKadScript->GetJSScript(true); // this may throw a CJSException if instantiation fails m_pOperator = new CKadOperator(pKadScript, pJSScript, this); } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); return Exception.GetError(); } return ""; }
void CKadOperation::PrepareStop() { ASSERT(m_StopTime == -1); if(m_pOperator && m_pOperator->IsValid()) { try { m_pOperator->Finish(); } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); } } CKadLookup::PrepareStop(); }
int main(int argc, const char *arg[]) { std::string modelname = "../../media/models/primitive/cube.obj"; if (argc > 1) { std::string model(arg[1]); if (model == "corsair") { modelname = "../../media/models/aircraft/f4u-corsair/f4u-no-propeller.obj"; } else if (model == "p47") { modelname = "../../media/models/aircraft/p47-thunderbolt/p47.obj"; } else if (model == "ki-84" || model == "kate") { modelname = "../../media/models/aircraft/ki-84/ki84-no-propeller.obj"; } else if (model == "p40" || model == "warhawk") { modelname = "../../media/models/aircraft/p40-warkhawk/P40.obj"; } else if (model == "p38" || model == "lightning") { modelname = "../../media/models/aircraft/p38-lightning/P38.obj"; } else if (model == "uboat" || model == "U99") { modelname = "../../media/models/marine/uboat-u99/U99.obj"; } else if (model == "cube") { modelname = "../../media/models/primitive/cube.obj"; } else if (model == "trex" || model == "t-rex") { modelname = "../../media/models/objects/absurd/t-rex/t-rex.obj"; } else if (model == "path" && argc > 2) { modelname = arg[2]; } } Log::initialize("RenderRigidModel.log", Log::All); LogReport() << "GLFW version: " << glfwGetVersionString(); LogReport() << "Rendering model '" << modelname << "'."; std::cout << "Rendering model '" << modelname << "'." << std::endl; GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) { exit(EXIT_FAILURE); } window = glfwCreateWindow(800, 800, "Render Rigid Body", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); try { if (!application.initialize(modelname)) { return 0; } } catch (std::runtime_error &e) { LogError() << e.what(); std::cerr << e.what() << std::endl; return -1; } try { while (!glfwWindowShouldClose(window)) { application.update(); application.render(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); } catch (std::runtime_error &e) { LogError() << e.what(); std::cerr << e.what() << std::endl; } return 0; }
void test_memory() { LogWarn(""); auto heap = ::GetProcessHeap(); PROCESS_HEAP_ENTRY entry; memory::zero(entry); LogReport("Walking heap %p...", heap); while (::HeapWalk(heap, &entry) != FALSE) { if ((entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { LogReport("Allocated block"); if ((entry.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0) { LogReport(", movable with HANDLE %p", entry.Block.hMem); } if ((entry.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0) { LogReport(", DDESHARE"); } } else if ((entry.wFlags & PROCESS_HEAP_REGION) != 0) { LogReport("Region\n %d bytes committed" \ " %d bytes uncommitted\n First block address: %p" \ " Last block address: %p", entry.Region.dwCommittedSize, entry.Region.dwUnCommittedSize, entry.Region.lpFirstBlock, entry.Region.lpLastBlock); } else if ((entry.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE) != 0) { LogReport("Uncommitted range"); } else { LogReport("Block"); } LogReport(" Data portion begins at: %p\n Size: %d bytes" \ " Overhead: %d bytes\n Region index: %d", entry.lpData, entry.cbData, entry.cbOverhead, entry.iRegionIndex); } // LastError = GetLastError(); // if (LastError != ERROR_NO_MORE_ITEMS) { // _tprintf(TEXT("HeapWalk failed with LastError %d."), LastError); // } return; struct TypeTag {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag> heap_type; struct TypeTag1 {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag1> heap_type1; struct TypeTag2 {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag2> heap_type2; auto ptr = HostAlloc(heap_type, 47); HostFree(heap_type, ptr); HostAlloc(heap_type, 42); { const auto stat = heap_type::get_stat(); LogReport("stat alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } { const auto stat = heap_type1::get_stat(); LogReport("stat1 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat1 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat1 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } HostAlloc(heap_type1, 17); HostAlloc(heap_type1, 12); HostAlloc(heap_type2, 71); HostAlloc(heap_type2, 22); { const auto stat = heap_type1::get_stat(); LogReport("stat1 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat1 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat1 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } { const auto stat = heap_type2::get_stat(); LogReport("stat2 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat2 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat2 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } }
CVariant CKadOperation::AddCallRes(const CVariant& CallRes, CKadNode* pNode) { SOpProgress* pProgress = GetProgress(pNode); CVariant FilteredRes = CallRes.Clone(false); // Make a Shellow Copy const CVariant& Results = CallRes["RET"]; CVariant Filtered; for(uint32 i=0; i < Results.Count(); i++) { CVariant Result = Results.At(i).Clone(false); // Make a Shellow Copy const CVariant& XID = Result["XID"]; // this checks if this particular response is the last and and if this node is done if(pProgress) // might be NULL if we filter our own index response right now { SOpStatus &Status = pProgress->Calls[XID]; Status.Results++; if(!Result.Get("MORE")) Status.Done = true; // this marks that no more results are to be expected form this node } SOpStatus* pStatus = NULL; TCallOpMap::iterator I = m_CallMap.find(XID); if(I != m_CallMap.end()) { pStatus = &I->second.Status; pStatus->Results++; // count the response even if it gets filtered lateron if(!pStatus->Done) pStatus->Done = IsDone(SOpProgress::GetCalls, XID); } if(m_pOperator) { CKadOperator::TRequestMap& ResuestMap = m_pOperator->GetRequests(); CKadOperator::TRequestMap::iterator I = ResuestMap.find(XID); if(I != ResuestMap.end()) // this should not fail { SOpStatus* pAuxStatus = &I->second.Status; pAuxStatus->Results++; // count the response even if it gets filtered lateron if(!pAuxStatus->Done) pAuxStatus->Done = IsDone(SOpProgress::GetCalls, XID); } } if(!Result.Has("ERR")) { if(m_pOperator && m_pOperator->IsValid()) { try { if(m_pOperator->AddCallRes(Result["RET"], XID)) continue; // intercepted response - Note: if we add a response to this request now it wil be marked as no more results if thats so } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); } } } //else // LogLine(LOG_ERROR | LOG_DEBUG, L"Got Execution Error %s", Result["ERR"].To<wstring>().c_str()); // check if this is a call we issued, that is one not present in the call map, in that case its never to be relayed if(pStatus) { // UpdateMore sets the "MORE" flag on the packet we relay further down to the source, and checks if we considder this request done if(!pStatus->Done) Result.Insert("MORE", true); else Result.Remove("MORE"); Filtered.Append(Result); } } if(m_pOperator) // add new result to the filtered list Filtered.Merge(m_pOperator->GetResponses()); FilteredRes.Insert("RET", Filtered); return FilteredRes; }
void CKadOperation::Stop() { CKadLookup::Stop(); LogReport(LOG_INFO, L"Stopped Operation"); }