Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
186 lines (185 sloc) 9.38 KB
{
"rules":{
".read":true,
"users":{
"$user":{
".write":"
( //0: null -> IDLE, self
/*role */($user == auth.username)
/*from */ && data.child('state').val() == null
/*to */ && newData.child('state').val() == 'IDLE'
/*signal*/ && newData.child('signal').val() == null
/*effect*/ && (
newData.child('item').val() == null &&
newData.child('tx_itm').val() == null &&
newData.child('tx_ptr').val() == null &&
newData.child('rx_itm').val() == null &&
newData.child('rx_ptr').val() == null
)
)||
( //1: IDLE -> TX, self
/*role */($user == auth.username)
/*from */ && data.child('state').val() == 'IDLE'
/*to */ && newData.child('state').val() == 'TX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
data.child('item').val() != null &&
root.child('users').child(newData.child('tx_ptr').val()).child('state').val() != null &&
newData.child('tx_ptr').val() != $user
)
/*effect*/ && (
newData.child('tx_itm').val() == data.child('item').val() &&
newData.child('tx_ptr').val() != null &&
newData.child('item').val() == null
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //2: IDLE -> RX, self
/*role */($user == auth.username)
/*from */ && data.child('state').val() == 'IDLE'
/*to */ && newData.child('state').val() == 'RX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
data.child('item').val() == null &&
$user == root.child('users').child(newData.child('rx_ptr').val()).child('tx_ptr').val()
)
/*effect*/ && (
newData.child('rx_itm').val() == root.child('users').child(newData.child('rx_ptr').val()).child('tx_itm').val() &&
newData.child('rx_ptr').val() != null &&
newData.child('tx_itm').val() == null
)
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('item').val() == data.child('item').val() //lock for item
)||
( //3: TX -> ACK_TX, other
/*role */(auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'TX'
/*to */ && newData.child('state').val() == 'ACK_TX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(newData.child('tx_ptr').val()).child('state').val() == 'ACK_RX'
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('item').val() == data.child('item').val() //lock for item
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //4: TX -> IDLE, self
/*role */($user == auth.username)
/*from */ && data.child('state').val() == 'TX'
/*to */ && newData.child('state').val() == 'IDLE'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
(root.child('users').child(data.child('tx_ptr').val()).child('state').val() != 'RX' &&
root.child('users').child(data.child('tx_ptr').val()).child('state').val() != 'ACK_RX') ||(
root.child('users').child(data.child('tx_ptr').val()).child('rx_ptr').val() != $user)
)
/*effect*/ && (
newData.child('tx_itm').val() == null &&
newData.child('tx_ptr').val() == null &&
newData.child('item').val() == data.child('tx_itm').val()
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //5: RX -> ACK_RX, other
/*role */(auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'RX'
/*to */ && newData.child('state').val() == 'ACK_RX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('rx_ptr').val()).child('state').val() == 'TX' &&
root.child('users').child(data.child('rx_ptr').val()).child('tx_ptr').val() == $user
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('item').val() == data.child('item').val() //lock for item
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //6: RX -> IDLE, either
/*role */($user == auth.username || auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'RX'
/*to */ && newData.child('state').val() == 'IDLE'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('rx_ptr').val()).child('state').val() == 'TX'
)
/*effect*/ && (
newData.child('rx_itm').val() == null &&
newData.child('rx_ptr').val() == null &&
newData.child('item').val() == null
)
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
)||
( //7: ACK_TX -> IDLE, either
/*role */($user == auth.username || auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'ACK_TX'
/*to */ && newData.child('state').val() == 'IDLE'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('tx_ptr').val()).child('state').val() == 'ACK_RX'
)
/*effect*/ && (
newData.child('item').val() == null &&
newData.child('tx_ptr').val() == null &&
newData.child('tx_itm').val() == null
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //8: ACK_TX -> TX, either
/*role */($user == auth.username || auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'ACK_TX'
/*to */ && newData.child('state').val() == 'TX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('tx_ptr').val()).child('state').val() == 'RX' &&
root.child('users').child(data.child('tx_ptr').val()).child('rx_ptr').val() == $user
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('item').val() == data.child('item').val() //lock for item
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)||
( //9: ACK_RX -> IDLE, either
/*role */($user == auth.username || auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'ACK_RX'
/*to */ && newData.child('state').val() == 'IDLE'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('rx_ptr').val()).child('state').val() != 'TX' &&
root.child('users').child(data.child('rx_ptr').val()).child('state').val() != 'ACK_TX'
)
/*effect*/ && (
newData.child('item').val() == data.child('rx_itm').val()&&
newData.child('rx_ptr').val() == null &&
newData.child('rx_itm').val() == null
)
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
)||
( //10: ACK_RX -> RX, either
/*role */($user == auth.username || auth.username == data.child('rx_ptr').val() || auth.username == data.child('tx_ptr').val())
/*from */ && data.child('state').val() == 'ACK_RX'
/*to */ && newData.child('state').val() == 'RX'
/*signal*/ && newData.child('signal').val() == null
/*guards*/ && (
root.child('users').child(data.child('rx_ptr').val()).child('state').val() == 'TX' &&
root.child('users').child(data.child('rx_ptr').val()).child('tx_ptr').val() == $user
)
&& newData.child('rx_ptr').val() == data.child('rx_ptr').val() //lock for rx_ptr
&& newData.child('tx_ptr').val() == data.child('tx_ptr').val() //lock for tx_ptr
&& newData.child('item').val() == data.child('item').val() //lock for item
&& newData.child('tx_itm').val() == data.child('tx_itm').val() //lock for tx_itm
&& newData.child('rx_itm').val() == data.child('rx_itm').val() //lock for rx_itm
)
"
}
}
}
}