|
|
|
@ -195,9 +195,8 @@ func (state * BaseLockableState) RemoveRequirement(requirement Lockable) {
|
|
|
|
|
state.requirements = state.requirements[0:(req_len-1)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Requires lockable and requirement's states to be locked for write
|
|
|
|
|
func UnlinkLockables(ctx * GraphContext, lockable Lockable, requirement Lockable) error {
|
|
|
|
|
// Check if requirement is a requirement of lockable
|
|
|
|
|
err := UpdateStates(ctx, []GraphNode{lockable}, func(nodes NodeMap) error{
|
|
|
|
|
state := lockable.State().(LockableState)
|
|
|
|
|
var found GraphNode = nil
|
|
|
|
|
for _, req := range(state.Requirements()) {
|
|
|
|
@ -211,20 +210,15 @@ func UnlinkLockables(ctx * GraphContext, lockable Lockable, requirement Lockable
|
|
|
|
|
return fmt.Errorf("UNLINK_LOCKABLES_ERR: %s is not a requirement of %s", requirement.ID(), lockable.ID())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := UpdateMoreStates(ctx, []GraphNode{found}, nodes, func(nodes NodeMap) error {
|
|
|
|
|
req_state := found.State().(LockableState)
|
|
|
|
|
req_state.RemoveDependency(lockable)
|
|
|
|
|
state.RemoveRequirement(requirement)
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LinkLockables(ctx * GraphContext, lockable Lockable, requirements []Lockable) error {
|
|
|
|
|
// Requires lockable and requirements to be locked for write, nodes passed because requirement check recursively locks
|
|
|
|
|
func LinkLockables(ctx * GraphContext, lockable Lockable, requirements []Lockable, nodes NodeMap) error {
|
|
|
|
|
if lockable == nil {
|
|
|
|
|
return fmt.Errorf("LOCKABLE_LINK_ERR: Will not link Lockables to nil as requirements")
|
|
|
|
|
}
|
|
|
|
@ -250,13 +244,6 @@ func LinkLockables(ctx * GraphContext, lockable Lockable, requirements []Lockabl
|
|
|
|
|
found[requirement.ID()] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gnodes := make([]GraphNode, len(requirements) + 1)
|
|
|
|
|
gnodes[0] = lockable
|
|
|
|
|
for i, node := range(requirements) {
|
|
|
|
|
gnodes[i+1] = node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := UpdateStates(ctx, gnodes, func(nodes NodeMap) error {
|
|
|
|
|
// Check that all the requirements can be added
|
|
|
|
|
lockable_state := lockable.State().(LockableState)
|
|
|
|
|
// If the lockable is already locked, need to lock this resource as well before we can add it
|
|
|
|
@ -299,10 +286,6 @@ func LinkLockables(ctx * GraphContext, lockable Lockable, requirements []Lockabl
|
|
|
|
|
|
|
|
|
|
// Return no error
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewBaseLockableState(name string, _type string) BaseLockableState {
|
|
|
|
@ -711,11 +694,21 @@ func NewSimpleLockable(ctx * GraphContext, name string, requirements []Lockable)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lockable_ptr := &lockable
|
|
|
|
|
err = LinkLockables(ctx, lockable_ptr, requirements)
|
|
|
|
|
|
|
|
|
|
if len(requirements) > 0 {
|
|
|
|
|
req_nodes := make([]GraphNode, len(requirements))
|
|
|
|
|
for i, req := range(requirements) {
|
|
|
|
|
req_nodes[i] = req
|
|
|
|
|
}
|
|
|
|
|
err = UpdateStates(ctx, req_nodes, func(nodes NodeMap) error {
|
|
|
|
|
return LinkLockables(ctx, lockable_ptr, requirements, nodes)
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lockable_ptr, nil
|
|
|
|
|
}
|
|
|
|
|