broken: warrend: moving to unified messeging system

This commit is contained in:
Dan Ballard 2015-03-29 10:45:43 -07:00
parent cc859d1780
commit c3c6bee7a8
4 changed files with 51 additions and 11 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
/deploy /deploy
/cmd/warren/warren /cmd/warren/warren
/cmd/warrend/warrend /cmd/warrend/warrend
.project

View File

@ -71,13 +71,12 @@ func unregRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
} }
err := conf.RmDeployment(args[0]) err := conf.RmDeployment(args[0])
if err != nil {
// Assume nick, check if registered warren.WriteStringz(c, "ERROR: " + err.Error())
deps := conf.GetConf().Deployments return
arg := args[0]
if _,ok := deps[arg]; !ok {
// not a registered nick, try as path
absPath := absPath(path, arg)
if _,ok := conf.
} }
warren.WriteStringz(c, "Unregistered deployment " + args[0])
} }

View File

@ -8,6 +8,29 @@ import (
"os" "os"
) )
type MsgType int
const (
AddDeployment MsgType = iota
RmDeploymen
)
type Msg struct {
mType MsgType
reply chan error
args map[string]string
}
func NewMsg(mType MsgType, args map[string]string) *Msg {
var m = &Msg{mType, make(chan error), args}
return m
}
func (m *Msg) Call() error {
confChan <- *m
err := <-m.reply
return err
}
// Conf package - thread safe conf // Conf package - thread safe conf
// All write ops are public API functions // All write ops are public API functions
// that internall use channels to thread safely queue writes // that internall use channels to thread safely queue writes
@ -22,7 +45,8 @@ type Conf struct {
var conf *Conf = nil var conf *Conf = nil
var Init = make(chan bool) var Init = make(chan bool)
var addDeploymentChan = make(chan DeploymentMsg) var confChan = make(chan Msg)
func loadConf() { func loadConf() {
file, err := os.Open(warren.WarrendConf) file, err := os.Open(warren.WarrendConf)
@ -63,7 +87,7 @@ func saveConf() error {
return errors.New("Error: Could not write to file: " + err.Error()) return errors.New("Error: Could not write to file: " + err.Error())
} }
return nil return ni l
} }
func GetConf() Conf { func GetConf() Conf {
@ -82,7 +106,9 @@ func Run() {
Init <- true Init <- true
// loop for Writes // loop for Writes
for { for {
select { m := <- confChan
select (m.mType) {
case dm := <-addDeploymentChan: case dm := <-addDeploymentChan:
addDeployment(&dm) addDeployment(&dm)
} }

View File

@ -60,3 +60,17 @@ func AddDeployment(d *DeploymentMsg) error {
return nil return nil
} }
func RmDeployment(string arg) error {
reply = make(chan error)
rmDeploymentChan <-
// Assume nick, check if registered
deps := GetConf().Deployments
arg := args[0]
if _,ok := deps[arg]; !ok {
// not a registered nick, try as path
absPath := absPath(path, arg)
// if _,ok := conf.
}
}