void onObserve(const HeaderOptions &headerOption , const OCRepresentation& rep , const int& eCode, const int& sequenceNumber) { std::cout << "onObserve" << std::endl; // if(eCode == SUCCESS_RESPONSE) if(eCode <= OC_STACK_RESOURCE_DELETED) { AttributeMap attributeMap = rep.getAttributeMap(); for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { if(attributeMap.find(it->first) == attributeMap.end()) { return; } } if(rep.getUri().empty()) { cout << "uri is null\n"; return; } std::cout << std::endl; std::cout << "========================================================" << std::endl; std::cout << "Receive OBSERVE RESULT:" << std::endl; std::cout << "\tSequenceNumber: " << sequenceNumber << std::endl; for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { std::cout << "\tAttribute name: " << it->first << " value: "; for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { std::cout << "\t" << *valueItr << " "; } std::cout << std::endl; } if(observe_count() > 30) { std::cout << "Cancelling Observe..." << std::endl; OCStackResult result = g_curResource->cancelObserve(); std::cout << "Cancel result: " << result << std::endl; sleep(10); std::cout << "DONE" << std::endl; std::exit(0); } } else { std::cout << "onObserve Response error: " << eCode << std::endl; std::exit(-1); } }
void KeyHandler::startElement(const QName& qname, const AttributeMap& attributes) { _result.reset(new Key()); auto number = attributes.find(kNumberAttribute); if (number != attributes.end()) _result->setNumber(lxml::IntegerHandler::parseInteger(number->second)); auto print = attributes.find(kPrintObjectAttribute); if (print != attributes.end()) _result->setPrintObject(print->second == "no" ? false : true); }
void MordentHandler::startElement(const lxml::QName& qname, const AttributeMap& attributes) { _result.reset(new Mordent()); auto placement = attributes.find(kPlacementAttribute); if (placement != attributes.end()) _result->setPlacement(presentOptional(EmptyPlacementHandler::placementFromString(placement->second))); auto longv = attributes.find(kLongAttribute); if (longv != attributes.end()) _result->setLong(longv->second == "yes"); }
void onPut(const OCRepresentation& rep , const int eCode) { if(eCode == SUCCESS_RESPONSE) { std::cout << "PUT request was successful" << std::endl; AttributeMap attributeMap = rep.getAttributeMap(); for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { std::cout << "\tAttribute name: " << it->first << " value: "; for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { std::cout << "\t" << *valueItr << " "; } std::cout << std::endl; } std::vector< OCRepresentation > children = rep.getChildren(); for(auto oit = children.begin() ; oit != children.end() ; ++oit) { attributeMap = oit->getAttributeMap(); for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { std::cout << "\tAttribute name: " << it->first << " value: "; for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { std::cout << "\t" << *valueItr << " "; } std::cout << std::endl; } } if(OBSERVE_TYPE_TO_USE == ObserveType::Observe) std::cout << std::endl << "Observe is used." << std::endl << std::endl; else if(OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll) std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl; QueryParamsMap test; g_curResource->observe(ObserveType::Observe , test , &onObserve); } else { std::cout << "onPut Response error: " << eCode << std::endl; std::exit(-1); } }
void onobserve() { oicappData *ad = g_oicObserveAd; AttributeMap attributeMap = g_curAttributeMap; std::string tmpStr[2]; int index = 0; for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { tmpStr[index] = it->first; tmpStr[index].append(" : "); for(auto value = it->second.begin() ; value != it->second.end() ; ++value) { tmpStr[index].append(*value); } index++; } DBG("%s" , tmpStr[0].c_str()); DBG("%s" , tmpStr[1].c_str()); _gl_update_item(ad , strdup(tmpStr[0].c_str()) , ad->itemConsumerTemp); _gl_update_item(ad , strdup(tmpStr[1].c_str()) , ad->itemConsumerHumid); }
bool TemplateBuilder::hasAttribute( const AttributeMap& attributes, const std::string& name) { return attributes.find(name) != attributes.end(); }
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Feature featureId, const AttributeMap &map, const std::string &attributeName) { StyleSheetTable::AttributeMap::const_iterator it = map.find(attributeName); if (it != map.end()) { ::trySetLength(entry, featureId, it->second); return; } }
// callback handler on GET request void onGet(const HeaderOptions &headerOption , const OCRepresentation& rep , const int eCode) { if(eCode == SUCCESS_RESPONSE) { std::cout << "GET request was successful" << std::endl; AttributeMap attributeMap = rep.getAttributeMap(); std::cout << "Resource URI: " << rep.getUri() << std::endl; for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { std::cout << "\tAttribute name: " << it->first << " value: "; for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { std::cout << "\t" << *valueItr << " "; } std::cout << std::endl; } std::vector< OCRepresentation > children = rep.getChildren(); for(auto oit = children.begin() ; oit != children.end() ; ++oit) { std::cout << "Child Resource URI: " << oit->getUri() << std::endl; attributeMap = oit->getAttributeMap(); for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { std::cout << "\tAttribute name: " << it->first << " value: "; for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { std::cout << "\t" << *valueItr << " "; } std::cout << std::endl; } } } else { std::cout << "onGET Response error: " << eCode << std::endl; std::exit(-1); } }
void PartHandler::startElement(const QName& qname, const AttributeMap& attributes) { _result.reset(new Part()); _measureIndex = 0; auto id = attributes.find(kIdTag); if (id != attributes.end()) _result->setId(id->second); }
void printAttributeMap(const AttributeMap attributeMap) { for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) { DBG("\tAttribute name: %s" , it->first.c_str()); for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) { DBG("\t\tAttribute value: %s" , (*valueItr).c_str()); } } }
void PedalHandler::startElement(const lxml::QName& qname, const AttributeMap& attributes) { using dom::presentOptional; using lxml::DoubleHandler; using lxml::StringHandler; _result.reset(new Pedal{}); _result->position = PositionFactory::buildFromAttributes(attributes); auto type = attributes.find(kTypeAttribute); if (type != attributes.end()) _result->setType(typeFromString(type->second)); auto line = attributes.find(kLineAttribute); if (line != attributes.end()) _result->setLine(presentOptional(line->second == "yes")); auto sign = attributes.find(kSignAttribute); if (sign != attributes.end()) _result->setSign(presentOptional(sign->second == "yes")); }
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName) { StyleSheetTable::AttributeMap::const_iterator it = map.find(attributeName); if (it == map.end()) { return; } const std::vector<std::string> &values = it->second; if (!values.empty() && !values[0].empty()) { short size; ZLTextStyleEntry::SizeUnit unit; parseLength(values[0], size, unit); entry.setLength(name, size, unit); } }
void WedgeHandler::startElement(const QName& qname, const AttributeMap& attributes) { using dom::presentOptional; using lxml::DoubleHandler; _result.reset(new Wedge{}); _result->position = PositionFactory::buildFromAttributes(attributes); auto type = attributes.find(kTypeAttribute); if (type != attributes.end()) _result->setType(typeFromString(type->second)); auto number = attributes.find(kNumberAttribute); if (number != attributes.end()) _result->setNumber(lxml::IntegerHandler::parseInteger(number->second)); auto spread = attributes.find(kSpreadAttribute); if (spread != attributes.end()) { auto spreadValue = DoubleHandler::parseDouble(spread->second); if (spreadValue > 0) _result->setSpread(spreadValue); } }
void SerializingParser::handleStartElement(const std::string& tag, const std::string& ns, const AttributeMap& attributes) { boost::shared_ptr<XMLElement> element(new XMLElement(tag, ns)); for (AttributeMap::const_iterator i = attributes.begin(); i != attributes.end(); ++i) { element->setAttribute((*i).first, (*i).second); } if (elementStack_.empty()) { rootElement_ = element; } else { (*(elementStack_.end() - 1))->addNode(element); } elementStack_.push_back(element); }
bool TemplateBuilder::getRequiredBooleanAttribute( const AttributeMap& attributes, const std::string& name) { AttributeMap::const_iterator it = attributes.find(name); if(it == attributes.end()) { std::string errMsg; errMsg += "[ERR S1] Missing required attribute \"" + name + "\""; throw TemplateDefinitionError(errMsg); } return getOptionalBooleanAttribute(attributes, name, false); }
bool TemplateBuilder::getOptionalAttribute( const AttributeMap& attributes, const std::string& name, std::string & result ) { AttributeMap::const_iterator it = attributes.find(name); if(it == attributes.end()) { return false; } result = it->second; return true; }
void writeSparse(QFile& file, const AttributeMap& data) { FNTRACE("ini", "", "writeSparse", QString("file %1, %2 rows of data").arg(file.fileName()).arg(data.size())); if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) ETHROW(Exception(QString("Unable to open %1 for writing.").arg(file.fileName()))); file.resize(0); QTextStream fout(&file); int max_key_length = 0; for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter) { if (iter.key().length() > max_key_length) max_key_length = iter.key().length(); } for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter) { fout << iter.key(); for (int i = iter.key().length(); i < max_key_length; ++i) fout << ' '; fout << " = " << iter.value() << "\n"; } }
void IQParser::handleStanzaAttributes(const AttributeMap& attributes) { AttributeMap::const_iterator type = attributes.find("type"); if (type != attributes.end()) { if (type->second == "set") { getStanzaGeneric()->setType(IQ::Set); } else if (type->second == "get") { getStanzaGeneric()->setType(IQ::Get); } else if (type->second == "result") { getStanzaGeneric()->setType(IQ::Result); } else if (type->second == "error") { getStanzaGeneric()->setType(IQ::Error); } else { std::cerr << "Unknown IQ type: " << type->second << std::endl; getStanzaGeneric()->setType(IQ::Get); } } }
bool TemplateBuilder::getOptionalBooleanAttribute( const AttributeMap& attributes, const std::string& name, bool defaultResult) { bool result = defaultResult; AttributeMap::const_iterator it = attributes.find(name); if(it != attributes.end()) { char yn = it->second[0]; yn = toupper(yn); if(yn != 'Y' && yn != 'N' && yn != 'T' && yn != 'F') { std::stringstream msg; msg << "[ERR S1] Invalid boolean \"" << name << "=\"" << it->second; throw TemplateDefinitionError(msg.str()); } result = (yn == 'Y' || yn == 'T'); } return result; }
void scanForWantedComponents(const AttributeMap &attributeMap) { // [EGL 1.5] section 3.4.1.2 page 30 // Sorting rule #3: by larger total number of color bits, not considering // components that are 0 or don't-care. for (auto attribIter = attributeMap.begin(); attribIter != attributeMap.end(); attribIter++) { EGLint attributeKey = attribIter->first; EGLint attributeValue = attribIter->second; if (attributeKey != 0 && attributeValue != EGL_DONT_CARE) { switch (attributeKey) { case EGL_RED_SIZE: mWantRed = true; break; case EGL_GREEN_SIZE: mWantGreen = true; break; case EGL_BLUE_SIZE: mWantBlue = true; break; case EGL_ALPHA_SIZE: mWantAlpha = true; break; case EGL_LUMINANCE_SIZE: mWantLuminance = true; break; } } } }
void XMLWriter::writeAttributes(const AttributeMap& attributeMap) { for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it) { if ((_options & PRETTY_PRINT) && (_options & PRETTY_PRINT_ATTRIBUTES)) { writeNewLine(); writeIndent(_depth + 1); } else { writeMarkup(MARKUP_SPACE); } writeXML(it->first); writeMarkup(MARKUP_EQQUOT); for (XMLString::const_iterator itc = it->second.begin(); itc != it->second.end(); ++itc) { XMLChar c = *itc; switch (c) { case '"': writeMarkup(MARKUP_QUOTENC); break; case '\'': writeMarkup(MARKUP_APOSENC); break; case '&': writeMarkup(MARKUP_AMPENC); break; case '<': writeMarkup(MARKUP_LTENC); break; case '>': writeMarkup(MARKUP_GTENC); break; case '\t': writeMarkup(MARKUP_TABENC); break; case '\r': writeMarkup(MARKUP_CRENC); break; case '\n': writeMarkup(MARKUP_LFENC); break; default: if (c >= 0 && c < 32) throw XMLException("Invalid character token."); else writeXML(c); } } writeMarkup(MARKUP_QUOT); } }
Error ValidateCreateImageKHR(const Display *display, gl::Context *context, EGLenum target, EGLClientBuffer buffer, const AttributeMap &attributes) { Error error = ValidateContext(display, context); if (error.isError()) { return error; } const DisplayExtensions &displayExtensions = display->getExtensions(); if (!displayExtensions.imageBase && !displayExtensions.image) { // It is out of spec what happens when calling an extension function when the extension is // not available. // EGL_BAD_DISPLAY seems like a reasonable error. return Error(EGL_BAD_DISPLAY, "EGL_KHR_image not supported."); } // TODO(geofflang): Complete validation from EGL_KHR_image_base: // If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is itself an // EGLImage sibling, the error EGL_BAD_ACCESS is generated. for (AttributeMap::const_iterator attributeIter = attributes.begin(); attributeIter != attributes.end(); attributeIter++) { EGLint attribute = attributeIter->first; EGLint value = attributeIter->second; switch (attribute) { case EGL_IMAGE_PRESERVED_KHR: switch (value) { case EGL_TRUE: case EGL_FALSE: break; default: return Error(EGL_BAD_PARAMETER, "EGL_IMAGE_PRESERVED_KHR must be EGL_TRUE or EGL_FALSE."); } break; case EGL_GL_TEXTURE_LEVEL_KHR: if (!displayExtensions.glTexture2DImage && !displayExtensions.glTextureCubemapImage && !displayExtensions.glTexture3DImage) { return Error(EGL_BAD_PARAMETER, "EGL_GL_TEXTURE_LEVEL_KHR cannot be used without " "KHR_gl_texture_*_image support."); } if (value < 0) { return Error(EGL_BAD_PARAMETER, "EGL_GL_TEXTURE_LEVEL_KHR cannot be negative."); } break; case EGL_GL_TEXTURE_ZOFFSET_KHR: if (!displayExtensions.glTexture3DImage) { return Error(EGL_BAD_PARAMETER, "EGL_GL_TEXTURE_ZOFFSET_KHR cannot be used without " "KHR_gl_texture_3D_image support."); } break; default: return Error(EGL_BAD_PARAMETER, "invalid attribute: 0x%X", attribute); } } switch (target) { case EGL_GL_TEXTURE_2D_KHR: { if (!displayExtensions.glTexture2DImage) { return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_2D_image not supported."); } if (buffer == 0) { return Error(EGL_BAD_PARAMETER, "buffer cannot reference a 2D texture with the name 0."); } const gl::Texture *texture = context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer)); if (texture == nullptr || texture->getTarget() != GL_TEXTURE_2D) { return Error(EGL_BAD_PARAMETER, "target is not a 2D texture."); } if (texture->getBoundSurface() != nullptr) { return Error(EGL_BAD_ACCESS, "texture has a surface bound to it."); } EGLint level = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0); if (texture->getWidth(GL_TEXTURE_2D, static_cast<size_t>(level)) == 0 || texture->getHeight(GL_TEXTURE_2D, static_cast<size_t>(level)) == 0) { return Error(EGL_BAD_PARAMETER, "target 2D texture does not have a valid size at specified level."); } if (level > 0 && (!texture->isMipmapComplete() || static_cast<size_t>(level) >= texture->getMipCompleteLevels())) { return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero."); } if (level == 0 && !texture->isMipmapComplete() && TextureHasNonZeroMipLevelsSpecified(context, texture)) { return Error(EGL_BAD_PARAMETER, "if level is zero and the texture is incomplete, it must have no mip " "levels specified except zero."); } } break; case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: { if (!displayExtensions.glTextureCubemapImage) { return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_cubemap_image not supported."); } if (buffer == 0) { return Error(EGL_BAD_PARAMETER, "buffer cannot reference a cubemap texture with the name 0."); } const gl::Texture *texture = context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer)); if (texture == nullptr || texture->getTarget() != GL_TEXTURE_CUBE_MAP) { return Error(EGL_BAD_PARAMETER, "target is not a cubemap texture."); } if (texture->getBoundSurface() != nullptr) { return Error(EGL_BAD_ACCESS, "texture has a surface bound to it."); } EGLint level = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0); GLenum cubeMapFace = egl_gl::EGLCubeMapTargetToGLCubeMapTarget(target); if (texture->getWidth(cubeMapFace, static_cast<size_t>(level)) == 0 || texture->getHeight(cubeMapFace, static_cast<size_t>(level)) == 0) { return Error(EGL_BAD_PARAMETER, "target cubemap texture does not have a valid size at specified level " "and face."); } if (level > 0 && (!texture->isMipmapComplete() || static_cast<size_t>(level) >= texture->getMipCompleteLevels())) { return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero."); } if (level == 0 && !texture->isMipmapComplete() && TextureHasNonZeroMipLevelsSpecified(context, texture)) { return Error(EGL_BAD_PARAMETER, "if level is zero and the texture is incomplete, it must have no mip " "levels specified except zero."); } if (level == 0 && !texture->isMipmapComplete() && CubeTextureHasUnspecifiedLevel0Face(texture)) { return Error(EGL_BAD_PARAMETER, "if level is zero and the texture is incomplete, it must have all of " "its faces specified at level zero."); } } break; case EGL_GL_TEXTURE_3D_KHR: { if (!displayExtensions.glTexture3DImage) { return Error(EGL_BAD_PARAMETER, "KHR_gl_texture_3D_image not supported."); } if (buffer == 0) { return Error(EGL_BAD_PARAMETER, "buffer cannot reference a 3D texture with the name 0."); } const gl::Texture *texture = context->getTexture(egl_gl::EGLClientBufferToGLObjectHandle(buffer)); if (texture == nullptr || texture->getTarget() != GL_TEXTURE_3D) { return Error(EGL_BAD_PARAMETER, "target is not a 3D texture."); } if (texture->getBoundSurface() != nullptr) { return Error(EGL_BAD_ACCESS, "texture has a surface bound to it."); } EGLint level = attributes.get(EGL_GL_TEXTURE_LEVEL_KHR, 0); EGLint zOffset = attributes.get(EGL_GL_TEXTURE_ZOFFSET_KHR, 0); if (texture->getWidth(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0 || texture->getHeight(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0 || texture->getDepth(GL_TEXTURE_3D, static_cast<size_t>(level)) == 0) { return Error(EGL_BAD_PARAMETER, "target 3D texture does not have a valid size at specified level."); } if (static_cast<size_t>(zOffset) >= texture->getDepth(GL_TEXTURE_3D, static_cast<size_t>(level))) { return Error(EGL_BAD_PARAMETER, "target 3D texture does not have enough layers for the specified Z " "offset at the specified level."); } if (level > 0 && (!texture->isMipmapComplete() || static_cast<size_t>(level) >= texture->getMipCompleteLevels())) { return Error(EGL_BAD_PARAMETER, "texture must be complete if level is non-zero."); } if (level == 0 && !texture->isMipmapComplete() && TextureHasNonZeroMipLevelsSpecified(context, texture)) { return Error(EGL_BAD_PARAMETER, "if level is zero and the texture is incomplete, it must have no mip " "levels specified except zero."); } } break; case EGL_GL_RENDERBUFFER_KHR: { if (!displayExtensions.glRenderbufferImage) { return Error(EGL_BAD_PARAMETER, "KHR_gl_renderbuffer_image not supported."); } if (attributes.contains(EGL_GL_TEXTURE_LEVEL_KHR)) { return Error(EGL_BAD_PARAMETER, "EGL_GL_TEXTURE_LEVEL_KHR cannot be used in conjunction with a " "renderbuffer target."); } if (buffer == 0) { return Error(EGL_BAD_PARAMETER, "buffer cannot reference a renderbuffer with the name 0."); } const gl::Renderbuffer *renderbuffer = context->getRenderbuffer(egl_gl::EGLClientBufferToGLObjectHandle(buffer)); if (renderbuffer == nullptr) { return Error(EGL_BAD_PARAMETER, "target is not a renderbuffer."); } if (renderbuffer->getSamples() > 0) { return Error(EGL_BAD_PARAMETER, "target renderbuffer cannot be multisampled."); } } break; default: return Error(EGL_BAD_PARAMETER, "invalid target: 0x%X", target); } return Error(EGL_SUCCESS); }
Error ValidateCreatePbufferFromClientBuffer(Display *display, EGLenum buftype, EGLClientBuffer buffer, Config *config, const AttributeMap& attributes) { Error error = ValidateConfig(display, config); if (error.isError()) { return error; } const DisplayExtensions &displayExtensions = display->getExtensions(); switch (buftype) { case EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE: if (!displayExtensions.d3dShareHandleClientBuffer) { return Error(EGL_BAD_PARAMETER); } if (buffer == nullptr) { return Error(EGL_BAD_PARAMETER); } break; default: return Error(EGL_BAD_PARAMETER); } for (AttributeMap::const_iterator attributeIter = attributes.begin(); attributeIter != attributes.end(); attributeIter++) { EGLint attribute = attributeIter->first; EGLint value = attributeIter->second; switch (attribute) { case EGL_WIDTH: case EGL_HEIGHT: if (!displayExtensions.d3dShareHandleClientBuffer) { return Error(EGL_BAD_PARAMETER); } if (value < 0) { return Error(EGL_BAD_PARAMETER); } break; case EGL_TEXTURE_FORMAT: switch (value) { case EGL_NO_TEXTURE: case EGL_TEXTURE_RGB: case EGL_TEXTURE_RGBA: break; default: return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_TEXTURE_TARGET: switch (value) { case EGL_NO_TEXTURE: case EGL_TEXTURE_2D: break; default: return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_MIPMAP_TEXTURE: break; default: return Error(EGL_BAD_ATTRIBUTE); } } if (!(config->surfaceType & EGL_PBUFFER_BIT)) { return Error(EGL_BAD_MATCH); } EGLenum textureFormat = attributes.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE); EGLenum textureTarget = attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE); if ((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) || (textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE)) { return Error(EGL_BAD_MATCH); } if ((textureFormat == EGL_TEXTURE_RGB && config->bindToTextureRGB != EGL_TRUE) || (textureFormat == EGL_TEXTURE_RGBA && config->bindToTextureRGBA != EGL_TRUE)) { return Error(EGL_BAD_ATTRIBUTE); } if (buftype == EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE) { EGLint width = attributes.get(EGL_WIDTH, 0); EGLint height = attributes.get(EGL_HEIGHT, 0); if (width == 0 || height == 0) { return Error(EGL_BAD_ATTRIBUTE); } const Caps &caps = display->getCaps(); if (textureFormat != EGL_NO_TEXTURE && !caps.textureNPOT && (!gl::isPow2(width) || !gl::isPow2(height))) { return Error(EGL_BAD_MATCH); } } return Error(EGL_SUCCESS); }
Error ValidateCreatePbufferSurface(Display *display, Config *config, const AttributeMap& attributes) { Error error = ValidateConfig(display, config); if (error.isError()) { return error; } for (AttributeMap::const_iterator attributeIter = attributes.begin(); attributeIter != attributes.end(); attributeIter++) { EGLint attribute = attributeIter->first; EGLint value = attributeIter->second; switch (attribute) { case EGL_WIDTH: case EGL_HEIGHT: if (value < 0) { return Error(EGL_BAD_PARAMETER); } break; case EGL_LARGEST_PBUFFER: break; case EGL_TEXTURE_FORMAT: switch (value) { case EGL_NO_TEXTURE: case EGL_TEXTURE_RGB: case EGL_TEXTURE_RGBA: break; default: return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_TEXTURE_TARGET: switch (value) { case EGL_NO_TEXTURE: case EGL_TEXTURE_2D: break; default: return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_MIPMAP_TEXTURE: break; case EGL_VG_COLORSPACE: break; case EGL_VG_ALPHA_FORMAT: break; default: return Error(EGL_BAD_ATTRIBUTE); } } if (!(config->surfaceType & EGL_PBUFFER_BIT)) { return Error(EGL_BAD_MATCH); } const Caps &caps = display->getCaps(); EGLenum textureFormat = attributes.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE); EGLenum textureTarget = attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE); if ((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) || (textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE)) { return Error(EGL_BAD_MATCH); } if ((textureFormat == EGL_TEXTURE_RGB && config->bindToTextureRGB != EGL_TRUE) || (textureFormat == EGL_TEXTURE_RGBA && config->bindToTextureRGBA != EGL_TRUE)) { return Error(EGL_BAD_ATTRIBUTE); } EGLint width = attributes.get(EGL_WIDTH, 0); EGLint height = attributes.get(EGL_HEIGHT, 0); if (textureFormat != EGL_NO_TEXTURE && !caps.textureNPOT && (!gl::isPow2(width) || !gl::isPow2(height))) { return Error(EGL_BAD_MATCH); } return Error(EGL_SUCCESS); }
Error ValidateCreateWindowSurface(Display *display, Config *config, EGLNativeWindowType window, const AttributeMap& attributes) { Error error = ValidateConfig(display, config); if (error.isError()) { return error; } if (!display->isValidNativeWindow(window)) { return Error(EGL_BAD_NATIVE_WINDOW); } const DisplayExtensions &displayExtensions = display->getExtensions(); for (AttributeMap::const_iterator attributeIter = attributes.begin(); attributeIter != attributes.end(); attributeIter++) { EGLint attribute = attributeIter->first; EGLint value = attributeIter->second; switch (attribute) { case EGL_RENDER_BUFFER: switch (value) { case EGL_BACK_BUFFER: break; case EGL_SINGLE_BUFFER: return Error(EGL_BAD_MATCH); // Rendering directly to front buffer not supported default: return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_POST_SUB_BUFFER_SUPPORTED_NV: if (!displayExtensions.postSubBuffer) { return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_WIDTH: case EGL_HEIGHT: if (!displayExtensions.windowFixedSize) { return Error(EGL_BAD_ATTRIBUTE); } if (value < 0) { return Error(EGL_BAD_PARAMETER); } break; case EGL_FIXED_SIZE_ANGLE: if (!displayExtensions.windowFixedSize) { return Error(EGL_BAD_ATTRIBUTE); } break; case EGL_VG_COLORSPACE: return Error(EGL_BAD_MATCH); case EGL_VG_ALPHA_FORMAT: return Error(EGL_BAD_MATCH); default: return Error(EGL_BAD_ATTRIBUTE); } } if (Display::hasExistingWindowSurface(window)) { return Error(EGL_BAD_ALLOC); } return Error(EGL_SUCCESS); }
Error ValidateCreateContext(Display *display, Config *configuration, gl::Context *shareContext, const AttributeMap& attributes) { Error error = ValidateConfig(display, configuration); if (error.isError()) { return error; } // Get the requested client version (default is 1) and check it is 2 or 3. EGLint clientMajorVersion = 1; EGLint clientMinorVersion = 0; EGLint contextFlags = 0; bool resetNotification = false; bool robustAccess = false; for (AttributeMap::const_iterator attributeIter = attributes.begin(); attributeIter != attributes.end(); attributeIter++) { EGLint attribute = attributeIter->first; EGLint value = attributeIter->second; switch (attribute) { case EGL_CONTEXT_CLIENT_VERSION: clientMajorVersion = value; break; case EGL_CONTEXT_MINOR_VERSION: clientMinorVersion = value; break; case EGL_CONTEXT_FLAGS_KHR: contextFlags = value; break; case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR: // Only valid for OpenGL (non-ES) contexts return Error(EGL_BAD_ATTRIBUTE); case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT: if (!display->getExtensions().createContextRobustness) { return Error(EGL_BAD_ATTRIBUTE); } if (value != EGL_TRUE && value != EGL_FALSE) { return Error(EGL_BAD_ATTRIBUTE); } robustAccess = (value == EGL_TRUE); break; case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR: static_assert(EGL_LOSE_CONTEXT_ON_RESET_EXT == EGL_LOSE_CONTEXT_ON_RESET_KHR, "EGL extension enums not equal."); static_assert(EGL_NO_RESET_NOTIFICATION_EXT == EGL_NO_RESET_NOTIFICATION_KHR, "EGL extension enums not equal."); // same as EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, fall through case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT: if (!display->getExtensions().createContextRobustness) { return Error(EGL_BAD_ATTRIBUTE); } if (value == EGL_LOSE_CONTEXT_ON_RESET_EXT) { resetNotification = true; } else if (value != EGL_NO_RESET_NOTIFICATION_EXT) { return Error(EGL_BAD_ATTRIBUTE); } break; default: return Error(EGL_BAD_ATTRIBUTE); } } if ((clientMajorVersion != 2 && clientMajorVersion != 3) || clientMinorVersion != 0) { return Error(EGL_BAD_CONFIG); } if (clientMajorVersion == 3 && !(configuration->conformant & EGL_OPENGL_ES3_BIT_KHR)) { return Error(EGL_BAD_CONFIG); } // Note: EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR does not apply to ES const EGLint validContextFlags = (EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR); if ((contextFlags & ~validContextFlags) != 0) { return Error(EGL_BAD_ATTRIBUTE); } if ((contextFlags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) > 0) { robustAccess = true; } if (robustAccess) { // Unimplemented return Error(EGL_BAD_CONFIG); } if (shareContext) { // Shared context is invalid or is owned by another display if (!display->isValidContext(shareContext)) { return Error(EGL_BAD_MATCH); } if (shareContext->isResetNotificationEnabled() != resetNotification) { return Error(EGL_BAD_MATCH); } if (shareContext->getClientVersion() != clientMajorVersion) { return Error(EGL_BAD_CONTEXT); } } return Error(EGL_SUCCESS); }
std::vector<const Config*> ConfigSet::filter(const AttributeMap &attributeMap) const { std::vector<const Config*> result; result.reserve(mConfigs.size()); for (auto configIter = mConfigs.begin(); configIter != mConfigs.end(); configIter++) { const Config &config = configIter->second; bool match = true; for (auto attribIter = attributeMap.begin(); attribIter != attributeMap.end(); attribIter++) { EGLint attributeKey = attribIter->first; EGLint attributeValue = attribIter->second; switch (attributeKey) { case EGL_BUFFER_SIZE: match = config.bufferSize >= attributeValue; break; case EGL_ALPHA_SIZE: match = config.alphaSize >= attributeValue; break; case EGL_BLUE_SIZE: match = config.blueSize >= attributeValue; break; case EGL_GREEN_SIZE: match = config.greenSize >= attributeValue; break; case EGL_RED_SIZE: match = config.redSize >= attributeValue; break; case EGL_DEPTH_SIZE: match = config.depthSize >= attributeValue; break; case EGL_STENCIL_SIZE: match = config.stencilSize >= attributeValue; break; case EGL_CONFIG_CAVEAT: match = config.configCaveat == (EGLenum)attributeValue; break; case EGL_CONFIG_ID: match = config.configID == attributeValue; break; case EGL_LEVEL: match = config.level >= attributeValue; break; case EGL_NATIVE_RENDERABLE: match = config.nativeRenderable == (EGLBoolean)attributeValue; break; case EGL_NATIVE_VISUAL_TYPE: match = config.nativeVisualType == attributeValue; break; case EGL_SAMPLES: match = config.samples >= attributeValue; break; case EGL_SAMPLE_BUFFERS: match = config.sampleBuffers >= attributeValue; break; case EGL_SURFACE_TYPE: match = (config.surfaceType & attributeValue) == attributeValue; break; case EGL_TRANSPARENT_TYPE: match = config.transparentType == (EGLenum)attributeValue; break; case EGL_TRANSPARENT_BLUE_VALUE: match = config.transparentBlueValue == attributeValue; break; case EGL_TRANSPARENT_GREEN_VALUE: match = config.transparentGreenValue == attributeValue; break; case EGL_TRANSPARENT_RED_VALUE: match = config.transparentRedValue == attributeValue; break; case EGL_BIND_TO_TEXTURE_RGB: match = config.bindToTextureRGB == (EGLBoolean)attributeValue; break; case EGL_BIND_TO_TEXTURE_RGBA: match = config.bindToTextureRGBA == (EGLBoolean)attributeValue; break; case EGL_MIN_SWAP_INTERVAL: match = config.minSwapInterval == attributeValue; break; case EGL_MAX_SWAP_INTERVAL: match = config.maxSwapInterval == attributeValue; break; case EGL_LUMINANCE_SIZE: match = config.luminanceSize >= attributeValue; break; case EGL_ALPHA_MASK_SIZE: match = config.alphaMaskSize >= attributeValue; break; case EGL_COLOR_BUFFER_TYPE: match = config.colorBufferType == (EGLenum)attributeValue; break; case EGL_RENDERABLE_TYPE: match = (config.renderableType & attributeValue) == attributeValue; break; case EGL_MATCH_NATIVE_PIXMAP: match = false; UNIMPLEMENTED(); break; case EGL_CONFORMANT: match = (config.conformant & attributeValue) == attributeValue; break; case EGL_MAX_PBUFFER_WIDTH: match = config.maxPBufferWidth >= attributeValue; break; case EGL_MAX_PBUFFER_HEIGHT: match = config.maxPBufferHeight >= attributeValue; break; case EGL_MAX_PBUFFER_PIXELS: match = config.maxPBufferPixels >= attributeValue; break; case EGL_FULLSCREEN_ANGLE: match = config.fullscreen == (EGLBoolean)attributeValue; break; default: UNREACHABLE(); } if (!match) { break; } } if (match) { result.push_back(&config); } } // Sort the result std::sort(result.begin(), result.end(), ConfigSorter(attributeMap)); return result; }
void AccountHandler::handleCharacterCreateMessage(AccountClient &client, MessageIn &msg) { std::string name = msg.readString(); int hairStyle = msg.readInt8(); int hairColor = msg.readInt8(); int gender = msg.readInt8(); // Avoid creation of character from old clients. int slot = -1; if (msg.getUnreadLength() > 7) slot = msg.readInt8(); MessageOut reply(APMSG_CHAR_CREATE_RESPONSE); Account *acc = client.getAccount(); if (!acc) { reply.writeInt8(ERRMSG_NO_LOGIN); } else if (!stringFilter->filterContent(name)) { reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (stringFilter->findDoubleQuotes(name)) { reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (hairStyle > mNumHairStyles) { reply.writeInt8(CREATE_INVALID_HAIRSTYLE); } else if (hairColor > mNumHairColors) { reply.writeInt8(CREATE_INVALID_HAIRCOLOR); } else if (gender > mNumGenders) { reply.writeInt8(CREATE_INVALID_GENDER); } else if ((name.length() < mMinNameLength) || (name.length() > mMaxNameLength)) { reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else { if (storage->doesCharacterNameExist(name)) { reply.writeInt8(CREATE_EXISTS_NAME); client.send(reply); return; } // An account shouldn't have more // than <account_maxCharacters> characters. Characters &chars = acc->getCharacters(); if (slot < 1 || slot > mMaxCharacters || !acc->isSlotEmpty((unsigned int) slot)) { reply.writeInt8(CREATE_INVALID_SLOT); client.send(reply); return; } if ((int)chars.size() >= mMaxCharacters) { reply.writeInt8(CREATE_TOO_MUCH_CHARACTERS); client.send(reply); return; } // TODO: Add race, face and maybe special attributes. // Customization of character's attributes... std::vector<int> attributes = std::vector<int>(mModifiableAttributes.size(), 0); for (unsigned int i = 0; i < mModifiableAttributes.size(); ++i) attributes[i] = msg.readInt16(); int totalAttributes = 0; for (unsigned int i = 0; i < mModifiableAttributes.size(); ++i) { // For good total attributes check. totalAttributes += attributes.at(i); // For checking if all stats are >= min and <= max. if (attributes.at(i) < mAttributeMinimum || attributes.at(i) > mAttributeMaximum) { reply.writeInt8(CREATE_ATTRIBUTES_OUT_OF_RANGE); client.send(reply); return; } } if (totalAttributes > mStartingPoints) { reply.writeInt8(CREATE_ATTRIBUTES_TOO_HIGH); } else if (totalAttributes < mStartingPoints) { reply.writeInt8(CREATE_ATTRIBUTES_TOO_LOW); } else { Character *newCharacter = new Character(name); // Set the initial attributes provided by the client for (unsigned int i = 0; i < mModifiableAttributes.size(); ++i) { newCharacter->mAttributes.insert( std::make_pair(mModifiableAttributes.at(i), attributes[i])); } newCharacter->mAttributes.insert(mDefaultAttributes.begin(), mDefaultAttributes.end()); newCharacter->setAccount(acc); newCharacter->setCharacterSlot(slot); newCharacter->setLevel(1); // Init GP value to avoid flawed ones. AttributeMap::iterator itr = newCharacter->mAttributes.find(ATTR_GP); if (itr != newCharacter->mAttributes.end()) { itr->second.base = 0; itr->second.modified = 0; } newCharacter->setCharacterPoints(0); newCharacter->setCorrectionPoints(0); newCharacter->setGender(gender); newCharacter->setHairStyle(hairStyle); newCharacter->setHairColor(hairColor); newCharacter->setMapId(Configuration::getValue("char_startMap", 1)); Point startingPos(Configuration::getValue("char_startX", 1024), Configuration::getValue("char_startY", 1024)); newCharacter->setPosition(startingPos); acc->addCharacter(newCharacter); LOG_INFO("Character " << name << " was created for " << acc->getName() << "'s account."); storage->flush(acc); // flush changes // log transaction Transaction trans; trans.mCharacterId = newCharacter->getDatabaseID(); trans.mAction = TRANS_CHAR_CREATE; trans.mMessage = acc->getName() + " created character "; trans.mMessage.append("called " + name); storage->addTransaction(trans); reply.writeInt8(ERRMSG_OK); client.send(reply); // Send new characters infos back to client sendCharacterData(client, *chars[slot]); return; } } client.send(reply); }
bool MessageLib::sendDeltasMSCO_3(ManufacturingSchematic* manSchem,PlayerObject* playerObject) { if(!(playerObject->isConnected())) return(false); Message* newMessage; AttributeMap* attributes = manSchem->getAttributeMap(); AttributeMap::iterator it = attributes->begin(); uint32 attByteCount = 0; // attributes we update here are the attrivutes the final object will have on completion while(it != attributes->end()) { attByteCount += 21 + gWorldManager->getAttributeKey((*it).first).getLength(); ++it; } mMessageFactory->StartMessage(); mMessageFactory->addUint32(opDeltasMessage); mMessageFactory->addUint64(manSchem->getId()); mMessageFactory->addUint32(opMSCO); mMessageFactory->addUint8(3); mMessageFactory->addUint32(12 + attByteCount); mMessageFactory->addUint16(1); mMessageFactory->addUint16(5); mMessageFactory->addUint32(attributes->size()); mMessageFactory->addUint32(++manSchem->mAttributesUpdateCounter); it = attributes->begin(); while(it != attributes->end()) { mMessageFactory->addUint8(2); mMessageFactory->addString(BString("crafting")); mMessageFactory->addUint32(0); mMessageFactory->addString(gWorldManager->getAttributeKey((*it).first)); if(manSchem->hasPPAttribute(gWorldManager->getAttributeKey((*it).first))) { float attributeValue = boost::lexical_cast<float,std::string>((*it).second); float attributeAddValue = manSchem->getPPAttribute<float>(gWorldManager->getAttributeKey((*it).first)); mMessageFactory->addFloat(attributeValue+attributeAddValue); } else mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); //mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); ++it; } newMessage = mMessageFactory->EndMessage(); (playerObject->getClient())->SendChannelA(newMessage,playerObject->getAccountId(),CR_Client,5); return(true); }
bool MessageLib::sendBaselinesMSCO_3(ManufacturingSchematic* manSchem,PlayerObject* playerObject,bool sendAttributes) { if(!(playerObject->isConnected())) return(false); Message* message; Message* part; DraftSchematic* draftSchematic = gSchematicManager->getSchematicBySlotId(manSchem->getDynamicInt32()); AttributeMap* attributes = manSchem->getAttributeMap(); AttributeMap::iterator it = attributes->begin(); uint32 attByteCount = 0; if(sendAttributes) { while(it != attributes->end()) { attByteCount += 21 + gWorldManager->getAttributeKey((*it).first).getLength(); ++it; } } if(!draftSchematic) return(false); string convPlayerName = playerObject->getFirstName(); string convCustomName = manSchem->getCustomName(); convPlayerName.convert(BSTRType_Unicode16); convCustomName.convert(BSTRType_Unicode16); mMessageFactory->StartMessage(); //object count mMessageFactory->addUint16(13); //0 mMessageFactory->addFloat(static_cast<float>(draftSchematic->getComplexity())); //1 mMessageFactory->addString(manSchem->getNameFile()); mMessageFactory->addUint32(0); mMessageFactory->addString(manSchem->getName()); //2 mMessageFactory->addString(convCustomName); //3 = volume mMessageFactory->addUint32(1); //4 = schematic quantity used with schematics with limited uses mMessageFactory->addUint32(1); //5 // send attributes on baseline so that they are shown on assembly //cave review update counter if(sendAttributes) { manSchem->mAttributesUpdateCounter = attributes->size(); mMessageFactory->addUint32(attributes->size()); mMessageFactory->addUint32(manSchem->mAttributesUpdateCounter); it = attributes->begin(); while(it != attributes->end()) { mMessageFactory->addUint8(0); mMessageFactory->addString(BString("crafting")); mMessageFactory->addUint32(0); mMessageFactory->addString(gWorldManager->getAttributeKey((*it).first)); //=============================0 // see whether the attribute has any component values which need adding in the preview if(manSchem->hasPPAttribute(gWorldManager->getAttributeKey((*it).first))) { float attributeValue = boost::lexical_cast<float,std::string>((*it).second); float attributeAddValue = manSchem->getPPAttribute<float>(gWorldManager->getAttributeKey((*it).first)); gLogger->logMsgF("MessageLib::sendBaselinesMSCO_3 Attribute Add Value",MSG_NORMAL); gLogger->logMsgF("MessageLib::sendBaselinesMSCO_3 we will add %f to %S",MSG_NORMAL,attributeAddValue,gWorldManager->getAttributeKey((*it).first).getAnsi()); mMessageFactory->addFloat(attributeValue+attributeAddValue); } else mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); ++it; } } else { mMessageFactory->addUint32(0); mMessageFactory->addUint32(0); } //6 creators name mMessageFactory->addString(convPlayerName); //7 complexity mMessageFactory->addUint32(static_cast<uint32>(manSchem->getComplexity())); // schematic data size mMessageFactory->addUint32(1); part = mMessageFactory->EndMessage(); mMessageFactory->StartMessage(); mMessageFactory->addUint32(opBaselinesMessage); mMessageFactory->addUint64(manSchem->getId()); mMessageFactory->addUint32(opMSCO); mMessageFactory->addUint8(3); mMessageFactory->addUint32(part->getSize()); mMessageFactory->addData(part->getData(),part->getSize()); message = mMessageFactory->EndMessage(); part->setPendingDelete(true); (playerObject->getClient())->SendChannelA(message,playerObject->getAccountId(),CR_Client,5); return(true); }