예제 #1
0
파일: Ascii.cpp 프로젝트: DoomHammer/ohNet
TUint Ascii::AppendDec(Bwx& aBuffer, TInt64 aValue)
{
    Bws<20> reversed; // Maximum value requires 20 digits

    if (aValue == 0) {
        aBuffer.Append('0');
        return (1);
    }

    TUint extra = 0;

    if (aValue < 0) {
        aBuffer.Append('-');
        extra++;
    }

    while(aValue != 0) {
        reversed.Append((TChar)('0' + abs((TInt)(aValue % 10))));
        aValue = aValue / 10;
    }

    for (TUint i = reversed.Bytes(); i > 0; i--) {
        aBuffer.Append(reversed[i - 1]);
    }

    return (reversed.Bytes() + extra);
}
예제 #2
0
TChar* CpListenerMsearch::CreateTypeString(const Brx& aDomain, const Brx& aType, TUint aVersion)
{
    TChar* type = (TChar*)malloc(aDomain.Bytes() + aType.Bytes() + 2 + Ascii::kMaxUintStringBytes + 1);
    TChar* ptr = type;
    (void)strncpy(ptr, (const TChar*)aDomain.Ptr(), aDomain.Bytes());
    ptr += aDomain.Bytes();
    *ptr = ':';
    ptr++;
    (void)strncpy(ptr, (const TChar*)aType.Ptr(), aType.Bytes());
    ptr += aType.Bytes();
    *ptr = ':';
    ptr++;
    Bws<Ascii::kMaxUintStringBytes> ver;
    Ascii::AppendDec(ver, aVersion);
    (void)strncpy(ptr, (const TChar*)ver.Ptr(), ver.Bytes());
    ptr += ver.Bytes();
    *ptr = '\0';
    return type;
}
예제 #3
0
void TcpSessionEcho::Run()
{
    Bws<1500> message;
    while (true) {
        Read(message);
        Write(message);
        if (message.Bytes() == 26)  // close session after receiving 26 byte message
            break;
    }
}
예제 #4
0
파일: Ascii.cpp 프로젝트: DoomHammer/ohNet
TUint Ascii::AppendDec(Bwx& aBuffer, TUint64 aValue)
{
    Bws<20> reversed; // Maximum value requires 20 digits

    if (aValue == 0) {
        aBuffer.Append('0');
        return (1);
    }

    while(aValue > 0) {
        reversed.Append((TChar)('0' + aValue % 10));
        aValue = aValue / 10;
    }

    for (TUint i = reversed.Bytes(); i > 0; i--) {
        aBuffer.Append(reversed[i - 1]);
    }

    return (reversed.Bytes());
}
예제 #5
0
Brn DeviceXml::ServiceVersion(const Brx& aServiceType) const
{
    const TUint kMaxDomainBytes = 64;
    const TUint kMaxTypeBytes = 64;
    
    Bws<kMaxDomainBytes> domain;
    Bws<kMaxTypeBytes> upnpType;
    
    Parser parser(aServiceType);
    
    TUint count = 0;
    
    while (!parser.Finished()) {
        upnpType.Replace(parser.Next('.'));
        count++;
    }

    parser.Restart();
        
    while (--count) {
        Brn element = parser.Next('.');
        
        if (domain.Bytes() > 0) {
            domain.Append('.');
        }
        
        domain.Append(element);
    }
    
    Bws<kMaxDomainBytes> upnpDomain;
    
    Ssdp::CanonicalDomainToUpnp(domain, upnpDomain);
    
    Brn serviceList = XmlParserBasic::Find("serviceList", iXml);
    
    for (;;) {
        Brn service = XmlParserBasic::Find("service", serviceList, serviceList);
        Brn type = XmlParserBasic::Find("serviceType", service);

        Parser parser(type);
        
        if (parser.Next(':') == Brn("urn")) {
            if (parser.Next(':') == upnpDomain) {
                if (parser.Next(':') == Brn("service")) {
                    if (parser.Next(':') == upnpType) {
                        return (parser.Remaining());
                    }
                }
            }
        }
    }
}
예제 #6
0
void SuiteFileStream::Test()
{
    const TUint kBytes = 256;
    Bws<kBytes> b;
    // Populate each position in the buffer with it's index.
    for (TUint i=0; i<kBytes; i++) {
        b.Append((TChar)i);
    }
    FileBrx f(b);
    FileStream stream;
    stream.SetFile(&f);
    TEST(stream.Bytes() == kBytes);

    // test basic reading
    Bws<kBytes> buf;
    stream.Read(buf);
    TEST(buf == b);
    TEST(stream.Tell() == kBytes);

    // test that reads on a full buffer and at the end of a file throw
    TEST_THROWS(stream.Read(buf), ReaderError);
    buf.SetBytes(0);
    TEST_THROWS(stream.Read(buf), ReaderError);

    // test seeking
    stream.Seek(0);
    TEST(stream.Tell() == 0);

    // test a stream can be (un)interrupted
    stream.ReadInterrupt();
    Bws<10> buf2;
    TEST_THROWS(stream.Read(buf2), ReaderError);
    stream.Interrupt(false);
    stream.Read(buf2);
    TEST(buf2.Bytes() == buf2.MaxBytes());
    for (TUint i=0; i<10; i++) {
        TEST(buf2[i] == b[i]);
    }
    
    // test that Read appends to a buffer
    buf.SetBytes(0);
    buf.Append(buf2);
    stream.Read(buf);
    TEST(buf.Bytes() == kBytes);
    TEST(buf == b);
}
예제 #7
0
void SuiteUnicast::Receiver()
{
    TBool first = true;
    iLastVal = 0;
    TUint val;
    Bws<kMsgBytes> recv;
    do {
        recv.SetBytes(0);
        (void)iReceiver->Receive(recv);
        ASSERT(recv.Bytes() >= sizeof(TUint32));
        val = *((TUint32*)recv.Ptr());
        if (val != kQuit) {
            if (first) {
                TEST(val == 0);
                first = false;
            }
            else {
                TEST(val == iLastVal+1);
            }
        }
        //Print("Received %u, last sent %u\n", val, iSendVal);
        iLastVal = val;
    } while (val != kQuit);
}