Beispiel #1
0
bool OSCServer::createClientIfNeeded(const OSCMessage &m){
    //    m.
    
    
    // TODO what clever protocol should we implement
    if(m.getAddressPattern().matches(OSCAddress("/Hi"))){
        String host = m[0].getString();
        if(host == "localhost"){
            host = "127.0.0.1";
        }
        int port = m[1].getInt32();
        for(auto & c:clients){
            if(c->host==host && c->port == port)
                return false;
        }
        OSCClient * cli = new OSCClient(host,port,true);
        for(auto & t:owner->tracks){
            for(auto & p :t.get()->getParameters()){
                cli->bindParameter(t, p, "/Tracks/"+String(*t->groupID) + "/" +String(*t->trackNum) + "/" + p->getName(50) );
            }
        }
        clients.add(cli);
        return true;
    }
    
    else if(m.getAddressPattern().matches(OSCAddress("/Bye"))){
        String host = m[0].getString();
        if(host == "localhost"){
            host = "127.0.0.1";
        }
        int port = m[1].getInt32();
        for(auto & c:clients){
            if(c->host==host && c->port == port){
                clients.removeObject(c);
                break;
            }
        }
        
    }
    
    
    return false;
}
Beispiel #2
0
    void runTest()
    {
        beginTest ("construction and parsing");
        {
            expectThrowsType (OSCAddressPattern (""), OSCFormatError);
            expectThrowsType (OSCAddressPattern ("noleadingslash"), OSCFormatError);
            expectThrowsType (OSCAddressPattern ("/notallowedchar "), OSCFormatError);
            expectThrowsType (OSCAddressPattern ("/notallowedchar#andsomemorechars"), OSCFormatError);
            expectThrowsType (OSCAddressPattern (String::fromUTF8 ("/nonasciicharacter\xc3\xbc""blabla")), OSCFormatError);
            expectThrowsType (OSCAddressPattern ("/nonprintableasciicharacter\t"), OSCFormatError);

            expectDoesNotThrow (OSCAddressPattern ("/"));
            expectDoesNotThrow (OSCAddressPattern ("/a"));
            expectDoesNotThrow (OSCAddressPattern ("/a/"));
            expectDoesNotThrow (OSCAddressPattern ("/a/bcd/"));
            expectDoesNotThrow (OSCAddressPattern ("/abcd/efgh/ijkLMNOPq/666r/s"));
            expectDoesNotThrow (OSCAddressPattern ("/allowedprintablecharacters!$%&()+-.:;<=>@^_`|~"));
            expectDoesNotThrow (OSCAddressPattern ("/additonalslashes//will///be////ignored"));
        }

        beginTest ("construction and parsing - with wildcards");
        {
            expectDoesNotThrow (OSCAddressPattern ("/foo/b?r/"));
            expectDoesNotThrow (OSCAddressPattern ("/?????"));
            expectDoesNotThrow (OSCAddressPattern ("/foo/b*r"));
            expectDoesNotThrow (OSCAddressPattern ("/**"));
            expectDoesNotThrow (OSCAddressPattern ("/?/b/*c"));
        }

        beginTest ("construction and parsing - with match expressions");
        {
            expectDoesNotThrow (OSCAddressPattern ("/{}"));
            expectDoesNotThrow (OSCAddressPattern ("/{foo}"));
            expectDoesNotThrow (OSCAddressPattern ("/{foo,bar,baz}"));
            expectDoesNotThrow (OSCAddressPattern ("/[]"));
            expectDoesNotThrow (OSCAddressPattern ("/[abcde]"));
            expectDoesNotThrow (OSCAddressPattern ("/[a-e]"));
            expectDoesNotThrow (OSCAddressPattern ("/foo/[a-z]x{foo,bar}/*BAZ42/"));

            /* Note: if malformed expressions are used, e.g. "bracenotclosed{" or "{a-e}" or "[-foo]",
               this should not throw at construction time. Instead it should simply fail any pattern match later.
               So there is no need to test for those.
               The reason is that we do not actually parse the expressions now, but only during matching.
            */
        }

        beginTest ("equality comparison");
        {
            {
                OSCAddressPattern lhs ("/test/1");
                OSCAddressPattern rhs ("/test/1");
                expect (lhs == rhs);
                expect (! (lhs != rhs));
            }
            {
                OSCAddressPattern lhs ("/test/1");
                OSCAddressPattern rhs ("/test/1/");
                expect (lhs == rhs);
                expect (! (lhs != rhs));
            }
            {
                OSCAddressPattern lhs ("/test/1");
                OSCAddressPattern rhs ("/test/2");
                expect (! (lhs == rhs));
                expect (lhs != rhs);
            }
        }

        beginTest ("basic string matching");
        {
            /* Note: the actual expression matching is tested in OSCPatternMatcher, so here we just
               do some basic tests and check if the matching works with multi-part addresses.
             */
            {
                OSCAddressPattern pattern ("/foo/bar");
                expect (! pattern.containsWildcards());

                OSCAddress address ("/foo/bar");
                expect (pattern.matches (address));
            }
            {
                OSCAddressPattern pattern ("/foo/bar/");
                expect (! pattern.containsWildcards());

                OSCAddress address ("/foo/bar");
                expect (pattern.matches (address));
            }
            {
                OSCAddressPattern pattern ("/");
                expect (! pattern.containsWildcards());

                OSCAddress address ("/");
                expect (pattern.matches (address));
            }
            {
                OSCAddressPattern pattern ("/foo/bar");
                expect (! pattern.containsWildcards());

                expect (! pattern.matches (OSCAddress ("/foo/baz")));
                expect (! pattern.matches (OSCAddress ("/foo/bar/baz")));
                expect (! pattern.matches (OSCAddress ("/foo")));
            }
        }

        beginTest ("string matching with wildcards");
        {
            OSCAddressPattern pattern ("/*/*put/slider[0-9]");
            expect (pattern.containsWildcards());

            expect (pattern.matches (OSCAddress ("/mypatch/input/slider0")));
            expect (pattern.matches (OSCAddress ("/myotherpatch/output/slider9")));
            expect (! pattern.matches (OSCAddress ("/myotherpatch/output/slider10")));
            expect (! pattern.matches (OSCAddress ("/output/slider9")));
            expect (! pattern.matches (OSCAddress ("/myotherpatch/output/slider9/position")));
        }

        beginTest ("conversion to/from String");
        {
            {
                OSCAddressPattern ap ("/this/is/a/very/long/address/");
                expectEquals (ap.toString(), String ("/this/is/a/very/long/address"));
            }
            {
                OSCAddressPattern ap ("/*/*put/{fader,slider,knob}[0-9]/ba?/");
                expectEquals (ap.toString(), String ("/*/*put/{fader,slider,knob}[0-9]/ba?"));
            }
        }
    }
