const SocketAddress Discovery::NodeDevice::getAddr(int port) const { auto s = addrStorage; // copy if (s.getFamily() == AF_INET6) { ((struct sockaddr_in6 *)&s)->sin6_port = htons(port); } else if(s.getFamily() == AF_INET) { ((struct sockaddr_in *)&s)->sin_port = htons(port); } return s; }
void TextLabel::updateFaceAndTexture(void) { if (_face != NULL) { std::string fam = getFamily(); if ((_face->getParam().size == getSize() && _face->getFamily() == fam) || fam.empty()) // FIXME: what about ""? { return; // nothing to be done } subRef(_face); _face = NULL; } // Create the font std::string family = getFamily(); if (family.empty()) family = "SANS"; TextTXFParam param; param.size = static_cast<UInt32>(getSize()); _face = TextTXFFace::create(family, TextFace::STYLE_PLAIN, param); if (_face != NULL) { TextureObjChunkRefPtr texObj = TextureObjChunk::create(); Image* texture = _face->getTexture(); texObj->setImage(texture); texObj->setWrapS(GL_CLAMP); texObj->setWrapT(GL_CLAMP); texObj->setMinFilter(GL_LINEAR); texObj->setMagFilter(GL_LINEAR); this->setTextureObject(texObj); } // We failed to create the font - fallback to the default font if (_face == NULL) { // FIXME: create TextLabelDefaultFont!!! _face = DefaultFont::the()->getFace(); this->setTextureObject(DefaultFont::the()->getTexture()); } // Increment reference counters addRef(_face); }
Connection::Connection(string ip, string socket, string family, bool server, int socktype){ memset(&hints, 0, sizeof(hints)); hints->ai_family = getFamily(family); hints->ai_socktype = socktype; hints->ai_flags = AI_PASSIVE; getaddrinfo() }
bool SockAddr::isPrivate() const { const int family = getFamily(); if(family == AF_INET){ const AUTO_REF(ip, reinterpret_cast<const unsigned char (&)[4]>( static_cast<const ::sockaddr_in *>(getData())->sin_addr)); if(ip[0] == 0){ // 0.0.0.0/8: 当前网络地址 return true; } else if(ip[0] == 10){ // 10.0.0.0/8: A 类私有地址 return true; } else if(ip[0] == 127){ // 127.0.0.0/8: 回环地址 return true; } else if((ip[0] == 172) && ((ip[1] & 0xF0) == 16)){ // 172.16.0.0/12: B 类私有地址 return true; } else if((ip[0] == 169) && (ip[1] == 254)){ // 169.254.0.0/16: 链路本地地址 return true; } else if((ip[0] == 192) && (ip[1] == 168)){ // 192.168.0.0/16: C 类私有地址 return true; } else if(ip[0] >= 224){ // D 类、E 类地址和广播地址 return true; } return false; } else if(family == AF_INET6){ static const unsigned char ZEROES[16] = { }; const AUTO_REF(ip, reinterpret_cast<const unsigned char (&)[16]>( static_cast<const ::sockaddr_in6 *>(getData())->sin6_addr)); if(std::memcmp(ip, ZEROES, 15) == 0){ if(ip[15] == 0){ // ::/128: 未指定的地址 return true; } if(ip[15] == 1){ // ::1/128: 回环地址 return true; } } else if((std::memcmp(ip, ZEROES, 10) == 0) && (ip[10] == 0xFF) && (ip[11] == 0xFF)){ // IPv4 翻译地址 if(ip[12] == 0){ // 0.0.0.0/8: 当前网络地址 return true; } else if(ip[12] == 10){ // 10.0.0.0/8: A 类私有地址 return true; } else if(ip[12] == 127){ // 127.0.0.0/8: 回环地址 return true; } else if((ip[12] == 172) && ((ip[13] & 0xF0) == 16)){ // 172.16.0.0/12: B 类私有地址 return true; } else if((ip[12] == 169) && (ip[13] == 254)){ // 169.254.0.0/16: 链路本地地址 return true; } else if((ip[12] == 192) && (ip[13] == 168)){ // 192.168.0.0/16: C 类私有地址 return true; } else if(ip[12] >= 224){ // D 类、E 类地址和广播地址 return true; } } else if((ip[0] == 0x01) && (std::memcmp(ip + 1, ZEROES, 7) == 0)){ // 100::/64 黑洞地址 return true; } else if(ip[0] >= 0xFC){ // 私有地址、链路本地地址和广播地址 return true; } return false; } LOG_POSEIDON_WARNING("Unknown IP protocol ", family); DEBUG_THROW(Exception, sslit("Unknown IP protocol")); }
/*! Create a new register holding the given value. A LOADI is pushed */ template <typename T> INLINE Register immReg(T value) { GBE_ASSERTM(fn != NULL, "No function currently defined"); const Immediate imm(value); const ImmediateIndex index = fn->newImmediate(imm); const RegisterFamily family = getFamily(imm.getType()); const Register reg = this->reg(family); this->LOADI(imm.getType(), reg, index); return reg; }
CFontPtr CFont:: rotated(double dangle) const { double angle = getAngle() + dangle; while (angle < 0 ) angle += 360; while (angle >= 360) angle -= 360; return dup(getFamily(), getStyle(), getSize(), angle, getCharAngle(), getXRes(), getYRes()); }
bool SockAddr::isIpv6() const { const int family = getFamily(); if(family == AF_INET){ return false; } else if(family == AF_INET6){ return true; } LOG_POSEIDON_WARNING("Unknown IP protocol ", family); DEBUG_THROW(Exception, sslit("Unknown IP protocol")); }
void UIFont::initText(void) { // Create the font //Check if I have a FilePathAttachment const BoostPath* FilePath(FilePathAttachment::getFilePath(UIFontRefPtr(this))); if(FilePath != NULL) { //Create the font from a file _face = TextTXFFace::createFromFile(FilePath->string().c_str()); } else { TextTXFParam param; param.size = getGlyphPixelSize(); param.gap = getGap(); param.textureWidth = getTextureWidth(); //Use my Family Field to create font texture _face = TextTXFFace::create(getFamily(), static_cast<TextFace::Style>(getStyle()), param); } TextureObjChunkUnrecPtr TheChunk(TextureObjChunk::create()); setTexture(TheChunk); if (_face != NULL) { ImageRefPtr image = _face->getTexture(); getTexture()->setImage(image); getTexture()->setWrapS(GL_CLAMP); getTexture()->setWrapT(GL_CLAMP); //if(getAntiAliasing()) //{ getTexture()->setMinFilter(GL_LINEAR_MIPMAP_NEAREST); getTexture()->setMagFilter(GL_LINEAR); //} //else //{ //getTexture()->setMinFilter(GL_NEAREST); //getTexture()->setMagFilter(GL_NEAREST); //} //getTexture()->setEnvMode(GL_MODULATE); } // We failed to create the font - fallback to the default font //if (_face == NULL) //{ // _face = getStatisticsDefaultFont(); // getTexture() = getStatisticsDefaultFontTexture(); //} }
string itsSetItem::getInformations() { // a stream is easier to manipulate stringstream infos; // Separator used between key and value string sep = ":\t"; infos << "\t" << "Key" << sep << getKey() << endl; infos << "\t" << "Family" << sep << getFamily() << endl; infos << "\t" << "Name" << sep << getName() << endl; infos << "\t" << "Accronym" << sep << getAccronym() << endl; infos << "\t" << "Description" << sep << getDescription() << endl; infos << "\t" << "Reference" << sep << getCitation() << endl; // get back the string only return infos.str(); }
string itsSetItem::getInformations_XML() { // a stream is easier to manipulate stringstream infos; infos << "<item>" << endl; infos << "<key>" << getKey() << "</key>" << endl; infos << "<family>" << getFamily() << "</family>" << endl; infos << "<name>" << getName() << "</name>" << endl; infos << "<accronym>" << getAccronym() << "</accronym>" << endl; infos << "<description>" << getDescription() << "</description>" << endl; infos << "<reference>" << getCitation() << "</reference>" << endl; infos << "</item>" << endl; // get back the string only return infos.str(); }
int SocketAddress::getPort(void) const { switch(getFamily()) { case PF_INET: { const struct sockaddr_in* sa((struct sockaddr_in*)m_sa); return ntohs(sa->sin_port); } case PF_INET6: { const struct sockaddr_in6* sa((struct sockaddr_in6*)m_sa); return ntohs(sa->sin6_port); } }; PWTRACE("invalid family for getPort"); return -1; }
bool Discovery::send(const std::string &msg, const NodeDevice &node) { bool isMulticast = !node.exists(); char data[500]; char *dp = &data[0]; auto devName = UP::getDeviceName(); // create 0-seperated string list strcpy(dp, msg.c_str()); dp += msg.length() + 1; strcpy(dp, devName.c_str()); dp += devName.length() + 1; strcpy(dp, getHwAddress().c_str()); dp += getHwAddress().length() + 1; int dataLen = dp - &data[0]; if (!isMulticast) { auto na = node.getAddr(m_broadcastPort); bool ipv6 = (na.getFamily() == AF_INET6); if (sendto(ipv6 ? m_socMulticast : m_socBroadcast4, data, dataLen, 0, (struct sockaddr*)&na, sizeof(na)) != dataLen) { LOG(logERROR) << "Could not send broadcast message to " << node << lastError(); return false; } } else { // ipv4 udp broadcast if (m_socBroadcast4 != -1) { struct sockaddr_in addr4; memset(&addr4, 0, sizeof(addr4)); addr4.sin_family = AF_INET; addr4.sin_port = htons(m_broadcastPort); addr4.sin_addr.s_addr = htonl(INADDR_BROADCAST); if (sendto(m_socBroadcast4, data, dataLen, 0, (struct sockaddr*)&addr4, sizeof(addr4)) != dataLen) { LOG(logERROR) << "Could not send broadcast message on INADDR_BROADCAST! " << lastError(); return false; } // Windows broadcast fix (for ipv4): send broadcast on each host addr char ac[1000]; if (gethostname(ac, sizeof(ac)) == -1) return false; // TODO bug gethostbyname causes seg fault on windows in release (maybe mongoose?) addrinfo *ai; if (getaddrinfo(ac, NULL, NULL, &ai) != 0) { return false; } for (auto cai = ai; cai != 0; cai = cai->ai_next) { struct in_addr daddr; memcpy(&daddr, cai->ai_addr, std::min(sizeof(daddr), (size_t)cai->ai_addrlen)); addr4.sin_addr.s_addr = daddr.s_addr | (255) << (8 * 3); std::string ip4(inet_ntoa(addr4.sin_addr)); //std::cout << "broadcast message to " << ip4 << ":" << ntohs(addr4.sin_port) << "" << std::endl; if (sendto(m_socBroadcast4, data, dataLen, 0, (struct sockaddr*)&addr4, sizeof(addr4)) != dataLen) { LOG(logERROR) << "Could not send broadcast message to " << ip4 << "!" << std::endl; } } freeaddrinfo(ai); } // ipv6 multicast if (m_socMulticast != -1) { if (sendto(m_socMulticast, data, dataLen, 0, (struct sockaddr *)&m_multicastAddrSend, sizeof(m_multicastAddrSend)) != dataLen) { LOG(logERROR) << "sending ipv6 multicast message on " << m_multicastAddrSend << " failed! " << lastError(); return false; } } // send to explicit nodes for (NodeDevice n : m_explicitNodes) { send(msg, n); } } return true; }
/*! Draw the statistics lines. */ void SimpleStatisticsForeground::draw(DrawEnv *pEnv, Viewport *pPort) { if(getActive() == false) return; if(_face == 0) initText(getFamily(), getSize()); if ((getCollector() == NULL) || (!getCollector()->getNumOfElems() && !getMFElementIDs()->size())) return; // nothing to do Real32 pw = Real32(pPort->getPixelWidth ()); Real32 ph = Real32(pPort->getPixelHeight()); if(pw < 1 || ph < 1) return; glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_DEPTH_TEST); glDisable(GL_COLOR_MATERIAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // Set viewport. We want to map one unit to one pixel on the // screen. Some sources in the internet say that we should // add an offset of -0.375 to prevent rounding errors. Don't // know if that is true, but it seems to work. glOrtho(0 - 0.375, pw - 0.375, 0 - 0.375, ph - 0.375, 0, 1); // retrieve text std::vector < std::string > stat; StatCollector *col = this->getCollector(); StatElem *el; if(getMFElementIDs()->size() != 0) { for(UInt32 i = 0; i < getMFElementIDs()->size(); ++i) { Int32 id(getElementIDs(i)); el = ((id >= 0) ? col->getElem(id) : 0); stat.resize(stat.size() + 1); std::vector < std::string >::iterator str = stat.end() - 1; const char *format = NULL; if(i < getMFFormats()->size() && getFormats(i).length()) { format = getFormats(i).c_str(); } if (el) el->putToString(*str, format); else *str = format; } } else // fallback, show all elements { for(UInt32 i = 0; i < col->getNumOfElems(); ++i) { el = col->getElem(i, false); if(el) { std::string desc(el->getDesc()->getName()), eltext; el->putToString(eltext); desc = desc + " : " + eltext; stat.resize(stat.size() + 1); std::vector < std::string >::iterator str = stat.end() - 1; *str = desc; } } } TextLayoutParam layoutParam; layoutParam.spacing = 1.1f; layoutParam.majorAlignment = TextLayoutParam::ALIGN_BEGIN; layoutParam.minorAlignment = TextLayoutParam::ALIGN_BEGIN; TextLayoutResult layoutResult; _face->layout(stat, layoutParam, layoutResult); Real32 scale = 1 / _face->getScale(); Real32 size = _face->getParam().size; Real32 textWidth = layoutResult.textBounds.x() * scale + size + getTextMargin().x() * 2.0f; Real32 textHeight = layoutResult.textBounds.y() * scale + size + getTextMargin().y() * 2.0f; // Let's do some simple form of layout management Real32 orthoX = 0, orthoY = ph; switch ( getHorizontalAlign() ) { case Right: orthoX = pw - textWidth; break; case Middle: orthoX = (pw - textWidth) * 0.5; break; case Left: default: break; } switch ( getVerticalAlign() ) { case Bottom: orthoY = textHeight; break; case Center: orthoY = (ph - textHeight) * 0.5 + textHeight; break; case Top: default: break; } glTranslatef(orthoX, orthoY, 0.0); // draw background glColor4fv(static_cast<const GLfloat *>(getBgColor().getValuesRGBA())); glBegin(GL_QUADS); glVertex2f(0, -textHeight); glVertex2f(textWidth, -textHeight); glVertex2f(textWidth, 0); glVertex2f(0, 0); glEnd(); // draw border if(getBorderColor().alpha() >= 0.0f) { glColor4fv( static_cast<const GLfloat *>(getBorderColor().getValuesRGBA())); glBegin(GL_LINE_LOOP); glVertex2f(getBorderOffset().x(), -textHeight + 1 + getBorderOffset().y()); glVertex2f(textWidth - 1 - getBorderOffset().x(), -textHeight + 1 + getBorderOffset().y()); glVertex2f(textWidth - 1 - getBorderOffset().x(), -1 - getBorderOffset().y()); glVertex2f(getBorderOffset().x(), -1 - getBorderOffset().y()); glEnd(); } glTranslatef( 0.5 * size + getTextMargin().x(), -0.5 * size - getTextMargin().y(), 0.0); _texchunk ->activate(pEnv); _texenvchunk->activate(pEnv); // draw text shadow glColor4fv(static_cast<const GLfloat *>(getShadowColor().getValuesRGBA())); glPushMatrix(); glTranslatef(getShadowOffset().x(), getShadowOffset().y(), 0); glScalef(scale, scale, 1); _face->drawCharacters(layoutResult); // draw text glColor4fv(static_cast<const GLfloat *>(getColor().getValuesRGBA())); glPopMatrix(); glScalef(scale, scale, 1); _face->drawCharacters(layoutResult); _texchunk ->deactivate(pEnv); _texenvchunk->deactivate(pEnv); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); }
FamilyRec * SkFontManager::getDefaultFamily() { uint32_t fontIndex = getCurrentFontIndex(); return getFamily( fontIndex ); }
CFontPtr CFont:: dup() const { return dup(getFamily(), getStyle(), getSize(), getAngle(), getCharAngle(), getXRes(), getYRes()); }