Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions classes/Hubs.sc
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@

AbstractHub : Participation {
var <>hub, <>locked=false;

init {
this.addResponder('/theHubIsMe', {|t,r,msg|
var who = msg[1].asSymbol, addr;
if(this.canBeChanged) {
addr = collective.everybody[who];
if(addr.notNil) {
hub = addr
} {
if(addr.notNil) {
hub = addr
} {
"something went wrong: hub % could not be assigned.".format(who).warn
}
} {
} {
if(hub.name !== who) {
"can't change hub to %, it is locked.".format(who).warn
}
};

})
}

canBeChanged {
^locked.not or: hub.isNil
}

theHubIsMe {
collective.sendToAll('/theHubIsMe', collective.myName)
}

isTheHubMe {
^hub == collective.myAddr
}

stop {
super.stop;
}

}




TheDiningPhilosophers : Participation {
var <forks, <addresses;

// to do..
// how to distribute the forks in the first place?
// maybe there needs to be a hub for this at least.

init {
this.addResponder('/pingThere', { arg r, t, msg;
this.addResponder('/pingThere', { arg r, t, msg;
var name = msg[1];
name !? { collective.sendToName(name, '/pingBack', collective.myName) }
name !? { collective.sendToName(name, '/pingBack', collective.myName) }
});
this.addResponder('/pingBack', { arg r, t, msg;
var name, addr;
Expand All @@ -63,13 +63,13 @@ TheDiningPhilosophers : Participation {
};
});
addresses = [];

}

createGlobalOrder {
collective.sendToAll('/pingThere', collective.myName);
}
}

numPhilosophers { ^addresses.size }
nextPhilosopher {
addresses.indexOf(collective.myAddr) + 1 % this.numPhilosophers
Expand All @@ -81,24 +81,25 @@ TheDiningPhilosophers : Participation {

/*
AbstractTransference : Participation {
var <channel='/transference', <>nextFunc, <>action;
var <>nextFunc, <>action;
init {
this.addResponder(channel, { arg r, t, msg;
channel='/transference';
this.addResponder(channel, { arg r, t, msg;
var follow = this.nextIndex;
var delta, n, blendFactor, recvedData;

#delta, n ... recvedData = msg[1..];

recvedData = this.transform(recvedData);
this.react(recvedData, delta, n);

if(n > 0 and: { follow.notNil }) {
SystemClock.sched(delta, {
collective.sendToIndex(follow, channel, delta, n - 1, *recvedData)
});
};


})
}
transform { arg data;
Expand All @@ -110,18 +111,19 @@ AbstractTransference : Participation {
var i = this.nextIndex;
collective.sendToIndex(i, channel, delta, length - 1, *data)
}

}
*/

// todo: generalize generation of next message

MarkovNet : Participation {
var <>data, <>transitions, <>weights, <channel='/markov';
var <>data, <>transitions, <>weights;
var <>function;

init {
this.addResponder(channel, { arg r, t, msg;
channel='/markov';
this.addResponder(channel, { arg r, t, msg;
var delta, n, blendFactor, recvedData, forwardData;
var sendData, infoSize, inject;
// length
Expand All @@ -140,16 +142,16 @@ MarkovNet : Participation {
SystemClock.sched(delta, {
this.newChain(delta, n - 1, blendFactor, inject, forwardData); });
};
function.value(sendData);
function.value(sendData);
})
}

nextIndex {
var res;
if(transitions.isNil) { ^collective.addresses.size.rand };
^if(weights.isNil) {
transitions.size.rand
} {
^if(weights.isNil) {
transitions.size.rand
} {
res = transitions[weights.windex];
if(res.isNil) { Error("not the right number of transitions / weights").throw };
res
Expand All @@ -159,9 +161,9 @@ MarkovNet : Participation {
var info;
info = [delta, blendFactor, inject.binaryValue];
sendData = sendData ? data;
collective.sendToIndex(this.nextIndex,
collective.sendToIndex(this.nextIndex,
channel, length, info.size, *(info ++ sendData)
)
}

}