Beispiel #3
0
    void runTest()
    {
        beginTest ("construction and parsing");
        {
            expectThrowsType (OSCAddress (""), OSCFormatError);
            expectThrowsType (OSCAddress ("noleadingslash"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar "), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar#"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar*"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar,"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar?"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar["), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar]"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar{"), OSCFormatError);
            expectThrowsType (OSCAddress ("/notallowedchar}andsomemorechars"), OSCFormatError);
            expectThrowsType (OSCAddress (String::fromUTF8 ("/nonasciicharacter\xc3\xbc""blabla")), OSCFormatError);
            expectThrowsType (OSCAddress ("/nonprintableasciicharacter\t"), OSCFormatError);

            expectDoesNotThrow (OSCAddress ("/"));
            expectDoesNotThrow (OSCAddress ("/a"));
            expectDoesNotThrow (OSCAddress ("/a/"));
            expectDoesNotThrow (OSCAddress ("/a/bcd/"));
            expectDoesNotThrow (OSCAddress ("/abcd/efgh/ijkLMNOPq/666r/s"));
            expectDoesNotThrow (OSCAddress ("/allowedprintablecharacters!$%&()+-.^_`|~"));
            expectDoesNotThrow (OSCAddress ("/additonalslashes//will///be////ignored"));
        }

        beginTest ("conversion to/from String");
        {
            OSCAddress address ("/this/is/a/very/long/address/");
            expectEquals (address.toString(), String ("/this/is/a/very/long/address"));
        }
    }