summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rddb/rddb.go91
1 files changed, 90 insertions, 1 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index c889dff..4edda6a 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -134,7 +134,9 @@ type CutListEntry struct {
type CartListEntry struct {
Number uint
Exists bool
+ Artist string
Title string
+ Album string
Cuts []CutListEntry
}
@@ -195,6 +197,16 @@ type getPoolListRequest struct {
response chan<- getPoolListResult
}
+type getPoolCartListResult struct {
+ carts map[uint]CartListEntry
+ err error
+}
+
+type getPoolCartListRequest struct {
+ pool PoolListEntry
+ response chan<- getPoolCartListResult
+}
+
type DB struct {
conf *config
dbh *sql.DB
@@ -219,6 +231,8 @@ type DB struct {
getJingleCutListChan chan getJingleCutListRequest
getPoolListChan chan getPoolListRequest
getPoolListStmt *sql.Stmt
+ getPoolCartListChan chan getPoolCartListRequest
+ getPoolCartsStmt *sql.Stmt
quit chan bool
done chan bool
}
@@ -263,7 +277,7 @@ func (db *DB) init() (err error) {
if db.getCartInfoStmt, err = db.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 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 {
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 {
@@ -272,6 +286,9 @@ func (db *DB) init() (err error) {
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 {
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 {
+ return
+ }
return
}
@@ -551,6 +568,56 @@ func (db *DB) getPoolList(username string) (result getPoolListResult) {
return
}
+func (db *DB) getPoolCartList(pool PoolListEntry) (result getPoolCartListResult) {
+ var rows *sql.Rows
+ if rows, result.err = db.getPoolCartsStmt.Query(pool.Group); result.err != nil {
+ return
+ }
+ defer rows.Close()
+
+ result.carts = make(map[uint]CartListEntry)
+ for rows.Next() {
+ var cut CutListEntry
+ var cart, length uint
+ var cutName, evergreen string
+ var artist, title, album sql.NullString
+
+ if result.err = rows.Scan(&cart, &artist, &title, &album, &cutName, &evergreen, &cut.Description, &length, &cut.Imported, &cut.NumPlayed, &cut.LastPlayed); result.err != nil {
+ return
+ }
+
+ parts := strings.Split(cutName, "_")
+ if len(parts) == 2 {
+ if cn, converr := strconv.ParseUint(parts[1], 10, 32); converr != nil {
+ continue
+ } else {
+ cut.Number = uint(cn)
+ }
+ } else {
+ continue
+ }
+ switch evergreen {
+ case "Y":
+ cut.Evergreen = true
+ default:
+ cut.Evergreen = false
+ }
+ cut.Duration = time.Duration(length) * time.Millisecond
+
+ if c, exists := result.carts[cart]; !exists {
+ c = CartListEntry{cart, true, artist.String, title.String, album.String, nil}
+ c.Cuts = append(c.Cuts, cut)
+ result.carts[cart] = c
+ } else {
+ c.Cuts = append(c.Cuts, cut)
+ }
+ }
+ result.err = rows.Err()
+ return
+
+ return
+}
+
func (db *DB) dispatchRequests() {
defer func() { db.done <- true }()
for {
@@ -577,6 +644,8 @@ func (db *DB) dispatchRequests() {
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)
}
}
}
@@ -595,6 +664,7 @@ type DBChan struct {
getJingleListChan chan<- getJingleListRequest
getJingleCutListChan chan<- getJingleCutListRequest
getPoolListChan chan<- getPoolListRequest
+ getPoolCartListChan chan<- getPoolCartListRequest
}
func (db *DBChan) GetPassword(username string, cached bool) (string, error) {
@@ -762,6 +832,20 @@ func (db *DBChan) GetPoolList(username string) (PoolList, error) {
return res.pools, nil
}
+func (db *DBChan) GetPoolCartList(pool PoolListEntry) (map[uint]CartListEntry, error) {
+ resCh := make(chan getPoolCartListResult)
+ req := getPoolCartListRequest{}
+ req.pool = pool
+ req.response = resCh
+ db.getPoolCartListChan <- req
+
+ res := <-resCh
+ if res.err != nil {
+ return nil, res.err
+ }
+ return res.carts, nil
+}
+
func (db *DB) GetInterface() *DBChan {
ch := &DBChan{}
ch.getPasswordChan = db.getPasswordChan
@@ -774,6 +858,7 @@ func (db *DB) GetInterface() *DBChan {
ch.getJingleListChan = db.getJingleListChan
ch.getJingleCutListChan = db.getJingleCutListChan
ch.getPoolListChan = db.getPoolListChan
+ ch.getPoolCartListChan = db.getPoolCartListChan
return ch
}
@@ -816,6 +901,9 @@ func (db *DB) Cleanup() {
if db.getPoolListStmt != nil {
db.getPoolListStmt.Close()
}
+ if db.getPoolCartsStmt != nil {
+ db.getPoolCartsStmt.Close()
+ }
}
func NewDB(configfile string) (db *DB, err error) {
@@ -836,6 +924,7 @@ func NewDB(configfile string) (db *DB, err error) {
db.getJingleListChan = make(chan getJingleListRequest, 10)
db.getJingleCutListChan = make(chan getJingleCutListRequest, 10)
db.getPoolListChan = make(chan getPoolListRequest, 10)
+ db.getPoolCartListChan = make(chan getPoolCartListRequest, 10)
if err = db.init(); err != nil {
return