void obtain() { if (!m_file_lock.get()) { THROW_EX(RuntimeError, "Trying to obtain a lock on an invalid LockFile object"); } if (!m_file_lock->obtain(m_lock_type)) { THROW_EX(RuntimeError, "Unable to obtain a file lock."); } }
boost::shared_ptr<ClassAdWrapper> EventIterator::next() { if (m_done) { if (m_blocking) { wait_internal(-1); } else { int fd = fileno(m_source); struct stat buf; if ((-1 == fstat(fd, &buf)) || (buf.st_size == m_done)) { THROW_EX(StopIteration, "All events processed"); } reset_to(m_done); } } boost::shared_ptr<ULogEvent> new_event; boost::shared_ptr<ClassAdWrapper> output(new ClassAdWrapper()); ULogEventOutcome retval; ULogEvent *tmp_event = NULL; retval = m_reader->readEvent(tmp_event); new_event.reset(tmp_event); classad::ClassAd *tmp_ad; // Bug workaround: the last event generates ULOG_RD_ERROR on line 0. switch (retval) { case ULOG_OK: tmp_ad = reinterpret_cast<classad::ClassAd*>(new_event->toClassAd()); if (tmp_ad) { output->CopyFrom(*tmp_ad); delete tmp_ad; } return output; // NOTE: ULOG_RD_ERROR is always done on the last event with an error on line 0 // How do we differentiate "empty file" versus a real parse error on line 0? case ULOG_NO_EVENT: m_done = ftell(m_source); THROW_EX(StopIteration, "All events processed"); break; case ULOG_RD_ERROR: case ULOG_MISSED_EVENT: case ULOG_UNK_ERROR: default: THROW_EX(ValueError, "Unable to parse input stream into a HTCondor event."); } return output; }
bool InstallerSession::ExpandRegistryVariable(const std::wstring& variable, std::wstring& value) { std::vector<std::wstring> parts = DVLib::split(variable, L"\\"); if (parts.size() < 2) THROW_EX(L"Invalid registry path '" << variable << L"'"); // hkey ULONG ulFlags = 0; std::vector<std::wstring> hkey_parts = DVLib::split(parts[0], L":", 2); HKEY hkey = DVLib::wstring2HKEY(hkey_parts[0]); DVLib::OperatingSystem type = DVLib::GetOperatingSystemVersion(); if (type >= DVLib::winXP) { if (hkey_parts.size() > 1) { if (hkey_parts[1] == L"WOW64_64") ulFlags |= KEY_WOW64_64KEY; else if (hkey_parts[1] == L"WOW64_32") ulFlags |= KEY_WOW64_32KEY; else THROW_EX(L"Invalid WOW option '" << hkey_parts[1] << L"' in '" << variable << L"'"); } } parts.erase(parts.begin()); // key name std::wstring key_name; if (parts.size() > 1) { key_name = parts[parts.size() - 1]; parts.erase(parts.end() - 1); } // path std::wstring key_path = DVLib::join(parts, L"\\"); if (! DVLib::RegistryValueExists(hkey, key_path, key_name, ulFlags)) { return false; } DWORD dwType = DVLib::RegistryGetValueType(hkey, key_path, key_name, ulFlags); switch(dwType) { case REG_SZ: value = DVLib::RegistryGetStringValue(hkey, key_path, key_name, ulFlags); break; case REG_DWORD: value = DVLib::towstring(DVLib::RegistryGetDWORDValue(hkey, key_path, key_name, ulFlags)); break; case REG_MULTI_SZ: value = DVLib::join(DVLib::RegistryGetMultiStringValue(hkey, key_path, key_name, ulFlags), L","); break; default: THROW_EX(L"Registry value '" << key_path << L"\\" << key_name << L"' is of unsupported type " << dwType); } return true; }
void resume() { if (m_claim.empty()) {THROW_EX(ValueError, "No claim set for object.");} DCStartd startd(m_addr.c_str()); startd.setClaimId(m_claim); compat_classad::ClassAd reply; bool rval; { condor::ModuleLock ml; rval = startd.resumeClaim(&reply, 20); } if (!rval) {THROW_EX(RuntimeError, "Sartd failed to resume claim.");} }
void deactivate(VacateType vacate_type) { if (m_claim.empty()) {THROW_EX(ValueError, "No claim set for object.");} DCStartd startd(m_addr.c_str()); startd.setClaimId(m_claim); compat_classad::ClassAd reply; bool rval; { condor::ModuleLock ml; rval = startd.deactivateClaim(vacate_type, &reply, 20); } if (!rval) {THROW_EX(RuntimeError, "Startd failed to deactivate claim.");} }
const char* toString(SerializationVersion version) { switch (version) { case SerializationVersion::VER3: return "VER3"; default: THROW_EX() << "Unknown serialization version: " << static_cast<int>(version); } }
void FileAttributes::Load(TiXmlElement * node) { CHECK_BOOL(node != NULL, L"Expected 'fileattributes' node"); CHECK_BOOL(0 == strcmp(node->Value(), "fileattributes"), L"Expected 'fileattributes' node, got '" << DVLib::string2wstring(node->Value()) << L"'"); TiXmlNode * child = NULL; while( (child = node->IterateChildren(child)) != NULL ) { TiXmlElement * child_element = child->ToElement(); if (child_element == NULL) continue; if (strcmp(child_element->Value(), "fileattribute") == 0) { FileAttributePtr fileattribute(new FileAttribute()); fileattribute->Load(child_element); (* this)[fileattribute->name] = fileattribute; } else { THROW_EX(L"Unexpected node '" << child_element->Value() << L"'"); } } LOG(L"Read " << size() << L" file attribute(s)"); }
bool DVLib::IsInOperatingSystemInRange(OperatingSystem os, const std::wstring& os_filter, OperatingSystem l, OperatingSystem r) { if (!os_filter.empty()) { if (l != winNone || r != winNone) { THROW_EX(L"Conflicting os_filter=" << os_filter << L", os_filter_min=" << DVLib::os2wstring(l) << L", os_filter_max=" << DVLib::os2wstring(r)); } return IsOperatingSystemID(os, os_filter); } else if (l != winNone && r != winNone) { return os >= l && os <= r; } else if (l != winNone) { return os >= l; } else if (r != winNone) { return os <= r; } return true; }
BOOL CLanguageSelectorDialog::OnInitDialog() { CDialog::OnInitDialog(); LOG(L"Opening language selector dialog '" << m_Title << L"'"); m_btnCancel.SetWindowText(m_CancelText.c_str()); m_btnOK.SetWindowText(m_OKText.c_str()); SetWindowText(m_Title.c_str()); DVLib::LcidType lcidType = InstallerSession::Instance->lcidtype; LCID lcid = DVLib::GetOperatingSystemLCID( lcidType ); int index = -1; for each(const ConfigurationPtr& configuration in m_Configurations) { // First configuration that match machine language? if( -1 == index && configuration->IsSupported( lcid ) ) { // Remember index of first configuration to select language in list. index = std::find( m_Configurations.begin(), m_Configurations.end(), configuration ) - m_Configurations.begin(); } m_listLanguages.AddString(configuration->GetLanguageString().c_str()); m_listLanguages.SetItemDataPtr(m_listLanguages.GetCount() - 1, static_cast<LPVOID>(get(configuration))); } if (m_listLanguages.GetCount() == 0) { THROW_EX(L"No languages are available for language selection"); } m_listLanguages.SetCurSel( -1 == index ? 0 : index ); return TRUE; }
void STSO::indicateRead(Isa100::ASL::Services::PrimitiveIndicationPointer indication) { ASL::PDU::ReadRequestPDUPointer readRequest = PDUUtils::extractReadRequest(indication->apduRequest); if ((int)readRequest->targetAttribute.attributeID == (int)STSOAttributeID::Current_UTC_Adjustment) { Device* device = engine->getDevice( engine->getAddress32(indication->clientNetworkAddress)); if (device) { NetworkOrderStream stream; stream.write(SmSettingsLogic::instance().currentUTCAdjustment); sendReadResponseToRequester(indication, SFC::success, BytesPointer(new Bytes(stream.ostream.str())), jobFinished); } else { sendReadResponseToRequester(indication, SFC::objectAccessDenied, BytesPointer(new Bytes()), jobFinished); } } else if ((int)readRequest->targetAttribute.attributeID == (int)STSOAttributeID::Next_UTC_Adjustment_Time) { NetworkOrderStream stream; stream.write(SmSettingsLogic::instance().nextUTCAdjustmentTime); sendReadResponseToRequester(indication, SFC::success, BytesPointer(new Bytes(stream.ostream.str())), jobFinished); } else if ((int)readRequest->targetAttribute.attributeID == (int)STSOAttributeID::Next_UTC_Adjustment) { NetworkOrderStream stream; stream.write(SmSettingsLogic::instance().nextUTCAdjustment); sendReadResponseToRequester(indication, SFC::success, BytesPointer(new Bytes(stream.ostream.str())), jobFinished); } else { THROW_EX(NE::Common::NEException, "Unknown attribute id: " << (int)readRequest->targetAttribute.attributeID); sendReadResponseToRequester(indication, SFC::invalidArgument, BytesPointer(new Bytes()), jobFinished); } }
SimilarFinder* SimilarFinder::instance() { if (instance_ == 0) { THROW_EX("SimilarFinder is not instantiated"); } return instance_; }
void CmdComponent::Exec() { std::wstring l_command; switch(InstallerSession::Instance->sequence) { case SequenceInstall: l_command = InstallUILevelSetting::Instance->GetCommand( command, command_basic, command_silent); break; case SequenceUninstall: l_command = InstallUILevelSetting::Instance->GetCommand( uninstall_command, uninstall_command_basic, uninstall_command_silent); break; default: THROW_EX(L"Unsupported install sequence: " << InstallerSession::Instance->sequence << L"."); } std::wstring additional_cmd = GetAdditionalCmd(); if (! additional_cmd.empty()) { l_command.append(L" "); l_command.append(additional_cmd); } l_command = InstallerSession::Instance->ExpandUserVariables(l_command); LOG(L"Executing: " << l_command); ProcessComponent::ExecCmd(l_command, execution_method, disable_wow64_fs_redirection); };
void release() { if (!m_file_lock.get()) { THROW_EX(RuntimeError, "Trying to release a lock on an invalid LockFile object"); } m_file_lock->release(); }
std::shared_ptr<IObject> CanvasLayout::getIObjectSPtr(IObject* obj) const { for (auto it = m_objects.begin(); it != m_objects.end(); ++it) { if (it->second.get() == obj) return it->second; } THROW_EX() << "Can't find shared_ptr to object by raw pointer"; }
HKEY DVLib::wstring2HKEY(const std::wstring& key) { for(int i = 0; i < ARRAYSIZE(HKEY2wstringMap); i++) { if (HKEY2wstringMap[i].name == key) return HKEY2wstringMap[i].value; } THROW_EX("Unknown HKEY: " << key); }
std::wstring DVLib::HKEY2wstring(HKEY root) { for(int i = 0; i < ARRAYSIZE(HKEY2wstringMap); i++) { if (HKEY2wstringMap[i].value == root) return HKEY2wstringMap[i].name; } THROW_EX("Unknown HKEY: " << root); }
int LinearLayout::addObject(const std::shared_ptr<IObject>& obj) { auto* objPosition = dynamic_cast<OffsettedPosition*>(obj.get()); if (!objPosition) THROW_EX() << "Can't add object with not OffsettedPosition"; objPosition->setRelativeOffset(m_skin->createOffset(m_list.size())); m_list.addObject(obj); update(); return static_cast<int>(m_list.size()) - 1; }
std::wstring DVLib::cem2wstring(DVLib::CommandExecutionMethod commandExecutionMethod) { for (int i = 0; i < ARRAYSIZE(CommandExecutionMethod2wstringMap); i++) { if (CommandExecutionMethod2wstringMap[i].command_execution_method == commandExecutionMethod) return CommandExecutionMethod2wstringMap[i].name; } THROW_EX(L"Invalid command execution method: " << commandExecutionMethod); }
void InstantVisibilityChange::load(const PropertiesRegister& props) { if (m_objName.empty()) { m_drawable = dynamic_cast<IDrawable*>(props.holder()); if (!m_drawable) THROW_EX() << "Animation holder is not drawable, can't change visibility"; return; } m_drawable = props.getObject<IDrawable>(m_objName); }
void activate(boost::python::object ad_obj) { if (m_claim.empty()) {THROW_EX(ValueError, "No claim set for object.");} compat_classad::ClassAd ad = boost::python::extract<ClassAdWrapper>(ad_obj)(); if (ad.find(ATTR_JOB_KEYWORD) == ad.end()) { ad.InsertAttr(ATTR_HAS_JOB_AD, true); } DCStartd startd(m_addr.c_str()); startd.setClaimId(m_claim); compat_classad::ClassAd reply; int irval; { condor::ModuleLock ml; irval = startd.activateClaim(&ad, &reply, 20); } if (irval != OK) {THROW_EX(RuntimeError, "Startd failed to activate claim.");} }
void EventIterator::wait_internal(int timeout_ms) { if (m_done == 0) {return;} off_t prev_done = m_done; if (timeout_ms == 0) { reset_to(prev_done); return; } int time_remaining = timeout_ms; int step = m_step; fflush(m_source); clearerr(m_source); int fd = fileno(m_source); struct stat result; while ((-1 != fstat(fd, &result)) && (result.st_size == m_done)) { struct pollfd fd; fd.fd = watch(); fd.events = POLLIN; Py_BEGIN_ALLOW_THREADS if (time_remaining != -1 && time_remaining < 1000) {step = time_remaining;} if (fd.fd == -1) { struct timeval tv; tv.tv_sec = step / 1000; tv.tv_usec = 1000*(step % 1000); select(1,NULL,NULL,NULL,&tv); } else { ::poll(&fd, 1, step); } Py_END_ALLOW_THREADS if (PyErr_CheckSignals() == -1) { boost::python::throw_error_already_set(); } time_remaining -= step; if (time_remaining <= 0) { errno = 0; break; } } if (errno) { THROW_EX(IOError, "Failure when checking file size of event log."); } reset_to(prev_done); }
GLuint Shader::load() { std::string shaderStr = loadTextFile(m_name); m_id = glCreateShader(m_type); if (m_id == 0) THROW_EX() << "Can't create shader " << m_name; const char* data = &shaderStr.front(); GLint len = (GLint)shaderStr.length(); glShaderSource(m_id, 1, &data, &len); glCompileShader(m_id); GLint success; glGetShaderiv(m_id, GL_COMPILE_STATUS, &success); if (!success) { GLchar buf[1024]; glGetShaderInfoLog(m_id, sizeof(buf), NULL, buf); THROW_EX() << "Error while compiling shader " << m_name << ": " << buf; } return m_id; }
JNIEXPORT jlong JNICALL Java_org_zoy_caca_Dither_createDither(JNIEnv *env, jclass cls, jint bpp, jint w, jint h, jint pitch, jint rmask, jint gmask, jint bmask, jint amask) { caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask); if(dither == NULL) { THROW_EX("Cannot create a new Dither"); return 0; } return (jlong)dither; }
void ConfigFile::LoadFile(const std::wstring& filename) { LOG(L"Loading configuration file: " << filename); std::vector<char> xml = DVLib::FileReadToEnd(filename); xml.push_back(0); // null-terminate LOG(L"Parsing: " << DVLib::FormatBytesW(xml.size())); if (xml.size() == 0) THROW_EX(L"Error loading file: " << filename << L", file is empty"); m_XmlDocument.Parse(& * xml.begin()); CHECK_BOOL(! m_XmlDocument.Error(), L"Error loading configuration: " << DVLib::string2wstring(m_XmlDocument.ErrorDesc()) << L" at " << m_XmlDocument.ErrorRow() << L":" << m_XmlDocument.ErrorCol()); Load(m_XmlDocument.FirstChildElement()); m_filename = filename; }
void LinearLayout::insertObject(int id, const std::shared_ptr<IObject>& obj) { size_t index = static_cast<size_t>(id); if (index == m_list.size()) { addObject(obj); return; } auto* objPosition = dynamic_cast<OffsettedPosition*>(obj.get()); if (!objPosition) THROW_EX() << "Can't insert object with not OffsettedPosition"; objPosition->setRelativeOffset(m_skin->createOffset(index)); m_list.replaceObject(id, obj); update(); }
void ExtractComponent::OnProgressInfo(Cabinet::CExtract::kProgressInfo* pk_Progress, void* p_Param) { ExtractComponent * extractComponent = static_cast<ExtractComponent*>(p_Param); extractComponent->OnStatus(std::wstring(pk_Progress->u16_RelPath) + L" - " + DVLib::FormatMessage(L"%.f%%", pk_Progress->fl_Percent)); if (extractComponent->cancelled) { std::wstring resolved_cancelled_message = extractComponent->cab_cancelled_message; if (resolved_cancelled_message.empty()) resolved_cancelled_message = L"Cancelled by user"; THROW_EX(resolved_cancelled_message); } }
std::wstring MsiComponent::GetCommandLine() const { std::wstring l_command = L"msiexec"; std::wstring l_package; std::wstring l_cmdparameters; switch(InstallerSession::Instance->sequence) { case SequenceInstall: l_package = package.GetValue(); l_cmdparameters = InstallUILevelSetting::Instance->GetCommand( cmdparameters, cmdparameters_basic, cmdparameters_silent); l_command += L" /i"; break; case SequenceUninstall: l_package = uninstall_package.empty() ? package.GetValue() : uninstall_package.GetValue(); l_cmdparameters = InstallUILevelSetting::Instance->GetCommand( uninstall_cmdparameters, uninstall_cmdparameters_basic, uninstall_cmdparameters_silent); l_command += L" /x"; break; default: THROW_EX(L"Unsupported install sequence: " << InstallerSession::Instance->sequence << L"."); } l_command.append(L" "); l_command.append(DVLib::GetQuotedPathOrGuid(l_package)); LOG(L"-- Package: " << l_package); if (! l_cmdparameters.empty()) { LOG(L"-- Additional command-line parameters: " << l_cmdparameters); l_command.append(L" "); l_command.append(l_cmdparameters); } std::wstring additional_cmd = GetAdditionalCmd(); if (! additional_cmd.empty()) { l_command.append(L" "); l_command.append(additional_cmd); } l_command = InstallerSession::Instance->ExpandUserVariables(l_command); return l_command; }
DVLib::CommandExecutionMethod DVLib::wstring2cem(const std::wstring& name, CommandExecutionMethod defaultValue) { if (name.empty()) { return defaultValue; } for (int i = 0; i < ARRAYSIZE(CommandExecutionMethod2wstringMap); i++) { if (CommandExecutionMethod2wstringMap[i].name == name) return CommandExecutionMethod2wstringMap[i].command_execution_method; } THROW_EX(L"Invalid command execution method: " << name); }
void requestCOD(boost::python::object constraint_obj, int lease_duration) { classad_shared_ptr<classad::ExprTree> constraint; boost::python::extract<std::string> constraint_extract(constraint_obj); if (constraint_obj.ptr() == Py_None) {} else if (constraint_extract.check()) { classad::ClassAdParser parser; std::string constraint_str = constraint_extract(); classad::ExprTree *expr_tmp = NULL; if (!parser.ParseExpression(constraint_str, expr_tmp)) {THROW_EX(ValueError, "Failed to parse request requirements expression");} constraint.reset(expr_tmp); } else { constraint.reset(convert_python_to_exprtree(constraint_obj)); } compat_classad::ClassAd ad, reply; if (constraint.get()) { classad::ExprTree *expr_tmp = constraint->Copy(); ad.Insert(ATTR_REQUIREMENTS, expr_tmp); } ad.InsertAttr(ATTR_JOB_LEASE_DURATION, lease_duration); bool rval; DCStartd startd(m_addr.c_str()); { condor::ModuleLock ml; rval = startd.requestClaim(CLAIM_COD, &ad, &reply, 20); } if (!rval) {THROW_EX(RuntimeError, "Failed to request claim from startd.");} if (!reply.EvaluateAttrString(ATTR_CLAIM_ID, m_claim)) {THROW_EX(RuntimeError, "Startd did not return a ClaimId.");} }
std::wstring InstallUILevelSetting::ToString(InstallUILevel value) { switch(value) { case InstallUILevelNotSet: return L""; case InstallUILevelFull: return L"full"; case InstallUILevelBasic: return L"basic"; case InstallUILevelSilent: return L"silent"; default: THROW_EX(L"Unsupported UI level: " << value); } }