示例#1
0
TTErr TTAddressItem::remove(TTAddress addressToRemove)
{
	TTAddressItemPtr anItem, parentItem;
	
	// if the item exist
	if (!this->find(addressToRemove, &anItem)) {
		
        // remove option (even empty option)
        anItem->options->remove(addressToRemove.getAttribute());
        
        // if there no more options
        if (anItem->options->isEmpty()) {
            
            // destroy upper parents if there are empty after removing the item
            do {
               
                parentItem = anItem->getParent();
                ((TTListPtr)parentItem)->remove((TTPtr)anItem);
                destroy(anItem);
                
                anItem = parentItem;
                
            } while (anItem->isEmpty()) ;
        }
			
		return kTTErrNone;
	}
	
	return kTTErrValueNotFound;
}
示例#2
0
TTErr TTAddressItem::append(TTAddress addressToAppend, TTAddressItemPtr *returnedItem)
{
	TTAddressItemPtr	anItem = this;
	TTAddressItemPtr	nextItem;
	TTList				nameInstanceList;
	TTSymbol			nameInstance(kTTSymEmpty);
	
	addressToAppend.listNameInstance(nameInstanceList);
	
	for (nameInstanceList.begin(); nameInstanceList.end(); nameInstanceList.next()) {
		nameInstance = nameInstanceList.current()[0];
		
		nextItem = anItem->getItem(nameInstance);
		
		if (!nextItem) {
			nextItem = new TTAddressItem(nameInstance, anItem);
			((TTListPtr)anItem)->append((TTPtr)nextItem);
		}
		
		anItem = nextItem;
	}
    
    anItem->options->appendUnique(addressToAppend.getAttribute());
	
	*returnedItem = anItem;
	return kTTErrNone;
}
示例#3
0
TTErr TTAddressItem::find(TTAddress addressToFind, TTAddressItemPtr *returnedItem)
{
	TTAddressItemPtr	anItem = this;
	TTAddressItemPtr	nextItem;
	TTList				nameInstanceList;
	TTSymbol			nameInstance(kTTSymEmpty);
    TTValue             v;
	
	addressToFind.listNameInstance(nameInstanceList);
    
    if (nameInstanceList.isEmpty())
        return kTTErrGeneric;
    
	for (nameInstanceList.begin(); nameInstanceList.end(); nameInstanceList.next()) {
		
		nameInstance = nameInstanceList.current()[0];
		
		nextItem = anItem->getItem(nameInstance);
		
		if (!nextItem)
			return kTTErrValueNotFound;
		else
			anItem = nextItem;
	}
    
    if (anItem->options->isEmpty() && addressToFind.getAttribute() == NO_ATTRIBUTE) {
        *returnedItem = anItem;
        return kTTErrNone;
    }
	
    if (!anItem->options->findEquals(addressToFind.getAttribute(), v)) {
        
        *returnedItem = anItem;
        return kTTErrNone;
    }
    
    return kTTErrValueNotFound;
}
示例#4
0
TTErr TTProtocol::ReceiveSetRequest(TTSymbol from, TTAddress address, const TTValue& newValue)
{
	TTValue v, none;
	TTErr	err;
	
	// set the an object in the namespace
    if (address.getAttribute() == NO_ATTRIBUTE)
        address = address.appendAttribute(kTTSym_value);
    
    v.append(address);
    v.append((TTPtr)&newValue);
    err = mApplicationManager.send("ApplicationSet", v);
    
    // TODO : test error and send notification if error
    return err;
}
示例#5
0
TTErr TTProtocol::ReceiveGetRequest(TTSymbol from, TTAddress address)
{
	TTErr	err;
	TTValue returnedValue;
    
    if (!mRunning)
        return kTTErrGeneric;
	
	// discover the namespace
    if (address.getAttribute() == NO_ATTRIBUTE)
        address = address.appendAttribute(kTTSym_value);
    
    err = mApplicationManager.send("ApplicationGet", address, returnedValue);
    
    return SendGetAnswer(from, address, returnedValue, err);
}
示例#6
0
TTErr TTProtocol::ReceiveListenAnswer(TTSymbol from, TTAddress address, const TTValue& newValue)
{
	TTValue v, none;
	TTErr	err;
	TTValue dummy;
	
    if (address.getAttribute() == NO_ATTRIBUTE)
        address = address.appendAttribute(kTTSym_value);
    
    v.append(from);
    v.append(address);
    v.append((TTPtr)&newValue);
    
    err = mApplicationManager.send("ApplicationListenAnswer", v);
    
    if (err && mRunning)
        return SendListenAnswer(from, address, dummy, err);
    
    return kTTErrGeneric;
}
示例#7
0
TTErr TTProtocol::ReceiveListenRequest(TTSymbol from, TTAddress address, TTBoolean enable) 
{
	TTValue v, none;
	TTErr	err;
	
	// listen an object or the namespace
    if (address.getAttribute() == NO_ATTRIBUTE)
        address = address.appendAttribute(kTTSym_value);
    
    v.append(mName);	// the name of the protocol is needed for feed back notifications
    v.append(from);
    v.append(address);
    v.append(enable);
    
    err = mApplicationManager.send("ApplicationListen", v);
    
    if (err && mRunning)
        return SendListenAnswer(from, address, none, err);
    
    return kTTErrGeneric;
}
示例#8
0
void TTNodeLibTestMiscellaneous(int& errorCount, int& testAssertionCount)
{
	TTTestLog("\n");
	TTTestLog("Miscellaneous Tests");
	
	// test convertUpperCasedName global method
	TTSymbol testSymbolA = "TestSymbolName";
	TTSymbol testSymbolB = "testSymbolName";
	TTSymbol testSymbolC = "testsymbolname";
	TTAddress result;
   

	convertUpperCasedNameInAddress(testSymbolA, result);
	TTTestAssertion("convertUpperCasedName: Test passes if \"TestSymbolName\" is converted in \"test/symbol/name\"",
					result == TTAddress("test/symbol/name"),
					testAssertionCount,
					errorCount);
	
	convertUpperCasedNameInAddress(testSymbolB, result);
	TTTestAssertion("convertUpperCasedName: Test passes if \"testSymbolName\" is converted in \"test/symbol/name\"",
					result == TTAddress("test/symbol/name"),
					testAssertionCount,
					errorCount);
	
	convertUpperCasedNameInAddress(testSymbolC, result);
	TTTestAssertion("convertUpperCasedName: Test passes if \"testsymbolname\" is not converted",
					result == testSymbolC,
					testAssertionCount,
					errorCount);
    
    // test TTSymbol to TTAdress casting
    TTValue     testValue = TTValue(TTSymbol("directory:/gran/parent/name.instance:attribute"));
    TTAddress   testAddress;
    
    testAddress = testValue[0];
    
    TTSymbol		directory	= testAddress.getDirectory();
	TTAddress		parent		= testAddress.getParent();
	TTSymbol		name		= testAddress.getName();
	TTSymbol		instance	= testAddress.getInstance();
	TTSymbol		attribute	= testAddress.getAttribute();
	TTAddressType	type		= testAddress.getType();
    
    TTBoolean t1 = directory == TTSymbol("directory");
    TTBoolean t2 = parent == TTAddress("/gran/parent");
    TTBoolean t3 = name == TTSymbol("name");
    TTBoolean t4 = instance == TTSymbol("instance");
    TTBoolean t5 = attribute == TTSymbol("attribute");
    TTBoolean t6 = type == kAddressAbsolute;

    TTTestAssertion("TTValue::get : Test2 fails if a TTSymbol contained into a value is not casted into a TTAddress during a get method",
					directory == TTSymbol("directory") &&
					parent == TTAddress("/gran/parent") &&
					name == TTSymbol("name") &&
					instance == TTSymbol("instance") &&
					attribute == TTSymbol("attribute") &&
					type == kAddressAbsolute,
					testAssertionCount,
					errorCount);

    // test TTSymbol for TTHash access when a key is stored using a TTAddress
    TTHash      testTable;
    TTAddress   keyAddress = TTAddress("testKeyAddress");
    TTValue     keyValue;
    TTErr       err;
    
    testTable.append(keyAddress, keyValue);             // store a value into the table using "testKeyAddress" address
    testValue = TTValue(TTSymbol("testKeyAddress"));    // store a "testKeyAddress" symbol into a value
    testAddress = testValue[0];                         // get it as an address
    err = testTable.lookup(testAddress, keyValue);      // use the address to lookup the table
    
    TTTestAssertion("TTHash::lookup : Test fails if a TTSymbol cannot be used as storage key for TTHash table when the lookup key is a TTAddress",
					err == kTTErrNone,
					testAssertionCount,
					errorCount);
    
    // The test below fails but it have been added only to check the opposite operation.
    // For instant we don't need this test to pass so it is commented out until we need this feature.
    
    /* test TTAddress for TTHash access when a key is stored using a TTSymbol
    TTSymbol    keySymbol = TTSymbol("testKeySymbol");
    TTSymbol    testSymbol;
    
    testTable.append(keySymbol, keyValue);              // store a value into the table using "testKeySymbol" symbol
    testValue = TTValue(TTAddress("testKeySymbol"));    // store a "testKeySymbol" address into a value
    testSymbol = testValue[0];                          // get it as an symbol
    err = testTable.lookup(testSymbol, keyValue);       // use the symbol to lookup the table
    
    TTTestAssertion("TTHash::lookup : Test fails if a TTAddress cannot be used as storage key for TTHash table when the lookup key is a TTSymbol",
					err == kTTErrNone,
					testAssertionCount,
					errorCount);
     */
}