diff options
-rw-r--r-- | player/player.go | 60 | ||||
-rw-r--r-- | rddb/rddb.go | 368 | ||||
-rw-r--r-- | rhimport/core.go | 4 | ||||
-rw-r--r-- | rhimport/session_store.go | 4 |
4 files changed, 218 insertions, 218 deletions
diff --git a/player/player.go b/player/player.go index e60b416..77f34a3 100644 --- a/player/player.go +++ b/player/player.go @@ -148,7 +148,7 @@ type pStateChangeCB struct { userdata interface{} } -type Player struct { +type player struct { pipe *gst.Pipeline src *gst.Element level *gst.Element @@ -173,7 +173,7 @@ type Player struct { stateChangeChan chan State } -func (p *Player) changeState(new State) { +func (p *player) changeState(new State) { p.state = new p.stateChangeChan <- new if new == IDLE { @@ -181,7 +181,7 @@ func (p *Player) changeState(new State) { } } -func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) { +func (p *player) onMessage(bus *gst.Bus, msg *gst.Message) { switch msg.GetType() { case gst.MESSAGE_EOS: p.pipe.SetState(gst.STATE_NULL) @@ -233,7 +233,7 @@ func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) { } } -func (p *Player) load(cart, cut uint) (resp loadResult) { +func (p *player) load(cart, cut uint) (resp loadResult) { filename := path.Join(p.basepath, fmt.Sprintf("%06d_%03d.wav", cart, cut)) var file *os.File @@ -262,13 +262,13 @@ func (p *Player) load(cart, cut uint) (resp loadResult) { return } -func (p *Player) unload() (resp unloadResult) { +func (p *player) unload() (resp unloadResult) { p.pipe.SetState(gst.STATE_NULL) p.changeState(IDLE) return } -func (p *Player) play() (resp playResult) { +func (p *player) play() (resp playResult) { if p.state != PAUSED { resp.err = fmt.Errorf("player: no file loaded") return @@ -278,7 +278,7 @@ func (p *Player) play() (resp playResult) { return } -func (p *Player) pause() (resp pauseResult) { +func (p *player) pause() (resp pauseResult) { if p.state != PLAYING { resp.err = fmt.Errorf("player: not playing") return @@ -288,7 +288,7 @@ func (p *Player) pause() (resp pauseResult) { return } -func (p *Player) playPause() (resp playPauseResult) { +func (p *player) playPause() (resp playPauseResult) { switch p.state { case IDLE, PAUSED: p.pipe.SetState(gst.STATE_PLAYING) @@ -300,7 +300,7 @@ func (p *Player) playPause() (resp playPauseResult) { return } -func (p *Player) stop() (resp stopResult) { +func (p *player) stop() (resp stopResult) { switch p.state { case IDLE: p.pipe.SetState(gst.STATE_NULL) @@ -313,7 +313,7 @@ func (p *Player) stop() (resp stopResult) { return } -func (p *Player) seek(pos float64) (resp seekResult) { +func (p *player) seek(pos float64) (resp seekResult) { postime := int64(float64(p.duration) * pos) switch p.state { case PLAYING, PAUSED: @@ -322,12 +322,12 @@ func (p *Player) seek(pos float64) (resp seekResult) { return } -func (p *Player) addUpdateHandler(callback UpdateCB, userdata interface{}) (resp addUpdateHandlerResult) { +func (p *player) addUpdateHandler(callback UpdateCB, userdata interface{}) (resp addUpdateHandlerResult) { p.updateCBs = append(p.updateCBs, &pUpdateCB{callback, userdata}) return } -func (p *Player) sendUpdate(duration time.Duration, pos time.Duration, meter Meter) { +func (p *player) sendUpdate(duration time.Duration, pos time.Duration, meter Meter) { for _, cb := range p.updateCBs { if cb.cb != nil { if keep := cb.cb(duration, pos, meter, cb.userdata); !keep { @@ -338,12 +338,12 @@ func (p *Player) sendUpdate(duration time.Duration, pos time.Duration, meter Met return } -func (p *Player) addStateChangeHandler(callback StateChangeCB, userdata interface{}) (resp addStateChangeHandlerResult) { +func (p *player) addStateChangeHandler(callback StateChangeCB, userdata interface{}) (resp addStateChangeHandlerResult) { p.stateChangeCBs = append(p.stateChangeCBs, &pStateChangeCB{callback, userdata}) return } -func (p *Player) sendStateChange(s State) { +func (p *player) sendStateChange(s State) { for _, cb := range p.stateChangeCBs { if cb.cb != nil { if keep := cb.cb(s, cb.userdata); !keep { @@ -354,7 +354,7 @@ func (p *Player) sendStateChange(s State) { return } -func (p *Player) dispatchRequests() { +func (p *player) dispatchRequests() { p.bus.AddSignalWatch() p.bus.Connect("message", func(bus *gst.Bus, msg *gst.Message) { p.onMessage(bus, msg) }) @@ -386,7 +386,7 @@ func (p *Player) dispatchRequests() { } } -func (p *Player) createPipeline() (err error) { +func (p *player) createPipeline() (err error) { if p.pipe, err = gst.PipelineNew("rhlibrary"); err != nil { return } @@ -441,7 +441,7 @@ func (p *Player) createPipeline() (err error) { // ********************************************************* // Public Interface -type PlayerChan struct { +type Player struct { load chan<- loadRequest unload chan<- unloadRequest play chan<- playRequest @@ -453,7 +453,7 @@ type PlayerChan struct { addStateChangeHandler chan<- addStateChangeHandlerRequest } -func (p *PlayerChan) Load(cart, cut uint) error { +func (p *Player) Load(cart, cut uint) error { resCh := make(chan loadResult) req := loadRequest{} req.cart = cart @@ -468,7 +468,7 @@ func (p *PlayerChan) Load(cart, cut uint) error { return nil } -func (p *PlayerChan) Unload() error { +func (p *Player) Unload() error { resCh := make(chan unloadResult) req := unloadRequest{} req.response = resCh @@ -481,7 +481,7 @@ func (p *PlayerChan) Unload() error { return nil } -func (p *PlayerChan) Play() error { +func (p *Player) Play() error { resCh := make(chan playResult) req := playRequest{} req.response = resCh @@ -494,7 +494,7 @@ func (p *PlayerChan) Play() error { return nil } -func (p *PlayerChan) Pause() error { +func (p *Player) Pause() error { resCh := make(chan pauseResult) req := pauseRequest{} req.response = resCh @@ -507,7 +507,7 @@ func (p *PlayerChan) Pause() error { return nil } -func (p *PlayerChan) PlayPause() error { +func (p *Player) PlayPause() error { resCh := make(chan playPauseResult) req := playPauseRequest{} req.response = resCh @@ -520,7 +520,7 @@ func (p *PlayerChan) PlayPause() error { return nil } -func (p *PlayerChan) Stop() error { +func (p *Player) Stop() error { resCh := make(chan stopResult) req := stopRequest{} req.response = resCh @@ -533,7 +533,7 @@ func (p *PlayerChan) Stop() error { return nil } -func (p *PlayerChan) Seek(pos float64) error { +func (p *Player) Seek(pos float64) error { resCh := make(chan seekResult) req := seekRequest{} req.pos = pos @@ -547,7 +547,7 @@ func (p *PlayerChan) Seek(pos float64) error { return nil } -func (p *PlayerChan) AddUpdateHandler(callback UpdateCB, userdata interface{}) error { +func (p *Player) AddUpdateHandler(callback UpdateCB, userdata interface{}) error { resCh := make(chan addUpdateHandlerResult) req := addUpdateHandlerRequest{} req.callback = callback @@ -562,7 +562,7 @@ func (p *PlayerChan) AddUpdateHandler(callback UpdateCB, userdata interface{}) e return nil } -func (p *PlayerChan) AddStateChangeHandler(callback StateChangeCB, userdata interface{}) error { +func (p *Player) AddStateChangeHandler(callback StateChangeCB, userdata interface{}) error { resCh := make(chan addStateChangeHandlerResult) req := addStateChangeHandlerRequest{} req.callback = callback @@ -577,8 +577,8 @@ func (p *PlayerChan) AddStateChangeHandler(callback StateChangeCB, userdata inte return nil } -func (p *Player) GetInterface() *PlayerChan { - ch := &PlayerChan{} +func (p *player) GetInterface() *Player { + ch := &Player{} ch.load = p.loadChan ch.unload = p.unloadChan ch.play = p.playChan @@ -591,8 +591,8 @@ func (p *Player) GetInterface() *PlayerChan { return ch } -func NewPlayer(basepath string, stdlog *log.Logger, dbglog *log.Logger) (p *Player, err error) { - p = &Player{} +func NewPlayer(basepath string, stdlog *log.Logger, dbglog *log.Logger) (p *player, err error) { + p = &player{} p.basepath = path.Clean(basepath) p.state = IDLE p.duration = 0 diff --git a/rddb/rddb.go b/rddb/rddb.go index e7f1d3a..4fbb303 100644 --- a/rddb/rddb.go +++ b/rddb/rddb.go @@ -221,7 +221,7 @@ type updateCutCartTitleRequest struct { response chan<- updateCutCartTitleResult } -type DB struct { +type db struct { conf *config dbh *sql.DB passwordCache map[string]string @@ -255,16 +255,16 @@ type DB struct { done chan bool } -func (db *DB) init() (err error) { +func (d *db) init() (err error) { godrv.Register("SET CHARACTER SET utf8;") - dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", db.conf.dbHost, db.conf.dbDb, db.conf.dbUser, db.conf.dbPasswd) - if db.dbh, err = sql.Open("mymysql", dsn); err != nil { + dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", d.conf.dbHost, d.conf.dbDb, d.conf.dbUser, d.conf.dbPasswd) + if d.dbh, err = sql.Open("mymysql", dsn); err != nil { return } var dbver int - err = db.dbh.QueryRow("select DB from VERSION;").Scan(&dbver) + err = d.dbh.QueryRow("select DB from VERSION;").Scan(&dbver) if err != nil { err = fmt.Errorf("fetching version: %s", err) return @@ -274,73 +274,73 @@ func (db *DB) init() (err error) { return } - if db.getPasswordStmt, err = db.dbh.Prepare("select PASSWORD from USERS where LOGIN_NAME = ?;"); err != nil { + if d.getPasswordStmt, err = d.dbh.Prepare("select PASSWORD from USERS where LOGIN_NAME = ?;"); err != nil { return } - if db.getGroupOfCartStmt, err = db.dbh.Prepare("select NAME,DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where DEFAULT_LOW_CART <= ? and DEFAULT_HIGH_CART >= ?;"); err != nil { + if d.getGroupOfCartStmt, err = d.dbh.Prepare("select NAME,DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where DEFAULT_LOW_CART <= ? and DEFAULT_HIGH_CART >= ?;"); err != nil { return } - if db.getShowInfoStmt, err = db.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.GROUP_NAME,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and GROUPS.NAME = DROPBOXES.GROUP_NAME and CART.NUMBER = ?;"); err != nil { + if d.getShowInfoStmt, err = d.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.GROUP_NAME,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and GROUPS.NAME = DROPBOXES.GROUP_NAME and CART.NUMBER = ?;"); err != nil { return } - if db.checkMusicGroupStmt, err = db.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil { + if d.checkMusicGroupStmt, err = d.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil { return } - if db.getMusicInfoStmt, err = db.dbh.Prepare("select NORMALIZATION_LEVEL,AUTOTRIM_LEVEL from DROPBOXES where DROPBOXES.GROUP_NAME = ?;"); err != nil { + if d.getMusicInfoStmt, err = d.dbh.Prepare("select NORMALIZATION_LEVEL,AUTOTRIM_LEVEL from DROPBOXES where DROPBOXES.GROUP_NAME = ?;"); err != nil { return } - if db.getShowListStmt, err = db.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.TO_CART,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, USER_PERMS, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { + if d.getShowListStmt, err = d.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.TO_CART,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, USER_PERMS, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { return } - if db.getCartInfoStmt, err = db.dbh.Prepare("select TITLE from CART where TYPE=1 and NUMBER = ?"); err != nil { + if d.getCartInfoStmt, err = d.dbh.Prepare("select TITLE from CART where TYPE=1 and NUMBER = ?"); err != nil { return } - if db.getCutInfoStmt, err = db.dbh.Prepare("select CUT_NAME,EVERGREEN,DESCRIPTION,LENGTH,ORIGIN_DATETIME,PLAY_COUNTER,LAST_PLAY_DATETIME from CUTS where CART_NUMBER = ?"); err != nil { + if d.getCutInfoStmt, err = d.dbh.Prepare("select CUT_NAME,EVERGREEN,DESCRIPTION,LENGTH,ORIGIN_DATETIME,PLAY_COUNTER,LAST_PLAY_DATETIME from CUTS where CART_NUMBER = ?"); err != nil { return } - if db.getJingleListStmt, err = db.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { + if d.getJingleListStmt, err = d.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { return } - if db.getPoolListStmt, err = db.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { + if d.getPoolListStmt, err = d.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil { return } - if db.getPoolCartsStmt, err = db.dbh.Prepare("select CART.NUMBER,CART.ARTIST,CART.TITLE,CART.ALBUM,CUTS.CUT_NAME,CUTS.EVERGREEN,CUTS.DESCRIPTION,CUTS.LENGTH,CUTS.ORIGIN_DATETIME,CUTS.PLAY_COUNTER,CUTS.LAST_PLAY_DATETIME from CUTS,CART where CUTS.CART_NUMBER = CART.NUMBER and CART.GROUP_NAME = ?;"); err != nil { + if d.getPoolCartsStmt, err = d.dbh.Prepare("select CART.NUMBER,CART.ARTIST,CART.TITLE,CART.ALBUM,CUTS.CUT_NAME,CUTS.EVERGREEN,CUTS.DESCRIPTION,CUTS.LENGTH,CUTS.ORIGIN_DATETIME,CUTS.PLAY_COUNTER,CUTS.LAST_PLAY_DATETIME from CUTS,CART where CUTS.CART_NUMBER = CART.NUMBER and CART.GROUP_NAME = ?;"); err != nil { return } - if db.getGroupDefaultTitleStmt, err = db.dbh.Prepare("select DEFAULT_TITLE from GROUPS where NAME = ?;"); err != nil { + if d.getGroupDefaultTitleStmt, err = d.dbh.Prepare("select DEFAULT_TITLE from GROUPS where NAME = ?;"); err != nil { return } - if db.updateCutTitleStmt, err = db.dbh.Prepare("update CUTS set DESCRIPTION = ? where CUT_NAME = ?;"); err != nil { + if d.updateCutTitleStmt, err = d.dbh.Prepare("update CUTS set DESCRIPTION = ? where CUT_NAME = ?;"); err != nil { return } - if db.updateCartTitleMaybeStmt, err = db.dbh.Prepare("update CART set TITLE = ? where NUMBER = ? and TITLE = ?;"); err != nil { + if d.updateCartTitleMaybeStmt, err = d.dbh.Prepare("update CART set TITLE = ? where NUMBER = ? and TITLE = ?;"); err != nil { return } return } -func (db *DB) getPassword(username string, cached bool) (result getPasswordResult) { +func (d *db) getPassword(username string, cached bool) (result getPasswordResult) { if cached { - result.password = db.passwordCache[username] + result.password = d.passwordCache[username] } if result.password == "" { - if result.err = db.getPasswordStmt.QueryRow(username).Scan(&result.password); result.err != nil { + if result.err = d.getPasswordStmt.QueryRow(username).Scan(&result.password); result.err != nil { if result.err == sql.ErrNoRows { result.err = fmt.Errorf("user '%s' not known by rivendell", username) } return } - db.passwordCache[username] = result.password + d.passwordCache[username] = result.password } return } -func (db *DB) getGroupOfCart(cart uint) (result getGroupOfCartResult) { +func (d *db) getGroupOfCart(cart uint) (result getGroupOfCartResult) { var rows *sql.Rows - if rows, result.err = db.getGroupOfCartStmt.Query(cart, cart); result.err != nil { + if rows, result.err = d.getGroupOfCartStmt.Query(cart, cart); result.err != nil { return } defer rows.Close() @@ -368,7 +368,7 @@ func (db *DB) getGroupOfCart(cart uint) (result getGroupOfCartResult) { return } -func (db *DB) getLogTableName(log string) (logtable string, err error) { +func (d *db) getLogTableName(log string) (logtable string, err error) { logtable = strings.Replace(log, " ", "_", -1) + "_LOG" if !mysqlTableNameRe.MatchString(logtable) { return "", fmt.Errorf("the log table name contains illegal charecters: %s", logtable) @@ -376,14 +376,14 @@ func (db *DB) getLogTableName(log string) (logtable string, err error) { return } -func (db *DB) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) { +func (d *db) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) { var logtable string - if logtable, err = db.getLogTableName(log); err != nil { + if logtable, err = d.getLogTableName(log); err != nil { return } q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", logtable, lowCart, highCart) var rows *sql.Rows - if rows, err = db.dbh.Query(q); err != nil { + if rows, err = d.dbh.Query(q); err != nil { return } defer rows.Close() @@ -398,10 +398,10 @@ func (db *DB) getShowCarts(log string, lowCart, highCart int) (carts []uint, err return } -func (db *DB) getShowInfo(showid uint) (result getShowInfoResult) { +func (d *db) getShowInfo(showid uint) (result getShowInfoResult) { var macros string var lowCart, highCart int - result.err = db.getShowInfoStmt.QueryRow(showid).Scan(&result.title, ¯os, &result.group, &result.normLvl, &result.trimLvl, &lowCart, &highCart) + result.err = d.getShowInfoStmt.QueryRow(showid).Scan(&result.title, ¯os, &result.group, &result.normLvl, &result.trimLvl, &lowCart, &highCart) if result.err != nil { if result.err == sql.ErrNoRows { result.err = fmt.Errorf("show '%d' not found", showid) @@ -410,13 +410,13 @@ func (db *DB) getShowInfo(showid uint) (result getShowInfoResult) { } result.normLvl /= 100 result.trimLvl /= 100 - result.carts, result.err = db.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart) + result.carts, result.err = d.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart) return } -func (db *DB) checkMusicGroup(group string) (result checkMusicGroupResult) { +func (d *db) checkMusicGroup(group string) (result checkMusicGroupResult) { var cnt int - if result.err = db.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil { + if result.err = d.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil { if result.err == sql.ErrNoRows { result.err = nil result.ismusic = false @@ -427,8 +427,8 @@ func (db *DB) checkMusicGroup(group string) (result checkMusicGroupResult) { return } -func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) { - result.err = db.getMusicInfoStmt.QueryRow(group).Scan(&result.normLvl, &result.trimLvl) +func (d *db) getMusicInfo(group string) (result getMusicInfoResult) { + result.err = d.getMusicInfoStmt.QueryRow(group).Scan(&result.normLvl, &result.trimLvl) if result.err != nil { if result.err == sql.ErrNoRows { result.err = fmt.Errorf("music pool '%s' not found", group) @@ -438,9 +438,9 @@ func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) { return } -func (db *DB) getShowList(username string) (result getShowListResult) { +func (d *db) getShowList(username string) (result getShowListResult) { var rows *sql.Rows - if rows, result.err = db.getShowListStmt.Query(username, dropboxPseudoStation); result.err != nil { + if rows, result.err = d.getShowListStmt.Query(username, dropboxPseudoStation); result.err != nil { return } defer rows.Close() @@ -463,9 +463,9 @@ func (db *DB) getShowList(username string) (result getShowListResult) { return } -func (db *DB) getCutInfo(cart uint) (cuts []CutListEntry, err error) { +func (d *db) getCutInfo(cart uint) (cuts []CutListEntry, err error) { var rows *sql.Rows - if rows, err = db.getCutInfoStmt.Query(cart); err != nil { + if rows, err = d.getCutInfoStmt.Query(cart); err != nil { return } defer rows.Close() @@ -503,11 +503,11 @@ func (db *DB) getCutInfo(cart uint) (cuts []CutListEntry, err error) { return } -func (db *DB) getCartInfo(cart uint) (c CartListEntry, err error) { +func (d *db) getCartInfo(cart uint) (c CartListEntry, err error) { c = CartListEntry{} c.Number = cart c.Exists = true - err = db.getCartInfoStmt.QueryRow(cart).Scan(&c.Title) + err = d.getCartInfoStmt.QueryRow(cart).Scan(&c.Title) if err != nil { if err == sql.ErrNoRows { err = nil @@ -515,21 +515,21 @@ func (db *DB) getCartInfo(cart uint) (c CartListEntry, err error) { } return } - if c.Cuts, err = db.getCutInfo(cart); err != nil { + if c.Cuts, err = d.getCutInfo(cart); err != nil { return } return } -func (db *DB) getShowCartList(show ShowListEntry) (result getShowCartListResult) { +func (d *db) getShowCartList(show ShowListEntry) (result getShowCartListResult) { var carts []uint - if carts, result.err = db.getShowCarts(show.log, show.lowCart, show.highCart); result.err != nil { + if carts, result.err = d.getShowCarts(show.log, show.lowCart, show.highCart); result.err != nil { return } for _, cart := range carts { var c CartListEntry - if c, result.err = db.getCartInfo(cart); result.err != nil { + if c, result.err = d.getCartInfo(cart); result.err != nil { return } result.carts = append(result.carts, c) @@ -537,9 +537,9 @@ func (db *DB) getShowCartList(show ShowListEntry) (result getShowCartListResult) return } -func (db *DB) getJingleList(username string) (result getJingleListResult) { +func (d *db) getJingleList(username string) (result getJingleListResult) { var rows *sql.Rows - if rows, result.err = db.getJingleListStmt.Query(username, dropboxPseudoStation); result.err != nil { + if rows, result.err = d.getJingleListStmt.Query(username, dropboxPseudoStation); result.err != nil { return } defer rows.Close() @@ -561,19 +561,19 @@ func (db *DB) getJingleList(username string) (result getJingleListResult) { return } -func (db *DB) getJingleCutList(jingle JingleListEntry) (result getJingleCutListResult) { - if result.active, result.err = db.getCartInfo(uint(jingle.ActiveCart)); result.err != nil { +func (d *db) getJingleCutList(jingle JingleListEntry) (result getJingleCutListResult) { + if result.active, result.err = d.getCartInfo(uint(jingle.ActiveCart)); result.err != nil { return } - if result.inactive, result.err = db.getCartInfo(uint(jingle.InactiveCart)); result.err != nil { + if result.inactive, result.err = d.getCartInfo(uint(jingle.InactiveCart)); result.err != nil { return } return } -func (db *DB) getPoolList(username string) (result getPoolListResult) { +func (d *db) getPoolList(username string) (result getPoolListResult) { var rows *sql.Rows - if rows, result.err = db.getPoolListStmt.Query(username, dropboxPseudoStation); result.err != nil { + if rows, result.err = d.getPoolListStmt.Query(username, dropboxPseudoStation); result.err != nil { return } defer rows.Close() @@ -595,9 +595,9 @@ func (db *DB) getPoolList(username string) (result getPoolListResult) { return } -func (db *DB) getPoolCartList(pool PoolListEntry) (result getPoolCartListResult) { +func (d *db) getPoolCartList(pool PoolListEntry) (result getPoolCartListResult) { var rows *sql.Rows - if rows, result.err = db.getPoolCartsStmt.Query(pool.Group); result.err != nil { + if rows, result.err = d.getPoolCartsStmt.Query(pool.Group); result.err != nil { return } defer rows.Close() @@ -643,13 +643,13 @@ func (db *DB) getPoolCartList(pool PoolListEntry) (result getPoolCartListResult) return } -func (db *DB) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) (result updateCutCartTitleResult) { +func (d *db) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) (result updateCutCartTitleResult) { path, filename := filepath.Split(sourceFile) ext := strings.TrimLeft(filepath.Ext(filename), ".") filename = strings.TrimRight(strings.TrimSuffix(filename, ext), ".") if groupName == "" { - res := db.getGroupOfCart(cart) + res := d.getGroupOfCart(cart) if res.err != nil { result.err = res.err return @@ -658,7 +658,7 @@ func (db *DB) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) ( } groupDefaultTitle := "" - result.err = db.getGroupDefaultTitleStmt.QueryRow(groupName).Scan(&groupDefaultTitle) + result.err = d.getGroupDefaultTitleStmt.QueryRow(groupName).Scan(&groupDefaultTitle) if result.err != nil { return } @@ -666,45 +666,45 @@ func (db *DB) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) ( r := strings.NewReplacer("%p", path, "%f", filename, "%e", ext) title := r.Replace(groupDefaultTitle) - if _, result.err = db.updateCutTitleStmt.Exec(title, fmt.Sprintf("%06d_%03d", cart, cut)); result.err != nil { + if _, result.err = d.updateCutTitleStmt.Exec(title, fmt.Sprintf("%06d_%03d", cart, cut)); result.err != nil { return } - if _, result.err = db.updateCartTitleMaybeStmt.Exec(title, cart, defaultCartTitle); result.err != nil { + if _, result.err = d.updateCartTitleMaybeStmt.Exec(title, cart, defaultCartTitle); result.err != nil { return } return } -func (db *DB) dispatchRequests() { - defer func() { db.done <- true }() +func (d *db) dispatchRequests() { + defer func() { d.done <- true }() for { select { - case <-db.quit: + case <-d.quit: return - case req := <-db.getPasswordChan: - req.response <- db.getPassword(req.username, req.cached) - case req := <-db.getGroupOfCartChan: - req.response <- db.getGroupOfCart(req.cart) - case req := <-db.getShowInfoChan: - req.response <- db.getShowInfo(req.showid) - case req := <-db.checkMusicGroupChan: - req.response <- db.checkMusicGroup(req.group) - case req := <-db.getMusicInfoChan: - req.response <- db.getMusicInfo(req.group) - case req := <-db.getShowListChan: - req.response <- db.getShowList(req.username) - case req := <-db.getShowCartListChan: - req.response <- db.getShowCartList(req.show) - case req := <-db.getJingleListChan: - req.response <- db.getJingleList(req.username) - case req := <-db.getJingleCutListChan: - req.response <- db.getJingleCutList(req.jingle) - case req := <-db.getPoolListChan: - req.response <- db.getPoolList(req.username) - case req := <-db.getPoolCartListChan: - req.response <- db.getPoolCartList(req.pool) - case req := <-db.updateCutCartTitleChan: - req.response <- db.updateCutCartTitle(req.cart, req.cut, req.groupName, req.sourceFile) + case req := <-d.getPasswordChan: + req.response <- d.getPassword(req.username, req.cached) + case req := <-d.getGroupOfCartChan: + req.response <- d.getGroupOfCart(req.cart) + case req := <-d.getShowInfoChan: + req.response <- d.getShowInfo(req.showid) + case req := <-d.checkMusicGroupChan: + req.response <- d.checkMusicGroup(req.group) + case req := <-d.getMusicInfoChan: + req.response <- d.getMusicInfo(req.group) + case req := <-d.getShowListChan: + req.response <- d.getShowList(req.username) + case req := <-d.getShowCartListChan: + req.response <- d.getShowCartList(req.show) + case req := <-d.getJingleListChan: + req.response <- d.getJingleList(req.username) + case req := <-d.getJingleCutListChan: + req.response <- d.getJingleCutList(req.jingle) + case req := <-d.getPoolListChan: + req.response <- d.getPoolList(req.username) + case req := <-d.getPoolCartListChan: + req.response <- d.getPoolCartList(req.pool) + case req := <-d.updateCutCartTitleChan: + req.response <- d.updateCutCartTitle(req.cart, req.cut, req.groupName, req.sourceFile) } } } @@ -712,7 +712,7 @@ func (db *DB) dispatchRequests() { // ********************************************************* // Public Interface -type DBChan struct { +type DB struct { getPasswordChan chan<- getPasswordRequest getGroupOfCartChan chan<- getGroupOfCartRequest getShowInfoChan chan<- getShowInfoRequest @@ -727,13 +727,13 @@ type DBChan struct { updateCutCartTitleChan chan<- updateCutCartTitleRequest } -func (db *DBChan) GetPassword(username string, cached bool) (string, error) { +func (d *DB) GetPassword(username string, cached bool) (string, error) { resCh := make(chan getPasswordResult) req := getPasswordRequest{} req.username = username req.cached = cached req.response = resCh - db.getPasswordChan <- req + d.getPasswordChan <- req res := <-resCh if res.err != nil { @@ -742,7 +742,7 @@ func (db *DBChan) GetPassword(username string, cached bool) (string, error) { return res.password, nil } -func (db *DBChan) CheckPassword(username, password string) (bool, error) { +func (d *DB) CheckPassword(username, password string) (bool, error) { cached := true for { @@ -751,7 +751,7 @@ func (db *DBChan) CheckPassword(username, password string) (bool, error) { req.username = username req.cached = cached req.response = resCh - db.getPasswordChan <- req + d.getPasswordChan <- req res := <-resCh if res.err != nil { @@ -769,12 +769,12 @@ func (db *DBChan) CheckPassword(username, password string) (bool, error) { return false, nil } -func (db *DBChan) GetGroupOfCart(cart uint) (string, error) { +func (d *DB) GetGroupOfCart(cart uint) (string, error) { resCh := make(chan getGroupOfCartResult) req := getGroupOfCartRequest{} req.cart = cart req.response = resCh - db.getGroupOfCartChan <- req + d.getGroupOfCartChan <- req res := <-resCh if res.err != nil { @@ -783,12 +783,12 @@ func (db *DBChan) GetGroupOfCart(cart uint) (string, error) { return res.group, nil } -func (db *DBChan) GetShowInfo(showid uint) (string, int, int, []uint, error) { +func (d *DB) GetShowInfo(showid uint) (string, int, int, []uint, error) { resCh := make(chan getShowInfoResult) req := getShowInfoRequest{} req.showid = showid req.response = resCh - db.getShowInfoChan <- req + d.getShowInfoChan <- req res := <-resCh if res.err != nil { @@ -797,12 +797,12 @@ func (db *DBChan) GetShowInfo(showid uint) (string, int, int, []uint, error) { return res.group, res.normLvl, res.trimLvl, res.carts, nil } -func (db *DBChan) CheckMusicGroup(groupname string) (bool, error) { +func (d *DB) CheckMusicGroup(groupname string) (bool, error) { resCh := make(chan checkMusicGroupResult) req := checkMusicGroupRequest{} req.group = groupname req.response = resCh - db.checkMusicGroupChan <- req + d.checkMusicGroupChan <- req res := <-resCh if res.err != nil { @@ -811,12 +811,12 @@ func (db *DBChan) CheckMusicGroup(groupname string) (bool, error) { return res.ismusic, nil } -func (db *DBChan) GetMusicInfo(groupname string) (int, int, error) { +func (d *DB) GetMusicInfo(groupname string) (int, int, error) { resCh := make(chan getMusicInfoResult) req := getMusicInfoRequest{} req.group = groupname req.response = resCh - db.getMusicInfoChan <- req + d.getMusicInfoChan <- req res := <-resCh if res.err != nil { @@ -825,12 +825,12 @@ func (db *DBChan) GetMusicInfo(groupname string) (int, int, error) { return res.normLvl, res.trimLvl, nil } -func (db *DBChan) GetShowList(username string) (ShowList, error) { +func (d *DB) GetShowList(username string) (ShowList, error) { resCh := make(chan getShowListResult) req := getShowListRequest{} req.username = username req.response = resCh - db.getShowListChan <- req + d.getShowListChan <- req res := <-resCh if res.err != nil { @@ -839,12 +839,12 @@ func (db *DBChan) GetShowList(username string) (ShowList, error) { return res.shows, nil } -func (db *DBChan) GetShowCartList(show ShowListEntry) ([]CartListEntry, error) { +func (d *DB) GetShowCartList(show ShowListEntry) ([]CartListEntry, error) { resCh := make(chan getShowCartListResult) req := getShowCartListRequest{} req.show = show req.response = resCh - db.getShowCartListChan <- req + d.getShowCartListChan <- req res := <-resCh if res.err != nil { @@ -853,12 +853,12 @@ func (db *DBChan) GetShowCartList(show ShowListEntry) ([]CartListEntry, error) { return res.carts, nil } -func (db *DBChan) GetJingleList(username string) (JingleList, error) { +func (d *DB) GetJingleList(username string) (JingleList, error) { resCh := make(chan getJingleListResult) req := getJingleListRequest{} req.username = username req.response = resCh - db.getJingleListChan <- req + d.getJingleListChan <- req res := <-resCh if res.err != nil { @@ -867,23 +867,23 @@ func (db *DBChan) GetJingleList(username string) (JingleList, error) { return res.jingles, nil } -func (db *DBChan) GetJingleCutList(jingle JingleListEntry) (CartListEntry, CartListEntry, error) { +func (d *DB) GetJingleCutList(jingle JingleListEntry) (CartListEntry, CartListEntry, error) { resCh := make(chan getJingleCutListResult) req := getJingleCutListRequest{} req.jingle = jingle req.response = resCh - db.getJingleCutListChan <- req + d.getJingleCutListChan <- req res := <-resCh return res.active, res.inactive, res.err } -func (db *DBChan) GetPoolList(username string) (PoolList, error) { +func (d *DB) GetPoolList(username string) (PoolList, error) { resCh := make(chan getPoolListResult) req := getPoolListRequest{} req.username = username req.response = resCh - db.getPoolListChan <- req + d.getPoolListChan <- req res := <-resCh if res.err != nil { @@ -892,12 +892,12 @@ func (db *DBChan) GetPoolList(username string) (PoolList, error) { return res.pools, nil } -func (db *DBChan) GetPoolCartList(pool PoolListEntry) (map[uint]CartListEntry, error) { +func (d *DB) GetPoolCartList(pool PoolListEntry) (map[uint]CartListEntry, error) { resCh := make(chan getPoolCartListResult) req := getPoolCartListRequest{} req.pool = pool req.response = resCh - db.getPoolCartListChan <- req + d.getPoolCartListChan <- req res := <-resCh if res.err != nil { @@ -906,7 +906,7 @@ func (db *DBChan) GetPoolCartList(pool PoolListEntry) (map[uint]CartListEntry, e return res.carts, nil } -func (db *DBChan) UpdateCutCartTitle(cart, cut uint, groupName, sourceFile string) error { +func (d *DB) UpdateCutCartTitle(cart, cut uint, groupName, sourceFile string) error { resCh := make(chan updateCutCartTitleResult) req := updateCutCartTitleRequest{} req.cart = cart @@ -914,108 +914,108 @@ func (db *DBChan) UpdateCutCartTitle(cart, cut uint, groupName, sourceFile strin req.groupName = groupName req.sourceFile = sourceFile req.response = resCh - db.updateCutCartTitleChan <- req + d.updateCutCartTitleChan <- req res := <-resCh return res.err } -func (db *DB) GetInterface() *DBChan { - ch := &DBChan{} - ch.getPasswordChan = db.getPasswordChan - ch.getGroupOfCartChan = db.getGroupOfCartChan - ch.getShowInfoChan = db.getShowInfoChan - ch.checkMusicGroupChan = db.checkMusicGroupChan - ch.getMusicInfoChan = db.getMusicInfoChan - ch.getShowListChan = db.getShowListChan - ch.getShowCartListChan = db.getShowCartListChan - ch.getJingleListChan = db.getJingleListChan - ch.getJingleCutListChan = db.getJingleCutListChan - ch.getPoolListChan = db.getPoolListChan - ch.getPoolCartListChan = db.getPoolCartListChan - ch.updateCutCartTitleChan = db.updateCutCartTitleChan +func (d *db) GetInterface() *DB { + ch := &DB{} + ch.getPasswordChan = d.getPasswordChan + ch.getGroupOfCartChan = d.getGroupOfCartChan + ch.getShowInfoChan = d.getShowInfoChan + ch.checkMusicGroupChan = d.checkMusicGroupChan + ch.getMusicInfoChan = d.getMusicInfoChan + ch.getShowListChan = d.getShowListChan + ch.getShowCartListChan = d.getShowCartListChan + ch.getJingleListChan = d.getJingleListChan + ch.getJingleCutListChan = d.getJingleCutListChan + ch.getPoolListChan = d.getPoolListChan + ch.getPoolCartListChan = d.getPoolCartListChan + ch.updateCutCartTitleChan = d.updateCutCartTitleChan return ch } -func (db *DB) Cleanup() { - db.quit <- true - <-db.done - close(db.quit) - close(db.done) - close(db.getPasswordChan) - if db.dbh != nil { - db.dbh.Close() +func (d *db) Cleanup() { + d.quit <- true + <-d.done + close(d.quit) + close(d.done) + close(d.getPasswordChan) + if d.dbh != nil { + d.dbh.Close() } - if db.getPasswordStmt != nil { - db.getPasswordStmt.Close() + if d.getPasswordStmt != nil { + d.getPasswordStmt.Close() } - if db.getGroupOfCartStmt != nil { - db.getGroupOfCartStmt.Close() + if d.getGroupOfCartStmt != nil { + d.getGroupOfCartStmt.Close() } - if db.getShowInfoStmt != nil { - db.getShowInfoStmt.Close() + if d.getShowInfoStmt != nil { + d.getShowInfoStmt.Close() } - if db.checkMusicGroupStmt != nil { - db.checkMusicGroupStmt.Close() + if d.checkMusicGroupStmt != nil { + d.checkMusicGroupStmt.Close() } - if db.getMusicInfoStmt != nil { - db.getMusicInfoStmt.Close() + if d.getMusicInfoStmt != nil { + d.getMusicInfoStmt.Close() } - if db.getShowListStmt != nil { - db.getShowListStmt.Close() + if d.getShowListStmt != nil { + d.getShowListStmt.Close() } - if db.getCartInfoStmt != nil { - db.getCartInfoStmt.Close() + if d.getCartInfoStmt != nil { + d.getCartInfoStmt.Close() } - if db.getCutInfoStmt != nil { - db.getCutInfoStmt.Close() + if d.getCutInfoStmt != nil { + d.getCutInfoStmt.Close() } - if db.getJingleListStmt != nil { - db.getJingleListStmt.Close() + if d.getJingleListStmt != nil { + d.getJingleListStmt.Close() } - if db.getPoolListStmt != nil { - db.getPoolListStmt.Close() + if d.getPoolListStmt != nil { + d.getPoolListStmt.Close() } - if db.getPoolCartsStmt != nil { - db.getPoolCartsStmt.Close() + if d.getPoolCartsStmt != nil { + d.getPoolCartsStmt.Close() } - if db.getGroupDefaultTitleStmt != nil { - db.getGroupDefaultTitleStmt.Close() + if d.getGroupDefaultTitleStmt != nil { + d.getGroupDefaultTitleStmt.Close() } - if db.updateCutTitleStmt != nil { - db.updateCutTitleStmt.Close() + if d.updateCutTitleStmt != nil { + d.updateCutTitleStmt.Close() } - if db.updateCartTitleMaybeStmt != nil { - db.updateCartTitleMaybeStmt.Close() + if d.updateCartTitleMaybeStmt != nil { + d.updateCartTitleMaybeStmt.Close() } } -func NewDB(configfile string) (db *DB, err error) { - db = new(DB) - if db.conf, err = newConfig(configfile); err != nil { +func NewDB(configfile string) (d *db, err error) { + d = new(db) + if d.conf, err = newConfig(configfile); err != nil { return } - db.quit = make(chan bool) - db.done = make(chan bool) - db.passwordCache = make(map[string]string) - db.getPasswordChan = make(chan getPasswordRequest, 10) - db.getGroupOfCartChan = make(chan getGroupOfCartRequest, 10) - db.getShowInfoChan = make(chan getShowInfoRequest, 10) - db.checkMusicGroupChan = make(chan checkMusicGroupRequest, 10) - db.getMusicInfoChan = make(chan getMusicInfoRequest, 10) - db.getShowListChan = make(chan getShowListRequest, 10) - db.getShowCartListChan = make(chan getShowCartListRequest, 10) - db.getJingleListChan = make(chan getJingleListRequest, 10) - db.getJingleCutListChan = make(chan getJingleCutListRequest, 10) - db.getPoolListChan = make(chan getPoolListRequest, 10) - db.getPoolCartListChan = make(chan getPoolCartListRequest, 10) - db.updateCutCartTitleChan = make(chan updateCutCartTitleRequest, 10) + d.quit = make(chan bool) + d.done = make(chan bool) + d.passwordCache = make(map[string]string) + d.getPasswordChan = make(chan getPasswordRequest, 10) + d.getGroupOfCartChan = make(chan getGroupOfCartRequest, 10) + d.getShowInfoChan = make(chan getShowInfoRequest, 10) + d.checkMusicGroupChan = make(chan checkMusicGroupRequest, 10) + d.getMusicInfoChan = make(chan getMusicInfoRequest, 10) + d.getShowListChan = make(chan getShowListRequest, 10) + d.getShowCartListChan = make(chan getShowCartListRequest, 10) + d.getJingleListChan = make(chan getJingleListRequest, 10) + d.getJingleCutListChan = make(chan getJingleCutListRequest, 10) + d.getPoolListChan = make(chan getPoolListRequest, 10) + d.getPoolCartListChan = make(chan getPoolCartListRequest, 10) + d.updateCutCartTitleChan = make(chan updateCutCartTitleRequest, 10) - if err = db.init(); err != nil { + if err = d.init(); err != nil { return } - go db.dispatchRequests() + go d.dispatchRequests() return } diff --git a/rhimport/core.go b/rhimport/core.go index f01ed77..bf4a57e 100644 --- a/rhimport/core.go +++ b/rhimport/core.go @@ -137,7 +137,7 @@ type AttachmentChunk struct { type Context struct { conf *Config - db *rddb.DBChan + db *rddb.DB stdlog *log.Logger dbglog *log.Logger UserName string @@ -169,7 +169,7 @@ type Context struct { Cancel <-chan bool } -func NewContext(conf *Config, db *rddb.DBChan, stdlog, dbglog *log.Logger) *Context { +func NewContext(conf *Config, db *rddb.DB, stdlog, dbglog *log.Logger) *Context { if stdlog == nil { stdlog = log.New(ioutil.Discard, "", 0) } diff --git a/rhimport/session_store.go b/rhimport/session_store.go index bb36473..ec01071 100644 --- a/rhimport/session_store.go +++ b/rhimport/session_store.go @@ -133,7 +133,7 @@ func (user *sessionStoreUserElement) callUpdateHandlerRemove(id, refId string) { type sessionStore struct { store map[string]*sessionStoreUserElement conf *Config - db *rddb.DBChan + db *rddb.DB stdlog *log.Logger dbglog *log.Logger quit chan bool @@ -389,7 +389,7 @@ func (store *sessionStore) Cleanup() { close(store.removeChan) } -func NewSessionStore(conf *Config, db *rddb.DBChan, stdlog, dbglog *log.Logger) (store *sessionStore, err error) { +func NewSessionStore(conf *Config, db *rddb.DB, stdlog, dbglog *log.Logger) (store *sessionStore, err error) { store = &sessionStore{} store.conf = conf store.db = db |